Class: RightSupport::Config::FeatureSet
- Defined in:
- lib/right_support/config/feature_set.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#configuration_source ⇒ Object
Returns the value of attribute configuration_source.
Instance Method Summary collapse
-
#[](feature_group, feature = nil) ⇒ Object
Returns configuration value.
-
#initialize(cfg_source) ⇒ FeatureSet
constructor
Create features configuration object.
-
#load(something) ⇒ Object
Load configuration source.
Constructor Details
#initialize(cfg_source) ⇒ FeatureSet
Create features configuration object
Parameters
- cfg_source(IO|String)
-
File path, IO or raw yaml.
46 47 48 |
# File 'lib/right_support/config/feature_set.rb', line 46 def initialize(cfg_source) @configuration = load(cfg_source) end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
40 41 42 |
# File 'lib/right_support/config/feature_set.rb', line 40 def configuration @configuration end |
#configuration_source ⇒ Object
Returns the value of attribute configuration_source.
39 40 41 |
# File 'lib/right_support/config/feature_set.rb', line 39 def configuration_source @configuration_source end |
Instance Method Details
#[](feature_group, feature = nil) ⇒ Object
Returns configuration value
Parameters
- feature_group(String)
-
Feature group name
- feature(String|nil)
-
Feature name
Return
- (String|Boolean)
-
Configuration value
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/right_support/config/feature_set.rb', line 58 def [](feature_group, feature=nil) return_value = true if @configuration[feature_group] if feature == nil return_value = @configuration[feature_group] else return_value = @configuration[feature_group][feature] end else return_value = RecursiveTrueClass.new end return_value = true if return_value == nil return_value end |
#load(something) ⇒ Object
Load configuration source
Parameters
- something(IO|String|Hash)
-
File path, IO, raw YAML string, or a pre-loaded Hash
Return
- (Hash|nil)
-
Loaded yaml file
Raise
- (ArgumentError)
-
If configuration source can`t be loaded
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/right_support/config/feature_set.rb', line 83 def load(something) return_value = nil = '' @configuration_source = something begin return_value = YAMLConfig.read(something) rescue Exception => e = "#{e}" end raise ArgumentError, "Can't coerce #{something.inspect} into YAML/Hash. #{}" unless return_value return_value end |