Class: Tairu::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/tairu/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(layers, cache, name = nil) ⇒ Configuration

Returns a new instance of Configuration.



7
8
9
10
11
# File 'lib/tairu/configuration.rb', line 7

def initialize(layers, cache, name = nil)
  @layers = layers
  @cache = cache
  @name = name
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



5
6
7
# File 'lib/tairu/configuration.rb', line 5

def cache
  @cache
end

#layersObject

Returns the value of attribute layers.



5
6
7
# File 'lib/tairu/configuration.rb', line 5

def layers
  @layers
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/tairu/configuration.rb', line 5

def name
  @name
end

Class Method Details

.config_from_file(file) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tairu/configuration.rb', line 13

def self.config_from_file(file)
  file = File.expand_path(file)

  if File.exists?(file)
    data = YAML.load_file(file)
  else
    raise 'Configuration file not found at specified location.'
  end

  name = data['name'] if data['name']

  if data['layers']
    layers = data['layers']
  else
    raise 'Layers must be specified.'
  end

  if data['cache'] && data['cache']['type']
    cache_type = data['cache']['type']
    options = data['cache']['options'] ? data['cache']['options'] : {}

    cache = start_cache(cache_type, options)
  end

  cache = Tairu::Cache::Memory.new if cache.nil?

  config = Configuration.new(layers, cache, name)

  config
end

.start_cache(cache_type = nil, options = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/tairu/configuration.rb', line 44

def self.start_cache(cache_type = nil, options = nil)
  if cache_type
    cache = Tairu::Cache::TYPES[cache_type].new(options)
  else
    cache = Tairu::Cache::Memory.new
  end

  cache
end