Class: AdminModule::Rake::GdlTasks
- Inherits:
-
Object
- Object
- AdminModule::Rake::GdlTasks
- Includes:
- Rake::DSL
- Defined in:
- lib/admin_module/rake/gdl_tasks.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#env ⇒ Object
Returns the value of attribute env.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#stop_on_exception ⇒ Object
Returns the value of attribute stop_on_exception.
-
#valid_actions ⇒ Object
readonly
Returns the value of attribute valid_actions.
Class Method Summary collapse
Instance Method Summary collapse
- #assert_env_is_configured(arg) ⇒ Object
- #assert_provided(value, msg) ⇒ Object
- #commit ⇒ Object
- #default_params ⇒ Object
-
#define_task ⇒ Object
:nodoc:.
- #deploy(client) ⇒ Object
-
#initialize(task_name = 'gdls_task', desc = "Modify a gdl or gdls") {|_self| ... } ⇒ GdlTasks
constructor
A new instance of GdlTasks.
- #install ⇒ Object
-
#required_args_for_action ⇒ Object
Define the task arguments (and their order) required for a given action.
- #set_vars(args) ⇒ Object
- #validate_params ⇒ Object
- #version(client) ⇒ Object
Constructor Details
#initialize(task_name = 'gdls_task', desc = "Modify a gdl or gdls") {|_self| ... } ⇒ GdlTasks
Returns a new instance of GdlTasks.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 27 def initialize(task_name = 'gdls_task', desc = "Modify a gdl or gdls") @valid_actions = ['deploy', 'version'] @task_name, @desc = task_name, desc @stop_on_exception = true yield self if block_given? define_task end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
23 24 25 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 23 def action @action end |
#comments ⇒ Object
Returns the value of attribute comments.
21 22 23 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 21 def comments @comments end |
#env ⇒ Object
Returns the value of attribute env.
19 20 21 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 19 def env @env end |
#name ⇒ Object
Returns the value of attribute name.
20 21 22 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 20 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
22 23 24 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 22 def path @path end |
#stop_on_exception ⇒ Object
Returns the value of attribute stop_on_exception.
25 26 27 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 25 def stop_on_exception @stop_on_exception end |
#valid_actions ⇒ Object (readonly)
Returns the value of attribute valid_actions.
24 25 26 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 24 def valid_actions @valid_actions end |
Class Method Details
.install ⇒ Object
170 171 172 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 170 def install new.install end |
Instance Method Details
#assert_env_is_configured(arg) ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 138 def assert_env_is_configured arg unless AdminModule.configuration.credentials.key? arg init_msg = "Have you initialized your config file?\n Try: admin_module config init <filedir>" env_msg = "Have you configured your environments?\n Try: admin_module config add env <envname> <url>" raise "Unknown environment: #{arg}\n#{init_msg}\n\n#{env_msg}" end end |
#assert_provided(value, msg) ⇒ Object
132 133 134 135 136 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 132 def assert_provided value, msg if value.nil? || value.empty? raise msg end end |
#commit ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 64 def commit validate_params client = AdminModule::Client.new client.env = env if self.respond_to? action self.send(action, client) return else raise "Unknown action - #{action}" end rescue Exception => e raise e if stop_on_exception == true ensure client.quit unless client.nil? end |
#default_params ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 96 def default_params if comments.nil? || comments.empty? self.comments = AdminModule.configuration.default_comment unless comments.nil? || comments.empty? $stdout << "Using default comment - #{comments}\n" end end if path.nil? || path.empty? build_dir = Pathname('build') if build_dir.exist? && build_dir.directory? # Must be an absolute path: self.path = build_dir..to_s $stdout << "Using default path - #{path}\n" end end end |
#define_task ⇒ Object
:nodoc:
38 39 40 41 42 43 44 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 38 def define_task #:nodoc: desc @desc task(@task_name, required_args_for_action) do |t,args| set_vars args commit # Call method to perform when invoked. end end |
#deploy(client) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 83 def deploy client real_path = Pathname(path) if real_path.directory? client.guideline.deploy(path, comments) else client.guideline.deploy_file(path, comments) end end |
#install ⇒ Object
175 176 177 178 179 180 181 182 183 184 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 175 def install AdminModule.configuration.credentials.keys.each do |e| valid_actions.each do |action| AdminModule::Rake::GdlTasks.new("am:#{e}:gdl:#{action}", "#{action} #{e} gdl(s)") do |t| t.env = e t.action = action end end end end |
#required_args_for_action ⇒ Object
Define the task arguments (and their order) required for a given action
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 150 def required_args_for_action args = [] case action when 'deploy' args << :comments args << :path when 'version' args << :name args << :comments else # Noop end args end |
#set_vars(args) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 46 def set_vars args args.each do |arg,val| instance_variable_set "@#{arg}", val end args end |
#validate_params ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 114 def validate_params assert_provided env, 'Missing "env"' assert_provided action, 'Missing "action"' default_params case action when 'deploy' assert_provided path, 'Missing "path"' when 'version' assert_provided name, 'Missing "name"' end assert_env_is_configured env end |
#version(client) ⇒ Object
92 93 94 |
# File 'lib/admin_module/rake/gdl_tasks.rb', line 92 def version client client.guideline.version(name, comments) end |