Class: IdentityCache::Cached::AttributeByOne
- Defined in:
- lib/identity_cache/cached/attribute_by_one.rb
Instance Attribute Summary collapse
-
#key_field ⇒ Object
readonly
Returns the value of attribute key_field.
Attributes inherited from Attribute
#alias_name, #key_fields, #model, #unique
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize ⇒ AttributeByOne
constructor
A new instance of AttributeByOne.
Methods inherited from Attribute
#attribute, #cache_encode, #cache_key, #expire, #fetch, #fetch_multi, #load_multi_from_db, #load_one_from_db
Constructor Details
#initialize ⇒ AttributeByOne
Returns a new instance of AttributeByOne.
8 9 10 11 |
# File 'lib/identity_cache/cached/attribute_by_one.rb', line 8 def initialize(*) super @key_field = key_fields.first end |
Instance Attribute Details
#key_field ⇒ Object (readonly)
Returns the value of attribute key_field.
6 7 8 |
# File 'lib/identity_cache/cached/attribute_by_one.rb', line 6 def key_field @key_field end |
Instance Method Details
#build ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/identity_cache/cached/attribute_by_one.rb', line 13 def build cached_attribute = self model.define_singleton_method(:"fetch_#{fetch_method_suffix}") do |key| raise_if_scoped cached_attribute.fetch(key) end model.define_singleton_method(:"fetch_multi_#{fetch_method_suffix}") do |keys| raise_if_scoped cached_attribute.fetch_multi(keys) end end |