module Material::Attributes

Public Instance Methods

attribute_types() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/material/concerns/attributes.rb, line 31
def display_attributes
  attribute_names
end
formatted_attributes() click to toggle source
# 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
head_attributes() click to toggle source
# File lib/material/concerns/attributes.rb, line 18
def head_attributes
  %w[id]
end
human_attribute_value(attribute) click to toggle source
# File lib/material/concerns/attributes.rb, line 27
def human_attribute_value(attribute)
  formatted_attributes.fetch(attribute)
end
relationship_attributes() click to toggle source
# File lib/material/concerns/attributes.rb, line 57
def relationship_attributes
  source_class.reflect_on_all_associations.map(&:foreign_key)
end
sorted_attribute_names() click to toggle source
# 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
tail_attributes() click to toggle source
# File lib/material/concerns/attributes.rb, line 22
def tail_attributes
  %w[created_at updated_at]
end