Class: RubyYacht::Configuration::DSL

Inherits:
Object
  • Object
show all
Extended by:
DSL::Base::ClassMethods
Includes:
DSL::Base
Defined in:
lib/ruby_yacht/dsl/configuration.rb

Overview

This method provides a DSL for top-level configuration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DSL::Base::ClassMethods

add_attribute, add_boolean, add_generic_attribute, add_list, add_object, add_object_list, all_attributes, copied_attributes, created_type, creates_object, custom_attribute_method, default_values, required_attributes

Methods included from DSL::Base

#check_required_attributes, #check_server_type, #copy_local_config, #create_object, #load_custom_attributes, #run

Constructor Details

#initializeDSL

This initializer creates an empty configuration DSL.



107
108
109
110
111
# File 'lib/ruby_yacht/dsl/configuration.rb', line 107

def initialize
  self.load_custom_attributes
  @hook_options = {}
  @local_config = {}
end

Instance Attribute Details

#hook_optionsObject

The default options for the hooks we're defining in the current block.



144
145
146
# File 'lib/ruby_yacht/dsl/configuration.rb', line 144

def hook_options
  @hook_options
end

#local_configObject

The configuration that has been loaded from a local YAML file.



147
148
149
# File 'lib/ruby_yacht/dsl/configuration.rb', line 147

def local_config
  @local_config
end

Instance Method Details

#add_hooks(options = {}, &block) ⇒ Object

This method sets default attributes for a group of hooks.

Any hooks that you create in the associated block will have the included options set on them automatically. You will also be able to override these options in the configuration blocks for individual hooks.

Parameters

  • options: Hash The fields to set on the hooks.
  • block A block for adding the hooks.


159
160
161
162
163
164
# File 'lib/ruby_yacht/dsl/configuration.rb', line 159

def add_hooks(options = {}, &block)
  old_options = hook_options.dup
  self.hook_options = options
  block.call
  self.hook_options = old_options
end

#add_local_config(path) ⇒ Object

This method loads config from a local YAML file.

The contents of the file will be stored in the global configuration's local_config field. From there, it can be loaded into another DSL object by calling copy_local_config.

Parameters

  • path: String The full path to the config file.


175
176
177
178
# File 'lib/ruby_yacht/dsl/configuration.rb', line 175

def add_local_config(path)
  new_config = YAML.load_file(path)
  @local_config = @local_config.merge(new_config)
end

#after(event_type, &block) ⇒ Object

This method adds an after hook.

Parameters

  • event_type: Symbol The event type for the new hook.
  • block A block for configuring the hook. You can call the RubyYacht::Hook::DSL methods in this block.


200
201
202
# File 'lib/ruby_yacht/dsl/configuration.rb', line 200

def after(event_type, &block)
  add_hook :after, event_type, &block
end

#before(event_type, &block) ⇒ Object

This method adds a before hook.

Parameters

  • event_type: Symbol The event type for the new hook.
  • block A block for configuring the hook. You can call the RubyYacht::Hook::DSL methods in this block.


188
189
190
# File 'lib/ruby_yacht/dsl/configuration.rb', line 188

def before(event_type, &block)
  add_hook :before, event_type, &block
end

#during(event_type, &block) ⇒ Object

This method adds a during hook.

This hook will be run while event is happening, and provides the core logic for the event.

Parameters

  • event_type: Symbol The event type for the new hook.
  • block A block for configuring the hook. You can call the RubyYacht::Hook::DSL methods in this block.


215
216
217
# File 'lib/ruby_yacht/dsl/configuration.rb', line 215

def during(event_type, &block)
  add_hook :during, event_type, &block
end

#hookObject

:method: hook

This method adds a hook to the configuration.

This takes hook's event_time and event_type as its arguments. It also takes a block which you can use to configure the hook, using RubyYacht::Hook::DSL.



131
# File 'lib/ruby_yacht/dsl/configuration.rb', line 131

add_object_list :hook, RubyYacht::Hook::DSL

#projectObject

:method: project

This method adds a project to the configuration.

This takes the project name as its first argument. It also takes a block which you can use to configure the project, using RubyYacht::Project::DSL.



121
# File 'lib/ruby_yacht/dsl/configuration.rb', line 121

add_object_list :project, RubyYacht::Project::DSL

#server_typeObject

:method: server_type

This method adds a server type to the configuration.

This takes type's name as its argument. It also takes a block which you can use to configure the type, using RubyYacht::ServerType::DSL.



141
# File 'lib/ruby_yacht/dsl/configuration.rb', line 141

add_object_list :server_type, RubyYacht::ServerType::DSL