Created
January 22, 2016 14:47
-
-
Save krisleech/e9e9127526b54bf58e4c to your computer and use it in GitHub Desktop.
Guarding configuration "type"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dry/container' | |
require 'logger' | |
module Oxygen | |
class Configuration | |
extend Dry::Container::Mixin | |
# default configuration | |
register('reports', []) | |
register('utils.logger', Logger.new($stdout)) | |
module Reports | |
def self.register(configuration) | |
raise ArgumentError unless %i(name url section).all? { |key| configuration.keys.include?(key) } | |
Configuration['reports'] << configuration | |
self | |
end | |
def self.all | |
Configuration['reports'] | |
end | |
end | |
end | |
end | |
Oxygen::Configuration::Reports.register(name: '...', url: '...', section: '...') | |
Oxygen::Configuration::Reports.all # => [...] | |
Oxygen::Configuration['reports'] # => [...] |
kwando
commented
Jan 22, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment