Class: WonderNavigation::DeferrableOption

Inherits:
Object
  • Object
show all
Defined in:
lib/wonder_navigation/deferrable_option.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @fixed_value_assigned = options.has_key?(:fixed) && !options[:fixed].nil?
  @fixed_value = options[:fixed]
  @block       = options[:block]
  @name        = options[:name]
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/wonder_navigation/deferrable_option.rb', line 3

def block
  @block
end

#fixed_valueObject

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_assignedObject

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

#nameObject

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

Returns:

  • (Boolean)


12
13
14
# File 'lib/wonder_navigation/deferrable_option.rb', line 12

def present?
  fixed_value_assigned || !!block
end

#resolvable?(object) ⇒ Boolean

Returns:

  • (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