Class: Moon::Application::Configuration

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

Overview

Application configuration.

Constant Summary collapse

SCHEMA =
Configure::Schema.build {
  only :session, :route, :validator, :formatter
  nested {
    session {
      only :secret
    }
    route {
      only :http_method, :path, :actions
      argument_keys :http_method, :path
    }
    validator {
      only :model_class, :attributes
    }
    formatter {
      only :model_class, :object
    }
  }
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Configuration

Returns a new instance of Configuration.



25
26
27
# File 'lib/moon/application/configuration.rb', line 25

def initialize(&block)
  @hash = Configure.process SCHEMA, &block
end

Instance Method Details

#formattersObject



46
47
48
49
50
51
52
53
# File 'lib/moon/application/configuration.rb', line 46

def formatters
  formatters = { }
  [ @hash[:formatter] ].compact.flatten.each do |formatter_hash|
    model_class, object = formatter_hash.values_at :model_class, :object
    formatters[model_class] = object
  end
  formatters
end

#routesObject



33
34
35
# File 'lib/moon/application/configuration.rb', line 33

def routes
  [ @hash[:route] ].compact.flatten
end

#sessionObject



29
30
31
# File 'lib/moon/application/configuration.rb', line 29

def session
  @hash[:session]
end

#validatorsObject



37
38
39
40
41
42
43
44
# File 'lib/moon/application/configuration.rb', line 37

def validators
  validators = { }
  [ @hash[:validator] ].compact.flatten.each do |validator_hash|
    model_class, attributes = validator_hash.values_at :model_class, :attributes
    validators[model_class] = attributes
  end
  validators
end