Class: Landrush::Store
- Inherits:
-
Object
- Object
- Landrush::Store
- Defined in:
- lib/landrush/store.rb
Instance Attribute Summary collapse
-
#backing_file ⇒ Object
Returns the value of attribute backing_file.
Class Method Summary collapse
Instance Method Summary collapse
- #clear! ⇒ Object
- #delete(key) ⇒ Object
- #find(search) ⇒ Object
- #get(key) ⇒ Object
-
#initialize(backing_file) ⇒ Store
constructor
A new instance of Store.
- #set(key, value) ⇒ Object
Constructor Details
#initialize(backing_file) ⇒ Store
Returns a new instance of Store.
9 10 11 |
# File 'lib/landrush/store.rb', line 9 def initialize(backing_file) @backing_file = Pathname(backing_file) end |
Instance Attribute Details
#backing_file ⇒ Object
Returns the value of attribute backing_file.
7 8 9 |
# File 'lib/landrush/store.rb', line 7 def backing_file @backing_file end |
Class Method Details
.hosts ⇒ Object
3 4 5 |
# File 'lib/landrush/store.rb', line 3 def self.hosts @hosts ||= new(Landrush.working_dir.join('hosts.json')) end |
Instance Method Details
#clear! ⇒ Object
41 42 43 |
# File 'lib/landrush/store.rb', line 41 def clear! write({}) end |
#delete(key) ⇒ Object
17 18 19 |
# File 'lib/landrush/store.rb', line 17 def delete(key) write(current_config.reject { |k, _| k == key }) end |
#find(search) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/landrush/store.rb', line 21 def find(search) current_config.keys.detect do |key| key == search || search =~ /#{key}$/ || key =~ /^#{search}\./ end end |
#get(key) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/landrush/store.rb', line 29 def get(key) value = current_config[key] redirect = find(value) if value if redirect get(redirect) else value end end end |
#set(key, value) ⇒ Object
13 14 15 |
# File 'lib/landrush/store.rb', line 13 def set(key, value) write(current_config.merge(key => value)) end |