Class: ActiveRecord::Defaults::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/defaults.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, value) ⇒ Default

Returns a new instance of Default.



117
118
119
# File 'lib/active_record/defaults.rb', line 117

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

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



115
116
117
# File 'lib/active_record/defaults.rb', line 115

def attribute
  @attribute
end

Instance Method Details

#value(record) ⇒ Object



121
122
123
124
125
126
127
128
129
# File 'lib/active_record/defaults.rb', line 121

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