Class: Sinatra::API::Config

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

Constant Summary collapse

Defaults =
{
  with_errors: true,
  verbose: false
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sinatra/api/config.rb', line 11

def initialize(options = {})
  api = Sinatra::API

  options = {}.merge(Config::Defaults).merge(options)
  options.each_pair do |key, setting|
    unless self.respond_to?(key)
      api.logger.warn "Unknown option #{key} => #{setting}"
      next
    end

    self[key] = setting if changed?(key, setting)
  end

  super()
end

Instance Attribute Details

#verboseObject

Returns the value of attribute verbose.



4
5
6
# File 'lib/sinatra/api/config.rb', line 4

def verbose
  @verbose
end

#with_errorsObject

Returns the value of attribute with_errors.



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

def with_errors
  @with_errors
end

Instance Method Details

#[](key) ⇒ Object



27
28
29
# File 'lib/sinatra/api/config.rb', line 27

def [](key)
  self.send key rescue nil
end

#[]=(key, value) ⇒ Object



31
32
33
34
# File 'lib/sinatra/api/config.rb', line 31

def []=(key, value)
  self.send("#{key}=", value)
  Sinatra::API.trigger "#{key}_setting", value
end