Class: WonderNavigation::DeferrableOption
- Inherits:
-
Object
- Object
- WonderNavigation::DeferrableOption
- Defined in:
- lib/wonder_navigation/deferrable_option.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#fixed_value ⇒ Object
Returns the value of attribute fixed_value.
-
#fixed_value_assigned ⇒ Object
Returns the value of attribute fixed_value_assigned.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ DeferrableOption
constructor
A new instance of DeferrableOption.
- #present? ⇒ Boolean
- #resolvable?(object) ⇒ Boolean
- #resolve(object) ⇒ Object
- #try_resolve(object) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ DeferrableOption
Returns a new instance of DeferrableOption.
5 6 7 8 9 10 |
# File 'lib/wonder_navigation/deferrable_option.rb', line 5 def initialize( = {}) @fixed_value_assigned = .has_key?(:fixed) && ![:fixed].nil? @fixed_value = [:fixed] @block = [:block] @name = [:name] end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
3 4 5 |
# File 'lib/wonder_navigation/deferrable_option.rb', line 3 def block @block end |
#fixed_value ⇒ Object
Returns the value of attribute fixed_value.
3 4 5 |
# File 'lib/wonder_navigation/deferrable_option.rb', line 3 def fixed_value @fixed_value end |
#fixed_value_assigned ⇒ Object
Returns the value of attribute fixed_value_assigned.
3 4 5 |
# File 'lib/wonder_navigation/deferrable_option.rb', line 3 def fixed_value_assigned @fixed_value_assigned end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/wonder_navigation/deferrable_option.rb', line 3 def name @name end |
Instance Method Details
#present? ⇒ Boolean
12 13 14 |
# File 'lib/wonder_navigation/deferrable_option.rb', line 12 def present? fixed_value_assigned || !!block end |
#resolvable?(object) ⇒ Boolean
16 17 18 |
# File 'lib/wonder_navigation/deferrable_option.rb', line 16 def resolvable?(object) fixed_value_assigned || !!block && (!!object || block.arity.zero?) end |
#resolve(object) ⇒ Object
24 25 26 27 |
# File 'lib/wonder_navigation/deferrable_option.rb', line 24 def resolve(object) check_resolvable(object) fixed_value_assigned ? fixed_value : block.call(object) end |
#try_resolve(object) ⇒ Object
20 21 22 |
# File 'lib/wonder_navigation/deferrable_option.rb', line 20 def try_resolve(object) resolve(object) if resolvable?(object) end |