Sha256: 5faa0f6242810ceae4556cb53ee6357f5f7ed33d26b8df01072d91c169581fbf
Contents?: true
Size: 1.24 KB
Versions: 28
Compression:
Stored size: 1.24 KB
Contents
## # File: <gem-root>/lib/skn_utils/exploring/configuration.rb # # Engines and Gem sometimes need a configuration object, this is an example # Options class, consider OpenStruct2 or ActiveSupport::OrderedOptions as alternatives module SknUtils module Exploring module Configuration module_function def option_defaults @option_defaults ||= {one: 1, two: 2, three: 3} end def option_defaults=(parms) @option_defaults = parms end def reset! @configuration = Options.new(option_defaults) true end def config configure end def configure # Initialize with both the configuration keys and default values @configuration || reset! yield(@configuration) if block_given? @configuration end private class Options def initialize(parms={}) parms.each_pair do |k,v| self.singleton_class.send(:attr_accessor, k) instance_variable_set("@#{k}",v) end end end end # require your Gem or Engine here end end # In config/initializers/gem_config.rb # SknUtils::Exploring::Configuration.class_variable_set(:option_defaults, {one: 1, two: 2, three: 3})
Version data entries
28 entries across 28 versions & 1 rubygems