Module: DigitalOceanInventory
- Defined in:
- lib/digital_ocean_inventory.rb,
lib/digital_ocean_inventory/host.rb,
lib/digital_ocean_inventory/group.rb,
lib/digital_ocean_inventory/config.rb,
lib/digital_ocean_inventory/version.rb,
lib/digital_ocean_inventory/collector.rb,
lib/digital_ocean_inventory/inventory.rb,
lib/digital_ocean_inventory/serializer.rb
Defined Under Namespace
Classes: Collector, Config, Error, Group, Host, Inventory, Serializer
Constant Summary
collapse
- VERSION =
"0.1.2"
Class Method Summary
collapse
Class Method Details
.build_inventory(config) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/digital_ocean_inventory.rb', line 43
def self.build_inventory(config)
inventory = Inventory.build config
collector = Collector.build config
collector.call inventory
end
|
.cache_inventory(config, json) ⇒ Object
50
51
52
53
54
|
# File 'lib/digital_ocean_inventory.rb', line 50
def self.cache_inventory(config, json)
File.open config.cache_file, "w+" do |f|
f.write json
end
end
|
.cache_valid?(config) ⇒ Boolean
29
30
31
32
33
34
35
36
37
|
# File 'lib/digital_ocean_inventory.rb', line 29
def self.cache_valid?(config)
return false unless File.exists? config.cache_file
max_age = config.cache_max_age
file_stat = File.stat config.cache_file
cache_age = Time.now.to_i - file_stat.mtime.to_i
max_age > cache_age
end
|
.call(argv) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/digital_ocean_inventory.rb', line 10
def self.call(argv)
config = Config.new
if cache_valid? config
json = load_cached config
else
inventory = build_inventory config
serializer = Serializer.build config
json = serializer.call inventory
cache_inventory config, json
end
puts json
json
end
|
.load_cached(config) ⇒ Object
39
40
41
|
# File 'lib/digital_ocean_inventory.rb', line 39
def self.load_cached(config)
File.read config.cache_file
end
|