Sha256: a095c361d7002ac35dbb63725e36ea357bb73bf54635c09b7b521c2b27be78be

Contents?: true

Size: 903 Bytes

Versions: 11

Compression:

Stored size: 903 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 ||=
        begin
          if File.exist?(@config_file)
            YAML.load_file(@config_file)
          else
            {}
          end
        end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hyrax-3.4.1 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-3.4.0 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-3.3.0 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-3.2.0 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-3.1.0 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-3.0.2 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-3.0.1 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-3.0.0 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-3.0.0.pre.rc4 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-3.0.0.pre.rc3 app/strategies/hyrax/strategies/yaml_strategy.rb
hyrax-3.0.0.pre.rc2 app/strategies/hyrax/strategies/yaml_strategy.rb