Class: Attrio::DefaultValue::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/attrio/default_value/base.rb

Direct Known Subclasses

Callable, Clonable, Symbol

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, value) ⇒ Base

Returns a new instance of Base.



18
19
20
# File 'lib/attrio/default_value/base.rb', line 18

def initialize(attribute, value)
  @attribute = attribute; @value = value;
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



6
7
8
# File 'lib/attrio/default_value/base.rb', line 6

def attribute
  @attribute
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'lib/attrio/default_value/base.rb', line 6

def value
  @value
end

Class Method Details

.handle(attribute, value) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/attrio/default_value/base.rb', line 8

def self.handle(attribute, value)
  handler = [
    Attrio::DefaultValue::Callable,
    Attrio::DefaultValue::Clonable,
    Attrio::DefaultValue::Symbol
  ].detect{ |handler| handler.handle?(value) }

  handler.new(attribute, value) if handler.present?
end

Instance Method Details

#call(instance) ⇒ Object

Evaluates the value

Returns:

  • (Object)

    evaluated value

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/attrio/default_value/base.rb', line 25

def call(instance)
  raise NotImplementedError
end