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
- #display_attributes ⇒ Object
- #formatted_attributes ⇒ Object
- #human_attribute_value(attribute) ⇒ Object
- #relationship_attributes ⇒ Object
- #sorted_attribute_names ⇒ Object
Instance Method Details
#attribute_types ⇒ Object
39 40 41 |
# File 'lib/material/concerns/attributes.rb', line 39 def attribute_types display_attributes.each_with_object({}) { |attribute, hash| hash[attribute] = type_for_attribute(attribute).type } end |
#attribute_values ⇒ Object
35 36 37 |
# File 'lib/material/concerns/attributes.rb', line 35 def attribute_values display_attributes.each_with_object({}) { |attribute, hash| hash[attribute] = public_send(attribute.to_sym) } end |
#display_attributes ⇒ Object
31 32 33 |
# File 'lib/material/concerns/attributes.rb', line 31 def display_attributes (attribute_names + relationship_attributes).uniq end |
#formatted_attributes ⇒ Object
43 44 45 46 47 |
# File 'lib/material/concerns/attributes.rb', line 43 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
57 58 59 |
# File 'lib/material/concerns/attributes.rb', line 57 def relationship_attributes source_class.reflect_on_all_associations.map(&:name).map(&:to_s) end |
#sorted_attribute_names ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/material/concerns/attributes.rb', line 49 def sorted_attribute_names [ (head_attributes & display_attributes), (display_attributes - head_attributes - tail_attributes).sort, (tail_attributes & display_attributes), ].flatten end |