From ea06cab2b7c40b1d070e0d2024205dce8e052266 Mon Sep 17 00:00:00 2001 From: Vince Broz Date: Mon, 19 Oct 2026 13:10:33 -0400 Subject: [PATCH 1/2] Add RBS for cache_method 0.2 cache_method includes CacheMethod::ClassMethods into Module and CacheMethod::InstanceMethods into Object at require time, so class bodies call cache_method and cache_method_clear_on with no explicit extend. Model those includes so Steep sees the DSL wherever the gem makes it available, along with CacheMethod.config and its Config. InstanceMethods declares a BasicObject self type: the implicit Object self type would make Object an ancestor of itself once the module is included into Object. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01Wo4FerFK9aaxrGrmVE9ncZ --- gems/cache_method/.rubocop.yml | 19 ++++++++ gems/cache_method/0.2/_test/metadata.yaml | 4 ++ gems/cache_method/0.2/_test/test.rb | 41 +++++++++++++++++ gems/cache_method/0.2/_test/test.rbs | 13 ++++++ gems/cache_method/0.2/cache_method.rbs | 56 +++++++++++++++++++++++ gems/cache_method/_reviewers.yaml | 2 + 6 files changed, 135 insertions(+) create mode 100644 gems/cache_method/.rubocop.yml create mode 100644 gems/cache_method/0.2/_test/metadata.yaml create mode 100644 gems/cache_method/0.2/_test/test.rb create mode 100644 gems/cache_method/0.2/_test/test.rbs create mode 100644 gems/cache_method/0.2/cache_method.rbs create mode 100644 gems/cache_method/_reviewers.yaml diff --git a/gems/cache_method/.rubocop.yml b/gems/cache_method/.rubocop.yml new file mode 100644 index 000000000..7d0be8ff2 --- /dev/null +++ b/gems/cache_method/.rubocop.yml @@ -0,0 +1,19 @@ +# This configuration inherits from /.rubocop.yml. +# You can configure RBS style of this gem. +# This file is used on CI. It is configured to automatically +# make rubocop suggestions on pull requests for this gem. +# If you do not like the style enforcement, you should remove this file. +inherit_from: ../../.rubocop.yml + +## +# If you want to customize the style, please consult with the gem reviewers. +# You can see the list of cops at https://github.com/ksss/rubocop-on-rbs/blob/main/docs/modules/ROOT/pages/cops.adoc + +RBS/Layout: + Enabled: true + +RBS/Lint: + Enabled: true + +RBS/Style: + Enabled: true diff --git a/gems/cache_method/0.2/_test/metadata.yaml b/gems/cache_method/0.2/_test/metadata.yaml new file mode 100644 index 000000000..29015bc02 --- /dev/null +++ b/gems/cache_method/0.2/_test/metadata.yaml @@ -0,0 +1,4 @@ +# If the test needs gem's RBS files, declare them here. +# +# additional_gems: +# - GEM_NAME diff --git a/gems/cache_method/0.2/_test/test.rb b/gems/cache_method/0.2/_test/test.rb new file mode 100644 index 000000000..7621842be --- /dev/null +++ b/gems/cache_method/0.2/_test/test.rb @@ -0,0 +1,41 @@ +require "cache_method" + +CacheMethod.config.default_ttl = 120 +CacheMethod.config.default_generational_ttl = 0 +CacheMethod.config.generational = true +CacheMethod.config.generational?.then { |generational| generational & true } +CacheMethod.config.default_ttl.succ +CacheMethod.digest([1, "two"]).length + +class Blog + def entries(date) + "entries for #{date}" + end + cache_method :entries, 60 + + def title + "Blog" + end + cache_method :title + + def update(stuff) + stuff + end + cache_method_clear_on :update, :entries + + def as_cache_key + { name: "blog" } + end +end + +module Feeds + def self.latest + [1, 2, 3] + end +end + +blog = Blog.new +blog.cache_method_clear(:entries) +blog.cache_method_cached?(:entries, "2024-01-01") & true +Blog.cache_method_clear(:entries) +Feeds.cache_method_cached?(:latest) & true diff --git a/gems/cache_method/0.2/_test/test.rbs b/gems/cache_method/0.2/_test/test.rbs new file mode 100644 index 000000000..50641050a --- /dev/null +++ b/gems/cache_method/0.2/_test/test.rbs @@ -0,0 +1,13 @@ +class Blog + def entries: (String date) -> String + + def title: () -> String + + def update: (String stuff) -> String + + def as_cache_key: () -> Hash[Symbol, String] +end + +module Feeds + def self.latest: () -> Array[Integer] +end diff --git a/gems/cache_method/0.2/cache_method.rbs b/gems/cache_method/0.2/cache_method.rbs new file mode 100644 index 000000000..5934b0e0f --- /dev/null +++ b/gems/cache_method/0.2/cache_method.rbs @@ -0,0 +1,56 @@ +module CacheMethod + VERSION: String + + MUTEX: Thread::Mutex + + CACHE_KEY_JOINER: String + + def self.config: () -> Config + + def self.resolve_cache_key: (untyped obj) -> untyped + + def self.digest: (untyped obj) -> String + + class Config + def initialize: () -> void + + def generational=: (boolish boolean) -> boolish + + def generational?: () -> bool + + # Wrapped with `Cache.wrap` from the cache gem. + def storage=: (untyped storage) -> untyped + + def storage: () -> untyped + + def default_ttl=: (Integer seconds) -> Integer + + def default_ttl: () -> Integer + + def default_generational_ttl=: (Integer seconds) -> Integer + + def default_generational_ttl: () -> Integer + end + + # Included into Object, so every object and class gets these methods. + module InstanceMethods : BasicObject + def cache_method_clear: (Symbol | String method_id) -> void + + def cache_method_cached?: (Symbol | String method_id, *untyped args) -> bool + end + + # Included into Class and Module, so class bodies can call these methods. + module ClassMethods + def cache_method: (Symbol | String method_id, ?Integer? ttl) -> Symbol + + def cache_method_clear_on: (Symbol | String method_id, Symbol | String cache_method_clear_id) -> Symbol + end +end + +class Object + include CacheMethod::InstanceMethods +end + +class Module + include CacheMethod::ClassMethods +end diff --git a/gems/cache_method/_reviewers.yaml b/gems/cache_method/_reviewers.yaml new file mode 100644 index 000000000..8d710c457 --- /dev/null +++ b/gems/cache_method/_reviewers.yaml @@ -0,0 +1,2 @@ +reviewers: + - apiology From 346be4e43b130837e90d2c1ca5a45e065432fd07 Mon Sep 17 00:00:00 2001 From: Vince Broz Date: Mon, 19 Oct 2026 13:19:55 -0400 Subject: [PATCH 2/2] Make cache_method storage= argument optional Config#storage= is defined as storage=(storage = nil). Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01Wo4FerFK9aaxrGrmVE9ncZ --- gems/cache_method/0.2/cache_method.rbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gems/cache_method/0.2/cache_method.rbs b/gems/cache_method/0.2/cache_method.rbs index 5934b0e0f..0c2ca6551 100644 --- a/gems/cache_method/0.2/cache_method.rbs +++ b/gems/cache_method/0.2/cache_method.rbs @@ -19,7 +19,7 @@ module CacheMethod def generational?: () -> bool # Wrapped with `Cache.wrap` from the cache gem. - def storage=: (untyped storage) -> untyped + def storage=: (?untyped storage) -> untyped def storage: () -> untyped