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_value(values, value) ⇒ Object
we take the values because that contains the humanizations in case humanizations are hard-coded as a hash.
- #humanized_values(record) ⇒ Object
-
#initialize(*args) ⇒ ScalarAttribute
constructor
A new instance of ScalarAttribute.
Methods inherited from Base
#assignable_value?, #assignable_values, #error_property, #not_included_error_message, #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_values_instance_method end |
Instance Method Details
#humanized_value(values, value) ⇒ Object
we take the values because that contains the humanizations in case humanizations are hard-coded as a hash
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/assignable_values/active_record/restriction/scalar_attribute.rb', line 13 def humanized_value(values, value) # we take the values because that contains the humanizations in case humanizations are hard-coded as a hash if value.present? if values && values.respond_to?(:humanizations) values.humanizations[value] else dictionary_scope = "assignable_values.#{model.name.underscore}.#{property}" I18n.t(value, :scope => dictionary_scope, :default => default_humanization_for_value(value)) end end end |
#humanized_values(record) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/assignable_values/active_record/restriction/scalar_attribute.rb', line 24 def humanized_values(record) values = assignable_values(record) values.collect do |value| HumanizedValue.new(value, humanized_value(values, value)) end end |