Class: Assh::Configuration
- Inherits:
-
Object
- Object
- Assh::Configuration
- Defined in:
- lib/configuration.rb
Instance Attribute Summary collapse
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#hosts ⇒ Object
Returns the value of attribute hosts.
Instance Method Summary collapse
- #add_host(group_name, host_name, host) ⇒ Object
- #generated_at(timestamp_file = File.expand_path(Assh::CONFIG_CACHE_AT)) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #load_cache!(config_file = File.expand_path(Assh::CONFIG_CACHE)) ⇒ Object
- #needs_generating?(timestamp_file = File.expand_path(Assh::CONFIG_CACHE_AT)) ⇒ Boolean
-
#save_cache!(config_file = File.expand_path(Assh::CONFIG_CACHE), timestamp_file = File.expand_path(Assh::CONFIG_CACHE_AT)) ⇒ Object
TODO: Move generated-at to here and call config-cached-at.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
7 8 9 10 |
# File 'lib/configuration.rb', line 7 def initialize @hosts = {} @groups = {} end |
Instance Attribute Details
#groups ⇒ Object
Returns the value of attribute groups.
5 6 7 |
# File 'lib/configuration.rb', line 5 def groups @groups end |
#hosts ⇒ Object
Returns the value of attribute hosts.
5 6 7 |
# File 'lib/configuration.rb', line 5 def hosts @hosts end |
Instance Method Details
#add_host(group_name, host_name, host) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/configuration.rb', line 12 def add_host(group_name, host_name, host) puts "WARNING: Duplicate host named: #{name}. Only latest host is included" if @hosts[host_name] @groups[group_name] = {} unless @groups.has_key?(group_name) @groups[group_name][host_name] = host @hosts[host_name] = host end |
#generated_at(timestamp_file = File.expand_path(Assh::CONFIG_CACHE_AT)) ⇒ Object
43 44 45 46 |
# File 'lib/configuration.rb', line 43 def generated_at( = File.(Assh::CONFIG_CACHE_AT)) return File.read().to_i if File.exists?() 0 end |
#load_cache!(config_file = File.expand_path(Assh::CONFIG_CACHE)) ⇒ Object
33 34 35 36 37 |
# File 'lib/configuration.rb', line 33 def load_cache!(config_file = File.(Assh::CONFIG_CACHE)) cache = YAML::load_file(config_file) @hosts = cache[:hosts] @groups = cache[:groups] end |
#needs_generating?(timestamp_file = File.expand_path(Assh::CONFIG_CACHE_AT)) ⇒ Boolean
39 40 41 |
# File 'lib/configuration.rb', line 39 def ( = File.(Assh::CONFIG_CACHE_AT)) (current_time - generated_at()) > 72000 end |
#save_cache!(config_file = File.expand_path(Assh::CONFIG_CACHE), timestamp_file = File.expand_path(Assh::CONFIG_CACHE_AT)) ⇒ Object
TODO: Move generated-at to here and call config-cached-at
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/configuration.rb', line 22 def save_cache!(config_file = File.(Assh::CONFIG_CACHE), = File.(Assh::CONFIG_CACHE_AT)) cache = { hosts: @hosts, groups: @groups } File.open(config_file, 'w') { |f| f << cache.to_yaml } File.open(, 'w') { |f| f << current_time } end |