Module: RactorRailsShim::IESAccessor
- Defined in:
- lib/ractor_rails_shim/foundation/ies_accessor.rb
Class Method Summary collapse
-
.define_accessor(target, attr_name, ies_key) ⇒ Object
Generate both reader and writer on
target. -
.define_reader(target, attr_name, ies_key) ⇒ Object
Generate a reader method on
targetthat does the 3-tier lookup. -
.define_writer(target, attr_name, ies_key) ⇒ Object
Generate a writer method on
targetthat stores via storage_strategy.
Class Method Details
.define_accessor(target, attr_name, ies_key) ⇒ Object
Generate both reader and writer on target.
53 54 55 56 |
# File 'lib/ractor_rails_shim/foundation/ies_accessor.rb', line 53 def self.define_accessor(target, attr_name, ies_key) define_reader(target, attr_name, ies_key) define_writer(target, attr_name, ies_key) end |
.define_reader(target, attr_name, ies_key) ⇒ Object
Generate a reader method on target that does the 3-tier lookup.
target is a Class or Module. attr_name is the method name (Symbol).
ies_key is the storage key (Symbol).
30 31 32 33 34 35 36 37 38 |
# File 'lib/ractor_rails_shim/foundation/ies_accessor.rb', line 30 def self.define_reader(target, attr_name, ies_key) key_str = ies_key.inspect target.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{attr_name} strategy = RactorRailsShim.storage_strategy strategy.lookup(self, #{key_str}, nil) end RUBY end |
.define_writer(target, attr_name, ies_key) ⇒ Object
Generate a writer method on target that stores via storage_strategy.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ractor_rails_shim/foundation/ies_accessor.rb', line 41 def self.define_writer(target, attr_name, ies_key) key_str = ies_key.inspect target.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{attr_name}=(val) strategy = RactorRailsShim.storage_strategy strategy.store(self, #{key_str}, val) val end RUBY end |