Class: Granite::Form::Model::Attributes::Reflections::ReferenceOne

Inherits:
Base
  • Object
show all
Defined in:
lib/granite/form/model/attributes/reflections/reference_one.rb

Direct Known Subclasses

ReferenceMany

Instance Attribute Summary

Attributes inherited from Base

#name, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

attribute_class, build, #build_attribute, #enum, #initialize, #keys, #readonly, #type

Constructor Details

This class inherits a constructor from Granite::Form::Model::Attributes::Reflections::Base

Class Method Details

.generate_methods(name, target) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/granite/form/model/attributes/reflections/reference_one.rb', line 7

def self.generate_methods(name, target)
  target.class_eval "  def \#{name}\n    attribute('\#{name}').read\n  end\n\n  def \#{name}= value\n    attribute('\#{name}').write(value)\n  end\n\n  def \#{name}?\n    attribute('\#{name}').query\n  end\n\n  def \#{name}_before_type_cast\n    attribute('\#{name}').read_before_type_cast\n  end\n  RUBY\nend\n", __FILE__, __LINE__ + 1

Instance Method Details

#associationObject



31
32
33
# File 'lib/granite/form/model/attributes/reflections/reference_one.rb', line 31

def association
  @association ||= options[:association].to_s
end

#inspect_reflectionObject



27
28
29
# File 'lib/granite/form/model/attributes/reflections/reference_one.rb', line 27

def inspect_reflection
  "#{name}: (reference)"
end