Sha256: 3b4663400260564fc6cc7223c23eb24c7af634cf2eb81d10154a769391c6030d

Contents?: true

Size: 1.14 KB

Versions: 26

Compression:

Stored size: 1.14 KB

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 IgnoreGlobsWrapper.new(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

    class IgnoreGlobsWrapper < Array
      def ignore?(uri)
        path = Addressable::URI.parse(uri).path

        any? { |glob| glob.match?(path) }
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
wovnrb-3.11.1 lib/wovnrb/settings.rb
wovnrb-3.11.0 lib/wovnrb/settings.rb
wovnrb-3.10.3 lib/wovnrb/settings.rb
wovnrb-3.10.2 lib/wovnrb/settings.rb
wovnrb-3.10.1 lib/wovnrb/settings.rb
wovnrb-3.10.0 lib/wovnrb/settings.rb
wovnrb-3.9.0 lib/wovnrb/settings.rb
wovnrb-3.8.0 lib/wovnrb/settings.rb
wovnrb-3.7.2 lib/wovnrb/settings.rb
wovnrb-3.7.1 lib/wovnrb/settings.rb
wovnrb-3.6.0 lib/wovnrb/settings.rb
wovnrb-3.5.0 lib/wovnrb/settings.rb
wovnrb-3.4.1 lib/wovnrb/settings.rb
wovnrb-3.4.0 lib/wovnrb/settings.rb
wovnrb-3.3.1 lib/wovnrb/settings.rb
wovnrb-3.2.0 lib/wovnrb/settings.rb
wovnrb-3.1.0 lib/wovnrb/settings.rb
wovnrb-3.0.3 lib/wovnrb/settings.rb
wovnrb-3.0.1 lib/wovnrb/settings.rb
wovnrb-3.0.0 lib/wovnrb/settings.rb