class RubyYacht::Hook::DSL
This class provides a DSL
for configuring hooks.
Public Class Methods
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.
# 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
Public Instance Methods
You can call ‘app_server_type :rails` to signify that this hook applies to rails apps.
# File lib/ruby_yacht/dsl/hook.rb, line 58 add_attribute :app_server_type, :all
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.
RubyYacht::DSL::Base#check_required_attributes
# 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
This method adds a behavior to run a command when the hook is run.
### Parameters
-
**cmd: String** The command to run.
# File lib/ruby_yacht/dsl/hook.rb, line 93 def command(cmd) @behaviors << CommandBehavior.new(cmd) end
You can call ‘container_type :app` to signify that this hook applies to app images.
# File lib/ruby_yacht/dsl/hook.rb, line 79 add_attribute :container_type
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`.
# File lib/ruby_yacht/dsl/hook.rb, line 104 def copy_file(path) @behaviors << CopyFileBehavior.new("#{@script_folder}/#{path}") end
You can call ‘database_server_type :mysql` to signify that this hook applies to MySQL databases.
# File lib/ruby_yacht/dsl/hook.rb, line 65 add_attribute :database_server_type, :all
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.
# 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
You can call ‘script_folder ’./scripts’‘ to signify that the scripts for this hook are found in the `./scripts` folder.
# File lib/ruby_yacht/dsl/hook.rb, line 86 add_attribute :script_folder, '.'
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.
# 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
You can call ‘web_server_type :nginx` to signify that this hook applies to nginx web servers.
# File lib/ruby_yacht/dsl/hook.rb, line 72 add_attribute :web_server_type, :all