Module: ForemanMaintain::Concerns::Metadata::ClassMethods
- Includes:
- Finders
- Defined in:
- lib/foreman_maintain/concerns/metadata.rb
Instance Method Summary
collapse
Methods included from Finders
#check, #detector, #feature, #find_all_scenarios, #find_procedures, #find_scenarios, #procedure
Instance Method Details
#abstract_class ⇒ Object
Override if the class should be used as parent class only. By default, we assume the class that does’t inherit from class with Metadata is abstract = the base class of particular concept
124
125
126
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 124
def abstract_class
!(superclass < Metadata)
end
|
#advanced_run? ⇒ Boolean
185
186
187
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 185
def advanced_run?
metadata[:advanced_run]
end
|
#after ⇒ Object
177
178
179
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 177
def after
metadata[:after] || []
end
|
#all_sub_classes(ignore_abstract_classes = true) ⇒ Object
136
137
138
139
140
141
142
143
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 136
def all_sub_classes(ignore_abstract_classes = true)
ret = []
ret << self if !ignore_abstract_classes || !abstract_class
sub_classes.each do |sub_class|
ret.concat(sub_class.all_sub_classes(ignore_abstract_classes))
end
ret
end
|
#autodetect? ⇒ Boolean
132
133
134
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 132
def autodetect?
metadata.fetch(:autodetect, true)
end
|
#before ⇒ Object
173
174
175
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 173
def before
metadata[:before] || []
end
|
#description ⇒ Object
161
162
163
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 161
def description
metadata[:description] || to_s
end
|
#inherited(klass) ⇒ Object
117
118
119
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 117
def inherited(klass)
sub_classes << klass
end
|
189
190
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 189
def initialize_metadata
{ :tags => [],
:confine_blocks => [],
:params => {},
:preparation_steps_blocks => [],
:before => [],
:after => [],
:advanced_run => true }.tap do |metadata|
if superclass.respond_to?(:metadata)
metadata[:label] = superclass.metadata[:label]
end
end
end
|
#label ⇒ Object
157
158
159
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 157
def label
metadata[:label] || generate_label
end
|
145
146
147
148
149
150
151
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 145
def metadata(&block)
@metadata ||= initialize_metadata
if block
metadata_class.eval_dsl(@metadata, &block)
end
@metadata
end
|
153
154
155
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 153
def metadata_class
DSL
end
|
#params ⇒ Object
169
170
171
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 169
def params
metadata[:params] || {}
end
|
#preparation_steps(recursion_depth = 0, trace = []) ⇒ Object
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 207
def preparation_steps(recursion_depth = 0, trace = [])
raise "Too many dependent steps #{trace}" if recursion_depth > MAX_PREPARATION_STEPS_DEPTH
return @preparation_steps if defined?(@preparation_steps)
preparation_steps = metadata[:preparation_steps_blocks].map do |block|
instance_exec(&block)
end.flatten.compact
preparation_steps.each { |step| raise ArgumentError unless step.is_a?(Executable) }
all_preparation_steps = []
preparation_steps.each do |step|
all_preparation_steps.concat(
step.preparation_steps(recursion_depth + 1, trace + [step])
)
all_preparation_steps << step
end
@preparation_steps = all_preparation_steps
end
|
#present? ⇒ Boolean
203
204
205
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 203
def present?
evaluate_confines
end
|
#run_once? ⇒ Boolean
181
182
183
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 181
def run_once?
metadata[:run_once]
end
|
#sub_classes ⇒ Object
128
129
130
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 128
def sub_classes
@sub_classes ||= []
end
|
165
166
167
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 165
def tags
metadata[:tags]
end
|