Class: Reaver::MetaData
- Inherits:
-
Object
- Object
- Reaver::MetaData
- Defined in:
- lib/reaver/metadata.rb
Instance Attribute Summary collapse
-
#info ⇒ Object
Returns the value of attribute info.
Instance Method Summary collapse
-
#initialize(dirname, collection) ⇒ MetaData
constructor
A new instance of MetaData.
- #load_yaml ⇒ Object
- #save_yaml ⇒ Object
Constructor Details
#initialize(dirname, collection) ⇒ MetaData
Returns a new instance of MetaData.
7 8 9 10 11 12 |
# File 'lib/reaver/metadata.rb', line 7 def initialize(dirname, collection) @dirname = dirname @collection = collection @file = "#{@dirname}/metadata.yml" @info = { 'changed' => false, 'next' => Time.new } end |
Instance Attribute Details
#info ⇒ Object
Returns the value of attribute info.
5 6 7 |
# File 'lib/reaver/metadata.rb', line 5 def info @info end |
Instance Method Details
#load_yaml ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/reaver/metadata.rb', line 14 def load_yaml if File.exist? @file #puts "loading metadata #{@file}..." if RUBY_VERSION >= '3.0' @info = YAML.load_file(@file, permitted_classes: [Time, Symbol]) else @info = YAML.load_file(@file) end # puts @info.inspect else File.open(@file, 'w') { |f| YAML.dump(@info, f) } end end |
#save_yaml ⇒ Object
28 29 30 31 32 |
# File 'lib/reaver/metadata.rb', line 28 def save_yaml update_time File.open(@file, 'w') { |f| YAML.dump(@info, f) } end |