Class: Determinator::Models::Base
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Determinator::Models::Base
show all
- Defined in:
- lib/determinator/models/base.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
.elements ⇒ Object
Returns the value of attribute elements.
11
12
13
|
# File 'lib/determinator/models/base.rb', line 11
def elements
@elements
end
|
Class Method Details
.attribute(name, type, args = {}) ⇒ Object
13
14
15
16
|
# File 'lib/determinator/models/base.rb', line 13
def attribute(name, type, args={})
super(name, type)
element(name.to_s.chomp('?').to_sym, type, args)
end
|
.attribute?(name, type, args = {}) ⇒ Boolean
18
19
20
|
# File 'lib/determinator/models/base.rb', line 18
def attribute?(name, type, args={})
super(name, type)
end
|
.collect_elements(prefix = '') ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/determinator/models/base.rb', line 30
def collect_elements(prefix='')
@elements.map do |k, v|
if v.type.respond_to?(:collect_elements)
v.type.collect_elements("#{prefix}#{k}.")
else
[["#{prefix}#{k}", v]]
end
end.flatten(1)
end
|
.element(name, type, args = {}) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/determinator/models/base.rb', line 22
def element(name, type, args={})
if (args.keys - ARGS).length > 0
raise "Unrecognized arguments #{(args.keys - ARGS).join(', ')}"
end
@elements ||= {}
@elements[name] = Element.new(type, args[:descr])
end
|
Instance Method Details
#with(attributes = {}) ⇒ Object
41
42
43
|
# File 'lib/determinator/models/base.rb', line 41
def with(attributes={})
self.class.new(attributes.merge(to_h))
end
|