Class: Spectifly::Base::Builder
- Inherits:
-
Object
- Object
- Spectifly::Base::Builder
show all
- Defined in:
- lib/spectifly/base/builder.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(entity, options = {}) ⇒ Builder
Returns a new instance of Builder.
19
20
21
22
|
# File 'lib/spectifly/base/builder.rb', line 19
def initialize(entity, options = {})
@options = options
@entity = entity
end
|
Class Method Details
.from_path(path, options = {}) ⇒ Object
10
11
12
|
# File 'lib/spectifly/base/builder.rb', line 10
def from_path(path, options = {})
new(Spectifly::Entity.parse(path), options)
end
|
Instance Method Details
#association_class ⇒ Object
93
94
95
|
# File 'lib/spectifly/base/builder.rb', line 93
def association_class
eval("#{self.class.module_name}::Association")
end
|
#associations ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/spectifly/base/builder.rb', line 60
def associations
@associations ||= begin
associations = []
@entity.relationships.each do |relationship_type, type_associations|
relationship_type = Spectifly::Support.tokenize(relationship_type)
type_associations.each do |name, attributes|
associations << association_class.new(
name.dup, attributes.dup.merge(:relationship => relationship_type)
)
end
end
associations
end
end
|
#build ⇒ Object
97
98
99
|
# File 'lib/spectifly/base/builder.rb', line 97
def build
raise 'Subclass Responsibility'
end
|
#custom_types ⇒ Object
46
47
48
|
# File 'lib/spectifly/base/builder.rb', line 46
def custom_types
types - native_types - utilized_extended_types.keys
end
|
#field_class ⇒ Object
89
90
91
|
# File 'lib/spectifly/base/builder.rb', line 89
def field_class
eval("#{self.class.module_name}::Field")
end
|
#fields ⇒ Object
50
51
52
53
54
55
56
57
58
|
# File 'lib/spectifly/base/builder.rb', line 50
def fields
@fields ||= begin
fields = []
@entity.fields.each do |name, attributes|
fields << field_class.new(name.dup, attributes.dup)
end
fields
end
end
|
#native_types ⇒ Object
33
34
35
36
37
|
# File 'lib/spectifly/base/builder.rb', line 33
def native_types
@native_types ||= begin
eval("#{self.class.module_name}::Types::Native")
end
end
|
#present_as(presenter_entity) ⇒ Object
24
25
26
27
|
# File 'lib/spectifly/base/builder.rb', line 24
def present_as(presenter_entity)
@entity = @entity.present_as(presenter_entity)
self
end
|
#root ⇒ Object
85
86
87
|
# File 'lib/spectifly/base/builder.rb', line 85
def root
@entity.root
end
|
#types ⇒ Object
29
30
31
|
# File 'lib/spectifly/base/builder.rb', line 29
def types
[fields.map(&:type) + associations.map(&:type)].flatten.compact.uniq
end
|
#utilized_extended_type_fields ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'lib/spectifly/base/builder.rb', line 75
def utilized_extended_type_fields
@utilized_extended_type_fields ||= begin
fields = []
utilized_extended_types.each do |name, attributes|
fields << field_class.new(name.dup, attributes.dup)
end
fields
end
end
|
#utilized_extended_types ⇒ Object
39
40
41
42
43
44
|
# File 'lib/spectifly/base/builder.rb', line 39
def utilized_extended_types
@utilized_extended_types ||= begin
extended_types = eval("#{self.class.module_name}::Types::Extended")
extended_types.select { |k, v| types.include?(k) }
end
end
|