module DigitalOceanInventory
Constants
- VERSION
Public Class Methods
build_inventory(config)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/digital_ocean_inventory.rb, line 39 def self.load_cached(config) File.read config.cache_file end