Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gems/cache_method/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions gems/cache_method/0.2/_test/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# If the test needs gem's RBS files, declare them here.
#
# additional_gems:
# - GEM_NAME
41 changes: 41 additions & 0 deletions gems/cache_method/0.2/_test/test.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions gems/cache_method/0.2/_test/test.rbs
Original file line number Diff line number Diff line change
@@ -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
56 changes: 56 additions & 0 deletions gems/cache_method/0.2/cache_method.rbs
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions gems/cache_method/_reviewers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
reviewers:
- apiology
Loading