Class: FallsBackOn::Definition
- Inherits:
-
Object
- Object
- FallsBackOn::Definition
- Defined in:
- lib/falls_back_on/definition.rb,
lib/falls_back_on/definition/storage.rb
Defined Under Namespace
Classes: Storage
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
-
#as_cache_key ⇒ Object
for cache_method.
-
#as_lock ⇒ Object
for lock_method.
- #attrs ⇒ Object
- #attrs=(attrs) ⇒ Object
- #calculate(k) ⇒ Object
- #clear ⇒ Object
-
#initialize(parent) ⇒ Definition
constructor
A new instance of Definition.
Constructor Details
#initialize(parent) ⇒ Definition
Returns a new instance of Definition.
11 12 13 |
# File 'lib/falls_back_on/definition.rb', line 11 def initialize(parent) @parent = parent.to_s end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
9 10 11 |
# File 'lib/falls_back_on/definition.rb', line 9 def parent @parent end |
Class Method Details
.all ⇒ Object
5 6 7 |
# File 'lib/falls_back_on/definition.rb', line 5 def self.all Storage.instance.keys.map { |parent| new parent } end |
Instance Method Details
#as_cache_key ⇒ Object
for cache_method
51 52 53 |
# File 'lib/falls_back_on/definition.rb', line 51 def as_cache_key parent end |
#as_lock ⇒ Object
for lock_method
47 48 49 |
# File 'lib/falls_back_on/definition.rb', line 47 def as_lock parent end |
#attrs ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/falls_back_on/definition.rb', line 25 def attrs return {} unless Storage.instance[parent].is_a?(::Hash) Storage.instance[parent].inject({}) do |memo, (k, v)| memo[k] = calculate k memo end end |
#attrs=(attrs) ⇒ Object
21 22 23 |
# File 'lib/falls_back_on/definition.rb', line 21 def attrs=(attrs) Storage.instance[parent] = attrs end |
#calculate(k) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/falls_back_on/definition.rb', line 35 def calculate(k) v = Storage.instance[parent][k] case v when Proc v.call else v end end |
#clear ⇒ Object
15 16 17 18 19 |
# File 'lib/falls_back_on/definition.rb', line 15 def clear cache_method_clear :calculate cache_method_clear :attrs lock_method_clear :attrs end |