Class: Landrush::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/landrush/store.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_fileObject

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

.configObject



10
11
12
# File 'lib/landrush/store.rb', line 10

def self.config
  @config ||= new(Server.working_dir.join('config.json'))
end

.hostsObject



6
7
8
# File 'lib/landrush/store.rb', line 6

def self.hosts
  @hosts ||= new(Server.working_dir.join('hosts.json'))
end

.resetObject



14
15
16
17
# File 'lib/landrush/store.rb', line 14

def self.reset
  @config = nil
  @hosts = nil
end

Instance Method Details

#clear!Object



62
63
64
# File 'lib/landrush/store.rb', line 62

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
53
54
55
56
# File 'lib/landrush/store.rb', line 45

def find(search)
  search = IPAddr.new(search).reverse if begin
                                            IPAddr.new(search)
                                          rescue
                                            nil
                                          end
  current_config.keys.detect do |key|
    key.casecmp(search) == 0   ||
      search =~ /#{key}$/i     ||
      key    =~ /^#{search}\./i
  end
end

#get(key) ⇒ Object



58
59
60
# File 'lib/landrush/store.rb', line 58

def get(key)
  current_config[key]
end

#has?(key, value = nil) ⇒ Boolean

Returns:

  • (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