Module: Material::Attributes
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/material/concerns/attributes.rb
Instance Method Summary collapse
- #attribute_types ⇒ Object
- #attribute_values ⇒ Object
- #formatted_attributes ⇒ Object
- #human_attribute_value(attribute) ⇒ Object
- #relationship_attributes ⇒ Object
- #sorted_attribute_names ⇒ Object
Instance Method Details
#attribute_types ⇒ Object
35 36 37 |
# File 'lib/material/concerns/attributes.rb', line 35 def attribute_types attribute_names.each_with_object({}) { |attribute, hash| hash[attribute] = type_for_attribute(attribute).type } end |
#attribute_values ⇒ Object
31 32 33 |
# File 'lib/material/concerns/attributes.rb', line 31 def attribute_values attribute_names.each_with_object({}) { |attribute, hash| hash[attribute] = public_send(attribute.to_sym) } end |
#formatted_attributes ⇒ Object
39 40 41 42 43 |
# File 'lib/material/concerns/attributes.rb', line 39 def formatted_attributes attribute_types.each_with_object({}) do |(attribute, attribute_type), hash| hash[attribute] = format_by_type(attribute_values[attribute], type: attribute_type) end end |
#human_attribute_value(attribute) ⇒ Object
27 28 29 |
# File 'lib/material/concerns/attributes.rb', line 27 def human_attribute_value(attribute) formatted_attributes.fetch(attribute) end |
#relationship_attributes ⇒ Object
53 54 55 |
# File 'lib/material/concerns/attributes.rb', line 53 def relationship_attributes source_class.reflect_on_all_associations.map(&:foreign_key) end |
#sorted_attribute_names ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/material/concerns/attributes.rb', line 45 def sorted_attribute_names [ (head_attributes & attribute_names), (attribute_names - head_attributes - tail_attributes).sort, (tail_attributes & attribute_names), ].flatten end |