Class: Djinn::Base::Dsl::DslDefinitionHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/djinn/base/dsl.rb

Overview

A helper class for interpretting the definition block of a Djinn

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ DslDefinitionHelper

Returns a new instance of DslDefinitionHelper.



162
163
164
165
166
167
# File 'lib/djinn/base/dsl.rb', line 162

def initialize &block
  @actions = {}
  instance_eval(&block) if block_given?
  # create in case there was no configuration block
  @config_helper = ConfigHelper.new unless defined?(@config_helper)
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



160
161
162
# File 'lib/djinn/base/dsl.rb', line 160

def actions
  @actions
end

#config_helperObject

Returns the value of attribute config_helper.



160
161
162
# File 'lib/djinn/base/dsl.rb', line 160

def config_helper
  @config_helper
end

Instance Method Details

#configure(&block) ⇒ Object

Define configuration for a Djinn, adding ARGV switches that can be interpreted and acted on in your actions



171
172
173
# File 'lib/djinn/base/dsl.rb', line 171

def configure &block
  @config_helper = ConfigHelper.new(&block)
end

#exit(&block) ⇒ Object

Runs when Djinn exits



181
182
183
# File 'lib/djinn/base/dsl.rb', line 181

def exit &block
  @actions[:exit] = block
end

#prepare(config) ⇒ Object

Prepare the Djinn configuration based on informations passed in in the configuration block



192
193
194
# File 'lib/djinn/base/dsl.rb', line 192

def prepare(config)
  @config_helper.parse_config!(config)
end

#start(&block) ⇒ Object

Runs when the Djinn starts



176
177
178
# File 'lib/djinn/base/dsl.rb', line 176

def start &block
  @actions[:start] = block
end

#stop(&block) ⇒ Object

Runs when the Djinn stops



186
187
188
# File 'lib/djinn/base/dsl.rb', line 186

def stop &block
  @actions[:stop] = block
end