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_checks, #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
120
121
122
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 120
def abstract_class
!(superclass < Metadata)
end
|
#advanced_run? ⇒ Boolean
181
182
183
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 181
def advanced_run?
metadata[:advanced_run]
end
|
#after ⇒ Object
173
174
175
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 173
def after
metadata[:after] || []
end
|
#all_sub_classes(ignore_abstract_classes = true) ⇒ Object
132
133
134
135
136
137
138
139
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 132
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
128
129
130
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 128
def autodetect?
metadata.fetch(:autodetect, true)
end
|
#before ⇒ Object
169
170
171
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 169
def before
metadata[:before] || []
end
|
#description ⇒ Object
157
158
159
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 157
def description
metadata[:description] || to_s
end
|
#inherited(klass) ⇒ Object
113
114
115
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 113
def inherited(klass)
sub_classes << klass
end
|
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 185
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
153
154
155
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 153
def label
metadata[:label] || generate_label
end
|
141
142
143
144
145
146
147
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 141
def metadata(&block)
@metadata ||= initialize_metadata
if block
metadata_class.eval_dsl(@metadata, &block)
end
@metadata
end
|
149
150
151
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 149
def metadata_class
DSL
end
|
#params ⇒ Object
165
166
167
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 165
def params
metadata[:params] || {}
end
|
#preparation_steps(recursion_depth = 0, trace = []) ⇒ Object
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 203
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
199
200
201
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 199
def present?
evaluate_confines
end
|
#run_once? ⇒ Boolean
177
178
179
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 177
def run_once?
metadata[:run_once]
end
|
#sub_classes ⇒ Object
124
125
126
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 124
def sub_classes
@sub_classes ||= []
end
|
161
162
163
|
# File 'lib/foreman_maintain/concerns/metadata.rb', line 161
def tags
metadata[:tags]
end
|