Class: Braavos::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/braavos/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Config

Returns a new instance of Config.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/braavos/config.rb', line 6

def initialize(config)
  @settings = config
  config.each do |k,v|
    send("#{k}=", v) if respond_to?("#{k}=")
  end
  self.backup_prefix = nil if backup_prefix && backup_prefix.strip.size == 0
  self.storage_backing ||= 's3'
  self.temp_loc ||= ''

  FileUtils.mkdir_p temp_loc unless File.directory?(temp_loc)
  raise "Missing temp location: #{temp_loc}" unless File.directory?(temp_loc)
end

Instance Attribute Details

#backup_prefixObject

Returns the value of attribute backup_prefix.



3
4
5
# File 'lib/braavos/config.rb', line 3

def backup_prefix
  @backup_prefix
end

#bucket_nameObject

Returns the value of attribute bucket_name.



3
4
5
# File 'lib/braavos/config.rb', line 3

def bucket_name
  @bucket_name
end

#data_locObject

Returns the value of attribute data_loc.



3
4
5
# File 'lib/braavos/config.rb', line 3

def data_loc
  @data_loc
end

#discoveryObject

Returns the value of attribute discovery.



3
4
5
# File 'lib/braavos/config.rb', line 3

def discovery
  @discovery
end

#environmentObject

Returns the value of attribute environment.



3
4
5
# File 'lib/braavos/config.rb', line 3

def environment
  @environment
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/braavos/config.rb', line 3

def name
  @name
end

#parallel_jobsObject

Returns the value of attribute parallel_jobs.



3
4
5
# File 'lib/braavos/config.rb', line 3

def parallel_jobs
  @parallel_jobs
end

#serviceObject

Returns the value of attribute service.



3
4
5
# File 'lib/braavos/config.rb', line 3

def service
  @service
end

#settingsObject

Returns the value of attribute settings.



3
4
5
# File 'lib/braavos/config.rb', line 3

def settings
  @settings
end

#storage_backingObject

Returns the value of attribute storage_backing.



3
4
5
# File 'lib/braavos/config.rb', line 3

def storage_backing
  @storage_backing
end

#sync_locObject

Returns the value of attribute sync_loc.



3
4
5
# File 'lib/braavos/config.rb', line 3

def sync_loc
  @sync_loc
end

#temp_locObject

Returns the value of attribute temp_loc.



3
4
5
# File 'lib/braavos/config.rb', line 3

def temp_loc
  @temp_loc
end

Instance Method Details

#backup_path(reset = false) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/braavos/config.rb', line 31

def backup_path(reset=false)
  remove_instance_variable(:@backup_path) if reset
  @backup_path ||= -> do
    path = [backup_prefix, name, environment, service].compact
    File.join(*path)
  end.call
end

#get_regex(key) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/braavos/config.rb', line 39

def get_regex(key)
  if (regex = settings[key]) && regex.size > 2
    if regex[0] == regex[-1] && regex[0] == '/'
      regex = regex[1...-1]
    end
    /#{regex}/
  end
end

#service_classObject



19
20
21
22
23
# File 'lib/braavos/config.rb', line 19

def service_class
  @service_class ||= -> do
    Object.const_get("Braavos::Service::#{service.capitalize}")
  end.call
end

#storage_classObject



25
26
27
28
29
# File 'lib/braavos/config.rb', line 25

def storage_class
  @storage_class ||= -> do
    Object.const_get("Braavos::Storage::#{storage_backing.capitalize}")
  end.call
end