Class: Pushapp::Remote
- Inherits:
-
Object
- Object
- Pushapp::Remote
- Defined in:
- lib/pushapp/remote.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Instance Method Summary collapse
- #env ⇒ Object
- #env_run(cmd) ⇒ Object
- #exec(cmd) ⇒ Object
- #full_name ⇒ Object
- #host ⇒ Object
-
#initialize(name, group, location, config, options = {}) ⇒ Remote
constructor
A new instance of Remote.
- #on(event, &block) ⇒ Object
- #path ⇒ Object
- #rake(task_name, task_options = {}) ⇒ Object
- #run(cmd) ⇒ Object
- #script(script_name, script_options = {}) ⇒ Object
-
#setup! ⇒ Object
Set up Repositories and Hook.
- #ssh! ⇒ Object
- #task(task_name, task_options = {}) ⇒ Object
- #tasks_on(event) ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(name, group, location, config, options = {}) ⇒ Remote
Returns a new instance of Remote.
13 14 15 16 17 18 19 20 |
# File 'lib/pushapp/remote.rb', line 13 def initialize(name, group, location, config, = {}) @name = name @location = location @config = config @options = @group = group @tasks = Hash.new { |hash, key| hash[key] = [] } end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/pushapp/remote.rb', line 6 def config @config end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
11 12 13 |
# File 'lib/pushapp/remote.rb', line 11 def group @group end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
9 10 11 |
# File 'lib/pushapp/remote.rb', line 9 def location @location end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/pushapp/remote.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/pushapp/remote.rb', line 10 def @options end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
7 8 9 |
# File 'lib/pushapp/remote.rb', line 7 def tasks @tasks end |
Instance Method Details
#env ⇒ Object
105 106 107 |
# File 'lib/pushapp/remote.rb', line 105 def env ([:env] || {}) end |
#env_run(cmd) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/pushapp/remote.rb', line 85 def env_run cmd if host Pushapp::Pipe.run "ssh #{user}@#{host} 'cd #{path} && #{shell_env} $SHELL -l -c \"#{cmd}\"'" else Bundler.with_original_env do Pushapp::Pipe.run "cd #{path} && #{shell_env} #{cmd}" end end end |
#exec(cmd) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/pushapp/remote.rb', line 77 def exec cmd if host Kernel.exec "ssh -t #{user}@#{host} '#{cmd}'" else Kernel.exec cmd end end |
#full_name ⇒ Object
22 23 24 |
# File 'lib/pushapp/remote.rb', line 22 def full_name [group, name].compact.join('-') end |
#host ⇒ Object
55 56 57 58 |
# File 'lib/pushapp/remote.rb', line 55 def host host = @location.match(/@(.*):/) host[1] unless host.nil? end |
#on(event, &block) ⇒ Object
38 39 40 41 |
# File 'lib/pushapp/remote.rb', line 38 def on event, &block @event = event.to_s instance_eval(&block) if block_given? end |
#path ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/pushapp/remote.rb', line 47 def path if host @location.match(/:(.*)$/)[1] else @location end end |
#rake(task_name, task_options = {}) ⇒ Object
26 27 28 |
# File 'lib/pushapp/remote.rb', line 26 def rake(task_name, ={}) tasks[@event] << Pushapp::Tasks::Rake.new(task_name, ()) end |
#run(cmd) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/pushapp/remote.rb', line 95 def run cmd if host Pushapp::Pipe.run "ssh #{user}@#{host} '#{cmd}'" else Bundler.with_original_env do Pushapp::Pipe.run cmd end end end |
#script(script_name, script_options = {}) ⇒ Object
30 31 32 |
# File 'lib/pushapp/remote.rb', line 30 def script(script_name, ={}) tasks[@event] << Pushapp::Tasks::Script.new(script_name, ()) end |
#setup! ⇒ Object
Set up Repositories and Hook
72 73 74 75 |
# File 'lib/pushapp/remote.rb', line 72 def setup! run "#{init_repository} && #{setup_repository}" Pushapp::Hook.new(self).setup end |
#ssh! ⇒ Object
65 66 67 |
# File 'lib/pushapp/remote.rb', line 65 def ssh! exec "cd #{path} && #{shell_env} $SHELL -l" end |
#task(task_name, task_options = {}) ⇒ Object
34 35 36 |
# File 'lib/pushapp/remote.rb', line 34 def task(task_name, ={}) tasks[@event] << config.known_task(task_name).new(().merge(task_name: task_name)) end |
#tasks_on(event) ⇒ Object
43 44 45 |
# File 'lib/pushapp/remote.rb', line 43 def tasks_on event tasks[event.to_s] end |
#user ⇒ Object
60 61 62 63 |
# File 'lib/pushapp/remote.rb', line 60 def user user = @location.match(/(.*)@/) user[1] unless user.nil? end |