Module: ServerRemote::Util
- Included in:
- Command
- Defined in:
- lib/server_remote/server_remote.rb
Constant Summary collapse
- DEFAULT_PROFILE =
'app'
Instance Method Summary collapse
- #app_root ⇒ Object
- #app_root=(app_root) ⇒ Object
- #cd_to_app_action ⇒ Object
- #config ⇒ Object
- #config=(cfg) ⇒ Object
- #config_path ⇒ Object
- #console_action ⇒ Object
- #default_options_path ⇒ Object
- #execute(cmd) ⇒ Object
- #keyfile_option ⇒ Object
- #load_config ⇒ Object
- #parse_common_args ⇒ Object
- #remote_command(args) ⇒ Object
- #remote_command_in_app(args) ⇒ Object
- #scp_command ⇒ Object
- #scp_file_argument(arg) ⇒ Object
- #ssh_command ⇒ Object
- #tail_action(args) ⇒ Object
- #user_and_host ⇒ Object
Instance Method Details
#app_root ⇒ Object
80 81 82 83 |
# File 'lib/server_remote/server_remote.rb', line 80 def app_root raise 'app_root not set!' unless @app_root @app_root end |
#app_root=(app_root) ⇒ Object
76 77 78 |
# File 'lib/server_remote/server_remote.rb', line 76 def app_root=(app_root) @app_root = app_root end |
#cd_to_app_action ⇒ Object
52 53 54 |
# File 'lib/server_remote/server_remote.rb', line 52 def cd_to_app_action "cd #{config[:app_path]}" end |
#config ⇒ Object
89 90 91 |
# File 'lib/server_remote/server_remote.rb', line 89 def config @config ||= {} end |
#config=(cfg) ⇒ Object
85 86 87 |
# File 'lib/server_remote/server_remote.rb', line 85 def config=(cfg) @config = cfg end |
#config_path ⇒ Object
93 94 95 |
# File 'lib/server_remote/server_remote.rb', line 93 def config_path [:config_path] ? [:config_path] : File.join(app_root, 'config', 'server_remote.yml') end |
#console_action ⇒ Object
48 49 50 |
# File 'lib/server_remote/server_remote.rb', line 48 def console_action "./script/console #{config[:environment]}" end |
#default_options_path ⇒ Object
14 15 16 |
# File 'lib/server_remote/server_remote.rb', line 14 def File.join(*([GEM_ROOT] + %w{config defaults.yml})) end |
#execute(cmd) ⇒ Object
18 19 20 21 |
# File 'lib/server_remote/server_remote.rb', line 18 def execute(cmd) print "--> calling '#{cmd}'\n" Kernel.system(cmd) end |
#keyfile_option ⇒ Object
28 29 30 |
# File 'lib/server_remote/server_remote.rb', line 28 def keyfile_option "-i #{File.join(app_root, config[:keyfile])} " if config[:keyfile] end |
#load_config ⇒ Object
97 98 99 100 |
# File 'lib/server_remote/server_remote.rb', line 97 def load_config load_default_config load_app_config(config_path) end |
#parse_common_args ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/server_remote/server_remote.rb', line 102 def parse_common_args if args.first == '-p' args.shift p = args.shift if p config[:profile] = p else raise "Missing profile argument for -p" end end # get around simplecli's usage call when there are no arguments # instead of calling the default action args << '--nullarg' if args.empty? end |
#remote_command(args) ⇒ Object
66 67 68 69 |
# File 'lib/server_remote/server_remote.rb', line 66 def remote_command(args) args = args.join(' ') if args.respond_to?(:join) "#{ssh_command} '#{args}'" end |
#remote_command_in_app(args) ⇒ Object
71 72 73 74 |
# File 'lib/server_remote/server_remote.rb', line 71 def remote_command_in_app(args) args = args.join(' ') if args.respond_to?(:join) remote_command("#{cd_to_app_action};#{args}") end |
#scp_command ⇒ Object
36 37 38 |
# File 'lib/server_remote/server_remote.rb', line 36 def scp_command "scp #{keyfile_option}" end |
#scp_file_argument(arg) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/server_remote/server_remote.rb', line 40 def scp_file_argument(arg) if arg and arg[0..0] == ':' user_and_host + arg else arg end end |
#ssh_command ⇒ Object
32 33 34 |
# File 'lib/server_remote/server_remote.rb', line 32 def ssh_command "ssh -t #{keyfile_option}#{user_and_host}" end |
#tail_action(args) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/server_remote/server_remote.rb', line 56 def tail_action(args) if args and !args.empty? file = args.join(' ') else file = "log/#{config[:environment]}.log" end "tail -n #{config[:tail_initial_lines]} -f #{file}" end |
#user_and_host ⇒ Object
23 24 25 26 |
# File 'lib/server_remote/server_remote.rb', line 23 def user_and_host user = "#{config[:user]}@" if config[:user] "#{user}#{config[:host]}" end |