Sha256: 309414545fe9a8ca80b2bd70a7a3341fec964f80426ada6fa94860dcc8e2bc87
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
module Grenache class BaseConfiguration def values @values ||= {} end def method_missing(name, *args, &block) if name[-1] == "=" values[name[0,name.size-1]] = args.first else values[name.to_s] end end end class Configuration < BaseConfiguration def initialize(params = {}) @values = self.class.default.values.clone params.each do |k, v| @values[k.to_s] = v end # sanitize urls if not @values["grape_address"].end_with?("/") @values["grape_address"] = @values["grape_address"] + "/" end end def self.set_default &block yield default end def self.default @defaults ||= BaseConfiguration.new end end # Configuration helpers module Configurable def self.included(base) base.extend(ClassMethods) end # Instance configuration, can be altered indipendently def config @configuration ||= Configuration.new end module ClassMethods # Class configuration def config Grenache::Configuration.default end def default_conf &block Grenache::Configuration.set_default &block end alias_method :configure, :default_conf end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
grenache-ruby-base-0.2.18 | lib/grenache/configurable.rb |