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
- #each(*args, &block) ⇒ Object
- #find(search) ⇒ Object
- #get(key) ⇒ Object
- #has?(key, value = nil) ⇒ Boolean
-
#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.
21 22 23 |
# File 'lib/landrush/store.rb', line 21 def initialize(backing_file) @backing_file = Pathname(backing_file) end |
Instance Attribute Details
#backing_file ⇒ Object
Returns the value of attribute backing_file.
19 20 21 |
# File 'lib/landrush/store.rb', line 19 def backing_file @backing_file end |
Class Method Details
.config ⇒ Object
10 11 12 |
# File 'lib/landrush/store.rb', line 10 def self.config @config ||= new(Server.working_dir.join('config.json')) end |
.hosts ⇒ Object
6 7 8 |
# File 'lib/landrush/store.rb', line 6 def self.hosts @hosts ||= new(Server.working_dir.join('hosts.json')) end |
.reset ⇒ Object
14 15 16 17 |
# File 'lib/landrush/store.rb', line 14 def self.reset @config = nil @hosts = nil end |
Instance Method Details
#clear! ⇒ Object
58 59 60 |
# File 'lib/landrush/store.rb', line 58 def clear! write({}) end |
#delete(key) ⇒ Object
33 34 35 |
# File 'lib/landrush/store.rb', line 33 def delete(key) write(current_config.reject { |k, v| k == key || v == key }) end |
#each(*args, &block) ⇒ Object
29 30 31 |
# File 'lib/landrush/store.rb', line 29 def each(*args, &block) current_config.each(*args, &block) end |
#find(search) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/landrush/store.rb', line 45 def find(search) search = IPAddr.new(search).reverse if (IPAddr.new(search) rescue nil) current_config.keys.detect do |key| key.casecmp(search) == 0 || search =~ /#{key}$/i || key =~ /^#{search}\./i end end |
#get(key) ⇒ Object
54 55 56 |
# File 'lib/landrush/store.rb', line 54 def get(key) current_config[key] end |
#has?(key, value = nil) ⇒ Boolean
37 38 39 40 41 42 43 |
# File 'lib/landrush/store.rb', line 37 def has?(key, value = nil) if value.nil? current_config.key? key else current_config[key] == value end end |
#set(key, value) ⇒ Object
25 26 27 |
# File 'lib/landrush/store.rb', line 25 def set(key, value) write(current_config.merge(key => value)) end |