Class: Pike::Env
- Inherits:
-
Object
- Object
- Pike::Env
- Defined in:
- lib/pike/env.rb
Instance Attribute Summary collapse
-
#bundler_prefix ⇒ Object
readonly
Aboslute path to the bundle executable on the remote machine.
-
#lifecycle ⇒ Object
readonly
Returns the value of attribute lifecycle.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
-
#add_task(name, params = {}) ⇒ Object
Called from the DSL to add a task to the lifecycle.
-
#get_var(key) ⇒ Object
Returns a variables value.
-
#initialize(name, &block) ⇒ Env
constructor
Constructor.
-
#prepare ⇒ Object
Sets some internal variables.
-
#run_lifecycle ⇒ Object
Run the complete lifecycle of the environment.
-
#run_single_task(name) ⇒ Object
Runs a single task from that environment.
-
#run_task(name, params) ⇒ Object
Runs a task for that environment.
-
#set_var(vars = {}) ⇒ Object
Called from the DSL to set variables.
Constructor Details
#initialize(name, &block) ⇒ Env
Constructor
16 17 18 19 20 21 |
# File 'lib/pike/env.rb', line 16 def initialize(name, &block) @name = name @variables = {} @lifecycle = [] DSL::Environment.load(self, &block) end |
Instance Attribute Details
#bundler_prefix ⇒ Object (readonly)
Aboslute path to the bundle executable on the remote machine
9 10 11 |
# File 'lib/pike/env.rb', line 9 def bundler_prefix @bundler_prefix end |
#lifecycle ⇒ Object (readonly)
Returns the value of attribute lifecycle.
3 4 5 |
# File 'lib/pike/env.rb', line 3 def lifecycle @lifecycle end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/pike/env.rb', line 3 def name @name end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
3 4 5 |
# File 'lib/pike/env.rb', line 3 def variables @variables end |
Instance Method Details
#add_task(name, params = {}) ⇒ Object
Called from the DSL to add a task to the lifecycle
28 29 30 |
# File 'lib/pike/env.rb', line 28 def add_task(name, params = {}) @lifecycle << [name, params] end |
#get_var(key) ⇒ Object
Returns a variables value
108 109 110 |
# File 'lib/pike/env.rb', line 108 def get_var(key) @variables[key] || Main.get_var(key) end |
#prepare ⇒ Object
Sets some internal variables
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pike/env.rb', line 37 def prepare # Set the release path deploy_to = get_var(:deploy_to) + '/.pike/releases/' set_var release_path: (deploy_to.gsub('//', '/') + Time.new.to_i.to_s + '/') set_var root_dir: File.(Dir.pwd) set_var build_dir: File.("#{Dir.pwd}/.pikebuild") # Ensure the ssh connection works SSH::Connection.connect get_var(:host), get_var(:user) # Ensure sudo works if required if get_var(:use_sudo) SSH::Connection.try_sudo end # Get bundler path pre = "[[ -s '/etc/profile.d/rvm.sh' ]] && source /etc/profile.d/rvm.sh" @bundler_prefix = "#{pre} && " end |
#run_lifecycle ⇒ Object
Run the complete lifecycle of the environment
84 85 86 87 88 89 90 |
# File 'lib/pike/env.rb', line 84 def run_lifecycle prepare @lifecycle.each do |task| run_task task[0], task[1] end end |
#run_single_task(name) ⇒ Object
Runs a single task from that environment
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pike/env.rb', line 61 def run_single_task(name) prepare task_to_run = nil lifecycle.each do |task| if task[0] == name task_to_run = task break end end if task_to_run == nil Main.error("Unkown task '#{name}'") else run_task(task_to_run[0], task_to_run[1]) end end |
#run_task(name, params) ⇒ Object
Runs a task for that environment
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/pike/env.rb', line 117 def run_task(name, params) Main.action "# Run task #{name}" do task = Main.find_task(name) if task task.run(self, params) else raise "Task #{name} not found" end end end |
#set_var(vars = {}) ⇒ Object
Called from the DSL to set variables
97 98 99 100 101 |
# File 'lib/pike/env.rb', line 97 def set_var(vars = {}) vars.keys.each do |key| @variables[key] = vars[key] end end |