Module: Material::Attributes

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/material/concerns/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute_typesObject



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_valuesObject



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_attributesObject



31
32
33
# File 'lib/material/concerns/attributes.rb', line 31

def display_attributes
  attribute_names
end

#formatted_attributesObject



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_attributesObject



57
58
59
# File 'lib/material/concerns/attributes.rb', line 57

def relationship_attributes
  source_class.reflect_on_all_associations.map(&:foreign_key)
end

#sorted_attribute_namesObject



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