Sha256: 5d7caefa3f314498e91049df1ce1dc1fcd15f77f3ced4440ab15f7da186d687a

Contents?: true

Size: 973 Bytes

Versions: 8

Compression:

Stored size: 973 Bytes

Contents

module Wovnrb
  class Settings < Hash
    def initialize(*args, **kwargs)
      super(*args, **kwargs)
      @dynamic_settings = {}
    end

    def [](key)
      return @dynamic_settings[key] if @dynamic_settings.key?(key)
      return ignore_globs if key == 'ignore_globs'

      super(key)
    end

    def ignore_globs
      ignore_paths = self['ignore_paths']
      return [] unless ignore_paths.is_a?(Array)

      ignore_paths.map { |pattern| Glob.new(pattern) }
    end

    def clear_dynamic_settings!
      @dynamic_settings.clear
    end

    def update_dynamic_settings!(params)
      # If the user defines dynamic settings for this request, use it instead of the config
      DYNAMIC_KEYS.each do |params_key, setting_key|
        value = params[params_key]
        @dynamic_settings[setting_key] = value if value
      end
    end

    DYNAMIC_KEYS = {
      'wovn_token' => 'project_token',
      'wovn_ignore_paths' => 'ignore_paths'
    }.freeze
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
wovnrb-2.2.0 lib/wovnrb/settings.rb
wovnrb-2.1.0 lib/wovnrb/settings.rb
wovnrb-2.0.5 lib/wovnrb/settings.rb
wovnrb-2.0.4 lib/wovnrb/settings.rb
wovnrb-2.0.3 lib/wovnrb/settings.rb
wovnrb-2.0.2 lib/wovnrb/settings.rb
wovnrb-2.0.1 lib/wovnrb/settings.rb
wovnrb-2.0.0 lib/wovnrb/settings.rb