Class: ForemanMaintain::Concerns::Metadata::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/foreman_maintain/concerns/metadata.rb

Direct Known Subclasses

ScenarioMetadata::DSL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ DSL

Returns a new instance of DSL.



15
16
17
# File 'lib/foreman_maintain/concerns/metadata.rb', line 15

def initialize(data = {})
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/foreman_maintain/concerns/metadata.rb', line 13

def data
  @data
end

Class Method Details

.eval_dsl(metadata, &block) ⇒ Object



103
104
105
106
107
# File 'lib/foreman_maintain/concerns/metadata.rb', line 103

def self.eval_dsl(, &block)
  new().tap do |dsl|
    dsl.instance_eval(&block)
  end.data
end

Instance Method Details

#advanced_run(advanced_run) ⇒ Object



99
100
101
# File 'lib/foreman_maintain/concerns/metadata.rb', line 99

def advanced_run(advanced_run)
  @data[:advanced_run] = advanced_run
end

#after(*step_labels) ⇒ Object



40
41
42
# File 'lib/foreman_maintain/concerns/metadata.rb', line 40

def after(*step_labels)
  @data[:after].concat(step_labels)
end

#before(*step_labels) ⇒ Object



35
36
37
38
# File 'lib/foreman_maintain/concerns/metadata.rb', line 35

def before(*step_labels)
  raise Error::MultipleBeforeDetected, step_labels if step_labels.count > 1
  @data[:before].concat(step_labels)
end

#confine(&block) ⇒ Object



31
32
33
# File 'lib/foreman_maintain/concerns/metadata.rb', line 31

def confine(&block)
  @data[:confine_blocks] << block
end

#description(description) ⇒ Object



27
28
29
# File 'lib/foreman_maintain/concerns/metadata.rb', line 27

def description(description)
  @data[:description] = description
end

#for_feature(feature_label) ⇒ Object

Specify what feature the definition related to.



86
87
88
89
90
91
# File 'lib/foreman_maintain/concerns/metadata.rb', line 86

def for_feature(feature_label)
  @data[:for_feature] = feature_label
  confine do
    feature(feature_label)
  end
end

#label(label) ⇒ Object



19
20
21
# File 'lib/foreman_maintain/concerns/metadata.rb', line 19

def label(label)
  @data[:label] = label
end

#manual_detectionObject

Mark the class as manual: this means the instance of class will not be initialized by detector to check the confine block to determine if it’s valid on the system or not. The classes marked for manual detect need to be initialized in from other places (such as ‘additional_features` in Feature)



75
76
77
# File 'lib/foreman_maintain/concerns/metadata.rb', line 75

def manual_detection
  @data[:autodetect] = false
end

#param(name, descripiton_or_options = {}, options = {}, &block) ⇒ Object

Parametrize the definition.

Arguments

+name+: Name (Symbol) of the attribute
+description_or_options+: Description string or a Hash with options
+options+: Hash with options (unless specified in +descriptions_or_options+)
+&block+: block to be called when processing the data: can be used for validation
   and type-casing of the value: expected to return the value to be used

Options

+:description+: String describing the parameter
+:required+: true if required
+:flag+: param is just a true/false value: not expecting other values


60
61
62
63
64
65
66
67
68
# File 'lib/foreman_maintain/concerns/metadata.rb', line 60

def param(name, descripiton_or_options = {}, options = {}, &block)
  case descripiton_or_options
  when String
    description = descripiton_or_options
  when Hash
    options = options.merge(descripiton_or_options) if descripiton_or_options.is_a?(Hash)
  end
  @data[:params][name] = Param.new(name, description, options, &block)
end

#preparation_steps(&block) ⇒ Object

in the block, define one or more preparation steps needed before executing this definition



81
82
83
# File 'lib/foreman_maintain/concerns/metadata.rb', line 81

def preparation_steps(&block)
  @data[:preparation_steps_blocks] << block
end

#run_onceObject

Ensure to not run the step twice: expects the scenario to be persisted between runs to work properly



95
96
97
# File 'lib/foreman_maintain/concerns/metadata.rb', line 95

def run_once
  @data[:run_once] = true
end

#tags(*tags) ⇒ Object



23
24
25
# File 'lib/foreman_maintain/concerns/metadata.rb', line 23

def tags(*tags)
  @data[:tags].concat(tags)
end