Module: Granite::Form::Model::Representation::ClassMethods

Defined in:
lib/granite/form/model/representation.rb

Instance Method Summary collapse

Instance Method Details

#represented_attributesObject



43
44
45
46
47
# File 'lib/granite/form/model/representation.rb', line 43

def represented_attributes
  @represented_attributes ||= _attributes.values.select do |attribute|
    attribute.is_a? Granite::Form::Model::Attributes::Reflections::Represents
  end
end

#represented_names_and_aliasesObject



49
50
51
52
53
# File 'lib/granite/form/model/representation.rb', line 49

def represented_names_and_aliases
  @represented_names_and_aliases ||= represented_attributes.flat_map do |attribute|
    [attribute.name, *inverted_attribute_aliases[attribute.name]]
  end
end

#represents(*names, &block) ⇒ Object



36
37
38
39
40
41
# File 'lib/granite/form/model/representation.rb', line 36

def represents(*names, &block)
  options = names.extract_options!
  names.each do |name|
    add_attribute(Granite::Form::Model::Attributes::Reflections::Represents, name, options, &block)
  end
end