Class: Granite::Represents::Reflection

Inherits:
Form::Model::Attributes::Reflections::Represents
  • Object
show all
Defined in:
lib/granite/represents/reflection.rb

Class Method Summary collapse

Class Method Details

.attribute_classObject



18
19
20
# File 'lib/granite/represents/reflection.rb', line 18

def attribute_class
  @attribute_class ||= Granite::Represents::Attribute
end

.build(target, generated_methods, name, *args, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/granite/represents/reflection.rb', line 7

def build(target, generated_methods, name, *args, &block)
  options = args.last

  reference = target.reflect_on_association(options[:of]) if target.respond_to?(:reflect_on_association)
  reference ||= target.reflect_on_attribute(options[:of]) if target.respond_to?(:reflect_on_attribute)

  target.validates_presence_of(reference.name) if reference

  super(target, generated_methods, name, *args, &block)
end