Class: Rowr::StateSaver
- Inherits:
-
Object
- Object
- Rowr::StateSaver
- Defined in:
- lib/rowr/state_saver.rb
Instance Attribute Summary collapse
-
#cached ⇒ Object
Returns the value of attribute cached.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#scanned_files ⇒ Object
Returns the value of attribute scanned_files.
-
#src ⇒ Object
Returns the value of attribute src.
Instance Method Summary collapse
- #config_file_exists? ⇒ Boolean
-
#initialize(src_dir, filename) ⇒ StateSaver
constructor
A new instance of StateSaver.
- #load_state ⇒ Object
- #save_config(config) ⇒ Object
- #save_state ⇒ Object
Constructor Details
#initialize(src_dir, filename) ⇒ StateSaver
Returns a new instance of StateSaver.
7 8 9 10 11 12 13 |
# File 'lib/rowr/state_saver.rb', line 7 def initialize(src_dir, filename) @src = src_dir @file = File.(File.join(@src, filename)) @config = {} @cached = {} @scanned_files = [] end |
Instance Attribute Details
#cached ⇒ Object
Returns the value of attribute cached.
19 20 21 |
# File 'lib/rowr/state_saver.rb', line 19 def cached @cached end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
17 18 19 |
# File 'lib/rowr/state_saver.rb', line 17 def config @config end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
16 17 18 |
# File 'lib/rowr/state_saver.rb', line 16 def file @file end |
#scanned_files ⇒ Object
Returns the value of attribute scanned_files.
18 19 20 |
# File 'lib/rowr/state_saver.rb', line 18 def scanned_files @scanned_files end |
#src ⇒ Object
Returns the value of attribute src.
15 16 17 |
# File 'lib/rowr/state_saver.rb', line 15 def src @src end |
Instance Method Details
#config_file_exists? ⇒ Boolean
21 22 23 |
# File 'lib/rowr/state_saver.rb', line 21 def config_file_exists? File.exist?(@file) end |
#load_state ⇒ Object
34 35 36 37 38 39 |
# File 'lib/rowr/state_saver.rb', line 34 def load_state file = JSON.parse(File.open(@file).read, symbolize_names: true) @config = file[:config] @cached = file[:cached] @scanned_files = file[:scanned_files] end |
#save_config(config) ⇒ Object
41 42 43 44 |
# File 'lib/rowr/state_saver.rb', line 41 def save_config(config) @config = config save_state end |
#save_state ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/rowr/state_saver.rb', line 25 def save_state hashed = { config: @config, cached: @cached, scanned_files: scanned_files } File.open(@file, 'wb') { |f| f.write JSON.pretty_generate(hashed) } end |