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