Class: DevSuite::Utils::Store::Driver::File
- Inherits:
-
Base
- Object
- Construct::Component::Base
- Base
- DevSuite::Utils::Store::Driver::File
- Defined in:
- lib/dev_suite/utils/store/driver/file.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #export(destination) ⇒ Object
- #fetch(key) ⇒ Object
- #import(source) ⇒ Object
-
#initialize(**options) ⇒ File
constructor
A new instance of File.
- #set(key, value) ⇒ Object
Methods inherited from Construct::Component::Base
Constructor Details
#initialize(**options) ⇒ File
Returns a new instance of File.
8 9 10 11 12 13 |
# File 'lib/dev_suite/utils/store/driver/file.rb', line 8 def initialize(**) super() @path = [:path] || fetch_setting(:path, default: "tmp/store.json") @data = {} load_data end |
Instance Method Details
#clear ⇒ Object
29 30 31 32 |
# File 'lib/dev_suite/utils/store/driver/file.rb', line 29 def clear @data = {} save_data end |
#delete(key) ⇒ Object
24 25 26 27 |
# File 'lib/dev_suite/utils/store/driver/file.rb', line 24 def delete(key) Data.delete_key_by_path(@data, key) save_data end |
#export(destination) ⇒ Object
40 41 42 |
# File 'lib/dev_suite/utils/store/driver/file.rb', line 40 def export(destination) FileWriter.write(destination, @data) end |
#fetch(key) ⇒ Object
20 21 22 |
# File 'lib/dev_suite/utils/store/driver/file.rb', line 20 def fetch(key) Data.get_value_by_path(@data, key) end |
#import(source) ⇒ Object
34 35 36 37 38 |
# File 'lib/dev_suite/utils/store/driver/file.rb', line 34 def import(source) raise ArgumentError, "The file does not exist" unless ::File.exist?(source) @data = FileLoader.load(source) end |
#set(key, value) ⇒ Object
15 16 17 18 |
# File 'lib/dev_suite/utils/store/driver/file.rb', line 15 def set(key, value) Data.set_value_by_path(@data, key, value) save_data end |