Class: Ajimi::Server
- Inherits:
-
Object
- Object
- Ajimi::Server
- Defined in:
- lib/ajimi/server.rb,
lib/ajimi/server/ssh.rb,
lib/ajimi/server/entry.rb
Defined Under Namespace
Instance Method Summary collapse
- #==(other) ⇒ Object
- #backend ⇒ Object
- #cat(file) ⇒ Object
- #cat_or_md5sum(file) ⇒ Object
- #command_exec(cmd) ⇒ Object
- #entries(dir) ⇒ Object
- #find(dir, find_max_depth = nil, pruned_paths = [], enable_nice = nil) ⇒ Object
- #host ⇒ Object
-
#initialize(name, **options) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(name, **options) ⇒ Server
Returns a new instance of Server.
7 8 9 10 11 12 |
# File 'lib/ajimi/server.rb', line 7 def initialize(name, **) @name = name @options = @options[:ssh_options] = [:ssh_options] || {} @options[:ssh_options][:host] = [:ssh_options][:host] || @name end |
Instance Method Details
#==(other) ⇒ Object
14 15 16 17 |
# File 'lib/ajimi/server.rb', line 14 def ==(other) self.instance_variable_get(:@name) == other.instance_variable_get(:@name) self.instance_variable_get(:@options) == other.instance_variable_get(:@options) end |
#backend ⇒ Object
23 24 25 |
# File 'lib/ajimi/server.rb', line 23 def backend @backend ||= Ajimi::Server::Ssh.new(@options[:ssh_options]) end |
#cat(file) ⇒ Object
42 43 44 45 |
# File 'lib/ajimi/server.rb', line 42 def cat(file) stdout = command_exec("sudo cat #{file}") stdout.split(/\n/).map {|line| line.chomp } end |
#cat_or_md5sum(file) ⇒ Object
47 48 49 50 |
# File 'lib/ajimi/server.rb', line 47 def cat_or_md5sum(file) stdout = command_exec("if (sudo file -b #{file} | grep text > /dev/null 2>&1) ; then (sudo cat #{file}) else (sudo md5sum #{file}) fi") stdout.split(/\n/).map {|line| line.chomp } end |
#command_exec(cmd) ⇒ Object
27 28 29 |
# File 'lib/ajimi/server.rb', line 27 def command_exec(cmd) backend.command_exec(cmd) end |
#entries(dir) ⇒ Object
38 39 40 |
# File 'lib/ajimi/server.rb', line 38 def entries(dir) @entries ||= find(dir).map{ |line| Ajimi::Server::Entry.parse(line) } end |
#find(dir, find_max_depth = nil, pruned_paths = [], enable_nice = nil) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/ajimi/server.rb', line 31 def find(dir, find_max_depth = nil, pruned_paths = [], enable_nice = nil) enable_nice = @options[:enable_nice] if enable_nice.nil? cmd = build_find_cmd(dir, find_max_depth, pruned_paths, enable_nice) stdout = command_exec(cmd) stdout.split(/\n/).map {|line| line.chomp }.sort end |
#host ⇒ Object
19 20 21 |
# File 'lib/ajimi/server.rb', line 19 def host @options[:ssh_options][:host] end |