Class: AssignableValues::ActiveRecord::Restriction::ScalarAttribute
- Defined in:
- lib/assignable_values/active_record/restriction/scalar_attribute.rb
Instance Attribute Summary
Attributes inherited from Base
#default, #model, #options, #property, #secondary_default, #values
Instance Method Summary collapse
- #humanized_assignable_values(record, options = {}) ⇒ Object
- #humanized_value(klass, value) ⇒ Object
-
#initialize(*args) ⇒ ScalarAttribute
constructor
A new instance of ScalarAttribute.
Methods inherited from Base
#assignable_values, #set_default, #validate_record
Constructor Details
#initialize(*args) ⇒ ScalarAttribute
Returns a new instance of ScalarAttribute.
6 7 8 9 10 11 |
# File 'lib/assignable_values/active_record/restriction/scalar_attribute.rb', line 6 def initialize(*args) super define_humanized_value_instance_method define_humanized_value_class_method define_humanized_assignable_values_instance_method end |
Instance Method Details
#humanized_assignable_values(record, options = {}) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/assignable_values/active_record/restriction/scalar_attribute.rb', line 19 def humanized_assignable_values(record, = {}) values = assignable_values(record, ) values.collect do |value| HumanizedValue.new(value, humanized_value(record.class, value)) end end |
#humanized_value(klass, value) ⇒ Object
13 14 15 16 17 |
# File 'lib/assignable_values/active_record/restriction/scalar_attribute.rb', line 13 def humanized_value(klass, value) if value.present? humanization_from_i18n(klass, value) || default_humanization_for_value(value) end end |