Class: Rbfs::Command
- Inherits:
-
Object
- Object
- Rbfs::Command
- Defined in:
- lib/rbfs/command.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config = nil) ⇒ Command
constructor
A new instance of Command.
- #logger ⇒ Object
- #parse_config ⇒ Object
- #sync ⇒ Object
- #sync_host(host) ⇒ Object
- #sync_hosts ⇒ Object
Constructor Details
#initialize(config = nil) ⇒ Command
Returns a new instance of Command.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rbfs/command.rb', line 12 def initialize(config = nil) if config @config = config else @config = parse_config unless config end @config[:logger] = Logger.new(@config) logger.critical "No hosts file specified" unless @config[:hosts] logger.critical "Root path not specified" unless @config[:root] end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
10 11 12 |
# File 'lib/rbfs/command.rb', line 10 def config @config end |
Instance Method Details
#logger ⇒ Object
38 39 40 |
# File 'lib/rbfs/command.rb', line 38 def logger @config[:logger] end |
#parse_config ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rbfs/command.rb', line 23 def parse_config config = {} cmdline_args = Rbfs::Args.new.parse if cmdline_args[:config] config_args = Rbfs::Config.new(cmdline_args[:config]).parse config = config_args.merge(cmdline_args) else config = cmdline_args end unless config[:remote_root] config[:remote_root] = config[:root] end config end |
#sync ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rbfs/command.rb', line 42 def sync success = true sync_hosts.each do |host, result| logger.info "#{host.name}: #{result.error}" result.changes.each do |change| logger.puts " | #{change.filename} (#{change.summary})" end success = false unless result.success? end success end |
#sync_host(host) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/rbfs/command.rb', line 69 def sync_host(host) if config[:threaded] Future.new do Rsync.new(config, host).sync end else Rsync.new(config, host).sync end end |
#sync_hosts ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rbfs/command.rb', line 56 def sync_hosts if config[:subpath] config[:root] = File.join(config[:root], config[:subpath]) config[:remote_root] = File.join(config[:remote_root], config[:subpath]) end logger.info "Syncing #{config[:root]}..." hosts = HostsFile.load(config[:hosts]) hosts.collect do |host| [host, sync_host(host)] end end |