Class: RubyYacht::Hook::DSL
- Inherits:
-
Object
- Object
- RubyYacht::Hook::DSL
- Extended by:
- DSL::Base::ClassMethods
- Includes:
- DSL::Base
- Defined in:
- lib/ruby_yacht/dsl/hook.rb
Overview
This class provides a DSL for configuring hooks.
Instance Method Summary collapse
-
#app_server_type ⇒ Object
:method: app_server_type.
-
#check_required_attributes ⇒ Object
This method checks that all of the required attributes have been set on the object.
-
#command(cmd) ⇒ Object
This method adds a behavior to run a command when the hook is run.
-
#container_type ⇒ Object
:method: container_type.
-
#copy_file(path) ⇒ Object
This method adds a behavior to copy a file to the image when the hook is run.
-
#database_server_type ⇒ Object
:method: database_server_type.
-
#initialize(event_time, event_type) ⇒ DSL
constructor
This initializer creates a new Hook DSL.
-
#run_script(interpreter, name) ⇒ Object
This method adds a behavior to run a script.
-
#script_folder ⇒ Object
:method: script_folder.
-
#set_environment_variable(name, value = nil, &block) ⇒ Object
This method adds a behavior to set an environment variable.
-
#web_server_type ⇒ Object
:method: web_server_type.
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_server_type, #create_object, #load_custom_attributes, #run
Constructor Details
#initialize(event_time, event_type) ⇒ DSL
This initializer creates a new Hook DSL.
Parameters
- event_time: Symbol The time for the hook, relative to the event.
- event_type: Symbol The type of event the hook is attached to.
46 47 48 49 50 51 |
# File 'lib/ruby_yacht/dsl/hook.rb', line 46 def initialize(event_time, event_type) @event_time = event_time @event_type = event_type @behaviors = [] load_custom_attributes end |
Instance Method Details
#app_server_type ⇒ Object
:method: app_server_type
You can call app_server_type :rails
to signify that this hook applies
to rails apps.
58 |
# File 'lib/ruby_yacht/dsl/hook.rb', line 58 add_attribute :app_server_type, :all |
#check_required_attributes ⇒ Object
This method checks that all of the required attributes have been set on the object.
If they haven't, this will raise an exception.
This will also check that the app type is valid.
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/ruby_yacht/dsl/hook.rb', line 150 def check_required_attributes super if @app_server_type != :all check_server_type @app_server_type, :app end if @database_server_type != :all check_server_type @database_server_type, :database end if @web_server_type != :all check_server_type @web_server_type, :web end end |
#command(cmd) ⇒ Object
This method adds a behavior to run a command when the hook is run.
Parameters
- cmd: String The command to run.
93 94 95 |
# File 'lib/ruby_yacht/dsl/hook.rb', line 93 def command(cmd) @behaviors << CommandBehavior.new(cmd) end |
#container_type ⇒ Object
:method: container_type
You can call container_type :app
to signify that this hook applies to
app images.
79 |
# File 'lib/ruby_yacht/dsl/hook.rb', line 79 add_attribute :container_type |
#copy_file(path) ⇒ Object
This method adds a behavior to copy a file to the image when the hook is run.
Parameters
- path: String The path to the file, relative to the
script_folder
.
104 105 106 |
# File 'lib/ruby_yacht/dsl/hook.rb', line 104 def copy_file(path) @behaviors << CopyFileBehavior.new("#{@script_folder}/#{path}") end |
#database_server_type ⇒ Object
:method: database_server_type
You can call database_server_type :mysql
to signify that this hook
applies to MySQL databases.
65 |
# File 'lib/ruby_yacht/dsl/hook.rb', line 65 add_attribute :database_server_type, :all |
#run_script(interpreter, name) ⇒ Object
This method adds a behavior to run a script.
The script will be understood to be in the script folder that was given when the DSL was created.
Parameters
- interpreter: Symbol The interpreter that should process the script. e.g. ruby or bash
- name: String The filename of the script.
118 119 120 121 122 |
# File 'lib/ruby_yacht/dsl/hook.rb', line 118 def run_script(interpreter, name) copy_file name destination = "/var/docker/#{name}" command "#{interpreter} #{destination}" end |
#script_folder ⇒ Object
:method: script_folder
You can call script_folder './scripts'
to signify that the scripts for
this hook are found in the ./scripts
folder.
86 |
# File 'lib/ruby_yacht/dsl/hook.rb', line 86 add_attribute :script_folder, '.' |
#set_environment_variable(name, value = nil, &block) ⇒ Object
This method adds a behavior to set an environment variable.
The variable's value can be defined literally, by passing a value as the second parameter to this method, or at build-time, by passing a block.
Parameters
- name: String The name of the environment variable.
- value: String A literal value to set for the environment variable.
- block: Proc A block for providing the environment variable.
135 136 137 138 139 140 141 142 |
# File 'lib/ruby_yacht/dsl/hook.rb', line 135 def set_environment_variable(name, value=nil, &block) if value value_proc = Proc.new { value } else value_proc = block end @behaviors << EnvironmentVariableBehavior.new(name, value_proc) end |
#web_server_type ⇒ Object
:method: web_server_type
You can call web_server_type :nginx
to signify that this hook
applies to nginx web servers.
72 |
# File 'lib/ruby_yacht/dsl/hook.rb', line 72 add_attribute :web_server_type, :all |