Class: Pushapp::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/pushapp/remote.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @name     = name
  @location = location
  @config   = config
  @options  = options
  @group    = group
  @tasks    = Hash.new { |hash, key| hash[key] = [] }
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/pushapp/remote.rb', line 6

def config
  @config
end

#groupObject (readonly)

Returns the value of attribute group.



11
12
13
# File 'lib/pushapp/remote.rb', line 11

def group
  @group
end

#locationObject (readonly)

Returns the value of attribute location.



9
10
11
# File 'lib/pushapp/remote.rb', line 9

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/pushapp/remote.rb', line 8

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/pushapp/remote.rb', line 10

def options
  @options
end

#tasksObject (readonly)

Returns the value of attribute tasks.



7
8
9
# File 'lib/pushapp/remote.rb', line 7

def tasks
  @tasks
end

Instance Method Details

#envObject



105
106
107
# File 'lib/pushapp/remote.rb', line 105

def env
  (options[: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_nameObject



22
23
24
# File 'lib/pushapp/remote.rb', line 22

def full_name
  [group, name].compact.join('-')
end

#hostObject



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

#pathObject



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, task_options={})
  tasks[@event] << Pushapp::Tasks::Rake.new(task_name, merge_options(task_options))
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, script_options={})
  tasks[@event] << Pushapp::Tasks::Script.new(script_name, merge_options(script_options))
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, task_options={})
  tasks[@event] << config.known_task(task_name).new(merge_options(task_options).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

#userObject



60
61
62
63
# File 'lib/pushapp/remote.rb', line 60

def user
  user = @location.match(/(.*)@/)
  user[1] unless user.nil?
end