Sha256: c367250358948779b0165e1e2bfecfb5a4e4785d023640863e567040566dd976

Contents?: true

Size: 1.33 KB

Versions: 20

Compression:

Stored size: 1.33 KB

Contents

# Effective Engine concern

module EffectiveGem
  extend ActiveSupport::Concern

  included do
    raise("expected self.config_keys method") unless respond_to?(:config_keys)

    config_keys.each do |key|
      self.singleton_class.define_method(key) { config()[key] }
      self.singleton_class.define_method("#{key}=") { |value| config()[key] = value }
    end
  end

  module ClassMethods
    def config(namespace = nil)
      namespace ||= Tenant.current if defined?(Tenant)
      @config.dig(namespace) || @config.dig(:effective)
    end

    def setup(namespace = nil, &block)
      @config ||= ActiveSupport::OrderedOptions.new

      namespace ||= Tenant.current if defined?(Tenant)
      namespace ||= :effective

      @config[namespace] ||= ActiveSupport::OrderedOptions.new

      yield(config(namespace))

      if(unsupported = (config(namespace).keys - config_keys)).present?
        if unsupported.include?(:authorization_method)
          raise("config.authorization_method has been removed. This gem will call EffectiveResources.authorization_method instead. Please double check the config.authorization_method setting in config/initializers/effective_resources.rb and remove it from this file.")
        end

        raise("unsupported config keys: #{unsupported}\n supported keys: #{config_keys}")
      end

      true
    end
  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
effective_resources-1.9.19 lib/effective_resources/effective_gem.rb
effective_resources-1.9.18 lib/effective_resources/effective_gem.rb
effective_resources-1.9.17 lib/effective_resources/effective_gem.rb
effective_resources-1.9.16 lib/effective_resources/effective_gem.rb
effective_resources-1.9.15 lib/effective_resources/effective_gem.rb
effective_resources-1.9.14 lib/effective_resources/effective_gem.rb
effective_resources-1.9.13 lib/effective_resources/effective_gem.rb
effective_resources-1.9.12 lib/effective_resources/effective_gem.rb
effective_resources-1.9.11 lib/effective_resources/effective_gem.rb
effective_resources-1.9.10 lib/effective_resources/effective_gem.rb
effective_resources-1.9.9 lib/effective_resources/effective_gem.rb
effective_resources-1.9.8 lib/effective_resources/effective_gem.rb
effective_resources-1.9.7 lib/effective_resources/effective_gem.rb
effective_resources-1.9.6 lib/effective_resources/effective_gem.rb
effective_resources-1.9.5 lib/effective_resources/effective_gem.rb
effective_resources-1.9.4 lib/effective_resources/effective_gem.rb
effective_resources-1.9.3 lib/effective_resources/effective_gem.rb
effective_resources-1.9.2 lib/effective_resources/effective_gem.rb
effective_resources-1.9.1 lib/effective_resources/effective_gem.rb
effective_resources-1.9.0 lib/effective_resources/effective_gem.rb