Class: PhenomenalRails::Middleware
- Inherits:
-
Object
- Object
- PhenomenalRails::Middleware
- Defined in:
- lib/phenomenal_rails/middleware.rb
Instance Method Summary collapse
- #add_condition(feature, &block) ⇒ Object
- #before_call(env) ⇒ Object
- #call(env) ⇒ Object
- #clear_activition_conditions ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
2 3 4 5 6 |
# File 'lib/phenomenal_rails/middleware.rb', line 2 def initialize(app) @app=app @activation_conditions=Array.new Phenomenal::Feature.middleware=self end |
Instance Method Details
#add_condition(feature, &block) ⇒ Object
8 9 10 11 |
# File 'lib/phenomenal_rails/middleware.rb', line 8 def add_condition(feature,&block) @activation_conditions.push([feature,block]) sort_activation_conditions end |
#before_call(env) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/phenomenal_rails/middleware.rb', line 22 def before_call(env) @activation_conditions.each do |feature_block| feature,block = feature_block if feature.active? block.call(env) end end end |
#call(env) ⇒ Object
17 18 19 20 |
# File 'lib/phenomenal_rails/middleware.rb', line 17 def call(env) before_call(env) @app.call(env) end |
#clear_activition_conditions ⇒ Object
13 14 15 |
# File 'lib/phenomenal_rails/middleware.rb', line 13 def clear_activition_conditions @activation_conditions.clear end |