Class: Boar::Configuration

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Configuration

Returns a new instance of Configuration.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/boar/configuration.rb', line 12

def initialize(app)
  @data = {
    app: app,
    backend: Redis.new,
    skip_cache_param: "sc",
    handlers: {
      root: Boar::Handlers::Root,
      authentication: Boar::Handlers::Authentication,
      locale: Boar::Handlers::Locale,
      views: Boar::Handlers::Views,
      hosts: Boar::Handlers::Hosts
    }
  }

  initialize_pages()
  initialize_downloads()
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/boar/configuration.rb', line 35

def method_missing(method, *args, &block)
  key = method.to_sym

  if @data.has_key?(key) then
    rv = @data[key]
    rv = HashWithIndifferentAccess.new(rv) if rv.is_a?(Hash)
    rv
  else
    super
  end
end

Instance Method Details

#backend_key(key, _, request) ⇒ Object



30
31
32
33
# File 'lib/boar/configuration.rb', line 30

def backend_key(key, _, request)
  host = self.handlers[:hosts].new.call(request)
  "boar[#{host}]:#{key}"
end