Class: AttributeDefaults::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/attribute_defaults/default.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, value) ⇒ Default

Returns a new instance of Default.



5
6
7
# File 'lib/attribute_defaults/default.rb', line 5

def initialize(attribute, value)
  @attribute, @value = attribute.to_s, value
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



3
4
5
# File 'lib/attribute_defaults/default.rb', line 3

def attribute
  @attribute
end

Instance Method Details

#value(record) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/attribute_defaults/default.rb', line 9

def value(record)
  if @value.is_a?(Symbol)
    record.send(@value)
  elsif @value.respond_to?(:call)
    @value.call(record)
  else
    @value.duplicable? ? @value.dup : @value
  end
end