Class: Foobara::Manifest::BaseManifest
- Inherits:
-
Object
- Object
- Foobara::Manifest::BaseManifest
show all
- Includes:
- TruncatedInspect
- Defined in:
- foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb
Constant Summary
TruncatedInspect::MAX_LENGTH
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#inspect, truncating
Constructor Details
#initialize(root_manifest, path) ⇒ BaseManifest
Returns a new instance of BaseManifest.
52
53
54
55
56
57
58
59
60
61
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 52
def initialize(root_manifest, path)
self.root_manifest = root_manifest
self.path = path
if relevant_manifest.nil?
raise InvalidPath, "invalid path #{path}"
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 113
def method_missing(method_name, *, &)
if key?(method_name)
self[method_name]
elsif optional_key?(method_name)
self.class.optional_key_defaults[method_name.to_sym]
else
super
end
end
|
Class Attribute Details
.category_symbol ⇒ Object
Returns the value of attribute category_symbol.
11
12
13
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 11
def category_symbol
@category_symbol
end
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
8
9
10
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 8
def path
@path
end
|
#root_manifest ⇒ Object
Returns the value of attribute root_manifest.
8
9
10
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 8
def root_manifest
@root_manifest
end
|
Class Method Details
.category_to_manifest_class(category_symbol) ⇒ Object
43
44
45
46
47
48
49
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 43
def category_to_manifest_class(category_symbol)
category_symbol = category_symbol.to_sym
Util.descendants(BaseManifest).find do |manifest_class|
manifest_class.category_symbol == category_symbol
end
end
|
.optional_key(value, default: nil) ⇒ Object
39
40
41
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 39
def optional_key(value, default: nil)
optional_keys(value, default:)
end
|
.optional_key_defaults ⇒ Object
35
36
37
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 35
def optional_key_defaults
@optional_key_defaults ||= {}
end
|
.optional_keys(*values, default: nil) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 13
def optional_keys(*values, default: nil)
if values.empty?
@optional_keys ||= if superclass == Object
Set.new
else
superclass.optional_keys.dup
end
else
if default
default = default.freeze
end
values.each do |value|
value = value.to_sym
optional_keys << value
if default
optional_key_defaults[value] = default
end
end
end
end
|
Instance Method Details
#==(other) ⇒ Object
148
149
150
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 148
def ==(other)
other.class == self.class && other.path.map(&:to_sym) == path.map(&:to_sym)
end
|
#[](method_name) ⇒ Object
125
126
127
128
129
130
131
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 125
def [](method_name)
if relevant_manifest.key?(method_name.to_sym)
relevant_manifest[method_name.to_sym]
elsif relevant_manifest.key?(method_name.to_s)
relevant_manifest[method_name.to_s]
end
end
|
#domain ⇒ Object
63
64
65
66
67
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 63
def domain
domain_reference = self[:domain]
Domain.new(root_manifest, [:domain, domain_reference])
end
|
#eql?(other) ⇒ Boolean
152
153
154
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 152
def eql?(other)
self == other
end
|
#find_type(type_declaration) ⇒ Object
99
100
101
102
103
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 99
def find_type(type_declaration)
type_symbol = type_declaration.type
Type.new(root_manifest, [:type, type_symbol])
end
|
#global_domain ⇒ Object
105
106
107
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 105
def global_domain
Domain.new(root_manifest, %i[domain global_organization::global_domain])
end
|
#global_organization ⇒ Object
109
110
111
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 109
def global_organization
Organization.new(root_manifest, %i[organization global_organization])
end
|
#hash ⇒ Object
156
157
158
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 156
def hash
[root_manifest, path.map(&:to_sym)].hash
end
|
#key?(method_name) ⇒ Boolean
133
134
135
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 133
def key?(method_name)
relevant_manifest.key?(method_name.to_sym) || relevant_manifest.key?(method_name.to_s)
end
|
#optional_key?(key) ⇒ Boolean
137
138
139
140
141
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 137
def optional_key?(key)
if key.is_a?(::Symbol) || key.is_a?(::String)
self.class.optional_keys.include?(key.to_sym)
end
end
|
#organization ⇒ Object
69
70
71
72
73
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 69
def organization
organization_reference = self[:organization]
Organization.new(root_manifest, [:organization, organization_reference])
end
|
#parent ⇒ Object
75
76
77
78
79
80
81
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 75
def parent
if parent_category
parent_class = self.class.category_to_manifest_class(parent_category)
parent_class&.new(root_manifest, self[:parent])
end
end
|
#parent_category ⇒ Object
83
84
85
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 83
def parent_category
self[:parent]&.first
end
|
#parent_name ⇒ Object
87
88
89
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 87
def parent_name
self[:parent]&.last
end
|
#relevant_manifest ⇒ Object
95
96
97
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 95
def relevant_manifest
@relevant_manifest ||= Foobara::DataPath.values_at(path, root_manifest).first
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
143
144
145
146
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 143
def respond_to_missing?(method_name, include_private = false)
relevant_manifest.key?(method_name.to_sym) || relevant_manifest.key?(method_name.to_s) ||
optional_key?(method_name) || super
end
|
#scoped_category ⇒ Object
91
92
93
|
# File 'foobara-0.0.110/projects/manifest/src/foobara/manifest/base_manifest.rb', line 91
def scoped_category
self[:scoped_category]
end
|