Class: Reaver::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/reaver/collection.rb

Overview

Loading collection from ~/.config/reaver/<filename.yml> and threat them

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Collection

Returns a new instance of Collection.



12
13
14
15
# File 'lib/reaver/collection.rb', line 12

def initialize(file)
  @file = file
  @changed = false
end

Instance Attribute Details

#tasksObject (readonly)

Returns the value of attribute tasks.



10
11
12
# File 'lib/reaver/collection.rb', line 10

def tasks
  @tasks
end

Instance Method Details

#launch(metadata) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/reaver/collection.rb', line 33

def launch()
  return if !@tasks['things'] || @tasks['things'].nil?

  get_each_files(@tasks)
  @tasks['things'].each { |task| move_thing(task) unless task['git'] }
  .info['changed'] = @changed
end

#load_yamlObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/reaver/collection.rb', line 17

def load_yaml
  puts ">> Loading #{@file}..."
  @tasks = if RUBY_VERSION >= '3.0'
      YAML.load_file(@file, permitted_classes: [Time, Symbol])
    else
      @tasks = YAML.load_file(@file)
    end
rescue StandardError => e
  raise e, "loading YAML fail for #{@file}: #{e.message}"
end

#save_yamlObject



28
29
30
31
# File 'lib/reaver/collection.rb', line 28

def save_yaml
  in_yaml = YAML.dump(@tasks)
  File.write(@file, in_yaml)
end