Class: Granite::Form::Model::Attributes::Reflections::Base
- Inherits:
-
Object
- Object
- Granite::Form::Model::Attributes::Reflections::Base
show all
- Defined in:
- lib/granite/form/model/attributes/reflections/base.rb,
lib/granite/form/model/attributes/reflections/base/build_type_definition.rb
Defined Under Namespace
Classes: BuildTypeDefinition
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, *args, &block) ⇒ Base
Returns a new instance of Base.
22
23
24
25
26
27
28
|
# File 'lib/granite/form/model/attributes/reflections/base.rb', line 22
def initialize(name, *args, &block)
@name = name.to_s
@options = args.
@options[:type] = args.first if args.first
@options[:default] = block if block
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/granite/form/model/attributes/reflections/base.rb', line 7
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
7
8
9
|
# File 'lib/granite/form/model/attributes/reflections/base.rb', line 7
def options
@options
end
|
Class Method Details
.attribute_class ⇒ Object
17
18
19
|
# File 'lib/granite/form/model/attributes/reflections/base.rb', line 17
def attribute_class
@attribute_class ||= "Granite::Form::Model::Attributes::#{name.demodulize}".constantize
end
|
.build(_target, generated_methods, name, *args, &block) ⇒ Object
10
11
12
13
|
# File 'lib/granite/form/model/attributes/reflections/base.rb', line 10
def build(_target, generated_methods, name, *args, &block)
generate_methods name, generated_methods
new(name, *args, &block)
end
|
.generate_methods(name, target) ⇒ Object
15
|
# File 'lib/granite/form/model/attributes/reflections/base.rb', line 15
def generate_methods(name, target) end
|
Instance Method Details
#build_attribute(owner, raw_value = Granite::Form::UNDEFINED) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/granite/form/model/attributes/reflections/base.rb', line 30
def build_attribute(owner, raw_value = Granite::Form::UNDEFINED)
type_definition = self.class::BuildTypeDefinition.new(owner, self).call
attribute = self.class.attribute_class.new(type_definition)
attribute.write_value(raw_value, origin: :persistence) unless raw_value == Granite::Form::UNDEFINED
attribute
end
|
#enum ⇒ Object
45
46
47
|
# File 'lib/granite/form/model/attributes/reflections/base.rb', line 45
def enum
options[:enum] || options[:in]
end
|
#inspect_reflection ⇒ Object
53
54
55
|
# File 'lib/granite/form/model/attributes/reflections/base.rb', line 53
def inspect_reflection
"#{name}: #{type}"
end
|
#keys ⇒ Object
49
50
51
|
# File 'lib/granite/form/model/attributes/reflections/base.rb', line 49
def keys
@keys ||= Array.wrap(options[:keys]).map(&:to_s)
end
|
#readonly ⇒ Object
41
42
43
|
# File 'lib/granite/form/model/attributes/reflections/base.rb', line 41
def readonly
options[:readonly]
end
|
#type ⇒ Object
37
38
39
|
# File 'lib/granite/form/model/attributes/reflections/base.rb', line 37
def type
options[:type]
end
|