class SmoothChange::Adapters::Yaml

Load features from a YAML file

Public Class Methods

new(file:) click to toggle source
# File lib/smooth_change/adapters/yaml.rb, line 7
def initialize(file:)
  @file_content = if file.respond_to?(:read)
                    file.read
                  else
                    File.read(file)
                  end
  parse_file
end

Public Instance Methods

features() click to toggle source
# File lib/smooth_change/adapters/yaml.rb, line 16
def features
  @features ||= {}.with_indifferent_access
end
get(feature_name) click to toggle source

@return [Feature] @param [string] feature_name

# File lib/smooth_change/adapters/yaml.rb, line 22
def get(feature_name)
  @features[feature_name]
end

Private Instance Methods

parse_file() click to toggle source
# File lib/smooth_change/adapters/yaml.rb, line 28
def parse_file
  file_content = ::YAML.safe_load(@file_content)
  file_content["features"].each do |name, opts|
    features[name] = Feature.new(name, opts["mode"])
  end
end