Sha256: 2daa2472d06020731bba27245ef61bd24e544713fc2c570c78afe33463faccc1

Contents?: true

Size: 867 Bytes

Versions: 14

Compression:

Stored size: 867 Bytes

Contents

# frozen_string_literal: true
module Hyrax::Strategies
  class YamlStrategy < Flipflop::Strategies::AbstractStrategy
    class << self
      def default_description
        "Features configured by a YAML configuration file."
      end
    end

    def initialize(**options)
      @config_file = options.delete(:config)
      yaml_file
      super(**options)
    end

    def switchable?
      false
    end

    def enabled?(feature)
      return unless key_exists?(feature)
      yaml_file[feature.to_s]["enabled"]
    end

    def switch!(_feature, _enabled); end

    def clear!(_feature); end

    private

    def key_exists?(feature)
      yaml_file[feature.to_s]&.key?("enabled")
    end

    def yaml_file
      @yaml_file ||=
        if File.exist?(@config_file)
          YAML.load_file(@config_file)
        else
          {}
        end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-5.0.0 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-5.0.0.rc3 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-5.0.0.rc2 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-5.0.0.rc1 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-3.6.0 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-4.0.0 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-4.0.0.rc3 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-4.0.0.rc2 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-4.0.0.rc1 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-3.5.0 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-4.0.0.beta2 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-3.4.2 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-4.0.0.beta1 app/strategies/hyrax/strategies/yaml_strategy.rb