Class: RubyYacht::Hook::DSL

Inherits:
Object
  • Object
show all
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

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

#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
# File 'lib/ruby_yacht/dsl/hook.rb', line 46

def initialize(event_time, event_type)
  @event_time = event_time
  @event_type = event_type
  load_custom_attributes
end

Instance Method Details

#check_required_attributesObject

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.


110
111
112
113
114
115
# File 'lib/ruby_yacht/dsl/hook.rb', line 110

def check_required_attributes
  super
  unless RubyYacht.configuration.find_server_type(@server_type)
    raise "Hook has invalid app type `#{@server_type}`"
  end
end

#commandObject

:method: command

You can call command 'whoami' to signify that this hook runs the command whoami. You can also set the command through run_script, if the hook runs a script file included with the plugin.


65
# File 'lib/ruby_yacht/dsl/hook.rb', line 65

add_attribute :command

#copy_fileObject

:method: copy_file

You can call copy_file 'foo.txt' to signify that this hook should copy a file called foo.txt from the hook's script folder to /var/docker.

You can pair this with a command if you want to move it from that location in /var/docker into a custom location inside your code folder.

The file copying happens at the time the image has built.

When setting this attribute, you must provide another command using the command method.


81
# File 'lib/ruby_yacht/dsl/hook.rb', line 81

add_attribute :copy_file, nil, false

#create_objectObject

This method creates a Hook object from the DSL.


118
119
120
121
# File 'lib/ruby_yacht/dsl/hook.rb', line 118

def create_object
  @copied_file_path = File.join(@script_folder || '.', @copy_file) if @copy_file
  super
end

#run_script(name) ⇒ Object

This method sets the name of the script containing the code for the hook.

The script will be understood to be in the script folder that was given when the DSL was created.

Parameters

  • name: String The filename of the script.

99
100
101
102
# File 'lib/ruby_yacht/dsl/hook.rb', line 99

def run_script(name)
  @copy_file = name
  @command = "/var/docker/#{name}"
end

#script_folderObject

:method: script_folder

You can call script_folder './scripts' to signify that the scripts for this hook are found in the ./scripts folder.


88
# File 'lib/ruby_yacht/dsl/hook.rb', line 88

add_attribute :script_folder, nil, false

#server_typeObject

:method: server_type

You can call server_type :rails to signify that this hook applies to rails apps.


57
# File 'lib/ruby_yacht/dsl/hook.rb', line 57

add_attribute :server_type