Class: Nodectl::Recipe::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/nodectl/recipe.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, &blk) ⇒ DSL

Returns a new instance of DSL.



131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/nodectl/recipe.rb', line 131

def initialize(name, &blk)
  raise "Cannot create recipe without block" unless block_given?

  @name = name

  @actions  = {}
  @triggers = {}
  @events   = {}
  @logs     = {}
  @params   = {}
  @slots    = {}

  instance_eval &blk
end

Instance Method Details

#action(name, &blk) ⇒ Object



155
156
157
158
# File 'lib/nodectl/recipe.rb', line 155

def action(name, &blk)
  raise "Cannot create action without block" unless block_given?
  @actions[name] = blk
end

#createObject



146
147
148
149
150
151
152
153
# File 'lib/nodectl/recipe.rb', line 146

def create
  Nodectl::Recipe.new(@name, actions:  @actions,
                             triggers: @triggers,
                             events:   @events,
                             logs:     @logs,
                             params:   @params,
                             slots:    @slots)
end

#event(name, &blk) ⇒ Object



166
167
168
169
# File 'lib/nodectl/recipe.rb', line 166

def event(name, &blk)
  raise "Cannot create event without block" unless block_given?
  @events[name] = blk
end

#log(name, path) ⇒ Object



180
181
182
# File 'lib/nodectl/recipe.rb', line 180

def log(name, path)
  @logs[name.to_s] = Nodectl::Log.new(name, path)
end

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



176
177
178
# File 'lib/nodectl/recipe.rb', line 176

def param(name, options = {})
  @params[name] = options
end

#slot(name, &blk) ⇒ Object



160
161
162
163
164
# File 'lib/nodectl/recipe.rb', line 160

def slot(name, &blk)
  raise "Cannot create slots without block" unless block_given?
  raise "Unsupported slot name #{name}" unless Nodectl::Recipe::SLOT_NAMES.include?(name)
  @slots[name] = blk
end

#trigger(name, &blk) ⇒ Object



171
172
173
174
# File 'lib/nodectl/recipe.rb', line 171

def trigger(name, &blk)
  raise "Cannot create trigger without block" unless block_given?
  @triggers[name] = blk
end