Sha256: af1325e2efb36f6596cb185ef962458289c7bb98a799fe78804e64109b71aa7f

Contents?: true

Size: 711 Bytes

Versions: 16

Compression:

Stored size: 711 Bytes

Contents

module Enableable

  def enabled_middleware(root, env)
    middleware = self.singleton_class.ancestors.find(&it.to_s.start_with?("#{root}::Middleware"))
    return nil unless middleware.enabled?(env)
    middleware.disable if middleware.once?(env)
    middleware
  end

  def self.included(base)
    base.module_eval do
      def self.enable(condition = true, once:true)
        @enabled = condition
        @once = once
      end
      def self.enabled?(env)
        case @enabled
        when Proc then @enabled.call(env)
        else @enabled
        end
      end
      def self.once?(env)
        @once
      end
      def self.disable
        @enabled = false
      end

      disable
    end
  end
end


Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
schema_plus_indexes-0.3.1 spec/support/enableable.rb
schema_plus_indexes-0.3.0 spec/support/enableable.rb
schema_plus_indexes-0.2.4 spec/support/enableable.rb
schema_plus_indexes-0.2.3 spec/support/enableable.rb
schema_plus_core-1.0.2 spec/support/enableable.rb
schema_plus_core-1.0.1 spec/support/enableable.rb
schema_plus_indexes-0.2.2 spec/support/enableable.rb
schema_plus_indexes-0.2.1 spec/support/enableable.rb
schema_plus_core-1.0.0 spec/support/enableable.rb
schema_plus_core-0.6.2 spec/support/enableable.rb
schema_plus_core-0.6.1 spec/support/enableable.rb
schema_plus_core-0.6.0 spec/support/enableable.rb
schema_plus_core-0.5.1 spec/support/enableable.rb
schema_plus_core-0.5.0 spec/support/enableable.rb
schema_plus_indexes-0.2.0 spec/support/enableable.rb
schema_plus_core-0.4.0 spec/support/enableable.rb