Module: Inventory
- Defined in:
- lib/inventory.rb
Overview
Narou.rbのシステムが記録するデータ単位
.narou ディレクトリにYAMLファイルとして保存される
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.clear ⇒ Object
25 26 27 |
# File 'lib/inventory.rb', line 25 def self.clear @@cache = {} end |
.load(name, scope) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/inventory.rb', line 15 def self.load(name, scope) @@cache ||= {} return @@cache[name] if @@cache[name] {}.tap { |h| h.extend(Inventory) h.init(name, scope) @@cache[name] = h } end |
Instance Method Details
#init(name, scope) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/inventory.rb', line 29 def init(name, scope) dir = case scope when :local Narou.get_local_setting_dir when :global Narou.get_global_setting_dir else raise "Unknown scope" end return nil unless dir @inventory_file_path = File.join(dir, name + ".yaml") if File.exist?(@inventory_file_path) self.merge!(Helper::CacheLoader.memo(@inventory_file_path) { |yaml| YAML.load(yaml) }) end end |
#save ⇒ Object
47 48 49 50 51 52 |
# File 'lib/inventory.rb', line 47 def save unless @inventory_file_path raise "not initialized setting dir yet" end File.write(@inventory_file_path, YAML.dump(self)) end |