Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Commit

Permalink
Initialize action with flipper and request
Browse files Browse the repository at this point in the history
Need access to flipper and request for each action.
  • Loading branch information
jnunemaker committed Sep 12, 2012
1 parent c7029be commit 991a2e6
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/flipper/ui/middleware.rb
Expand Up @@ -27,10 +27,10 @@ def self.public_path
@public_path ||= Flipper::UI.root.join('public')
end

attr_reader :request
attr_reader :flipper, :request

def initialize(request)
@request = request
def initialize(flipper, request)
@flipper, @request = flipper, request
@code = 200
@headers = {'Content-Type' => 'text/html'}
end
Expand Down Expand Up @@ -70,14 +70,14 @@ def public_path
class Index < Action
Feature = Struct.new(:name)

def get(flipper)
def get
@features = flipper.adapter.set_members('features').map { |name| Feature.new(name) }
render :index
end
end

class File < Action
def get(flipper)
def get
Rack::File.new(public_path).call(request.env)
end
end
Expand All @@ -88,24 +88,26 @@ def self.detect(request)

case request.path_info
when /\/flipper\/?$/
Index.new(request)
Index
when /\/flipper\/images\/(.*)/
File.new(request)
File
when /\/flipper\/css\/(.*)/
File.new(request)
File
end
end
end

def call(env)
request = Rack::Request.new(env)

if action = Route.detect(request)
case request.request_method.downcase
when 'get'
action.get(@flipper)
if action_class = Route.detect(request)
action = action_class.new(@flipper, request)
method_name = request.request_method.downcase

if action.respond_to?(method_name)
action.send method_name
else
raise "#{request.request_method} not supported at this time"
raise "#{request.request_method} not supported by #{action.class}"
end
else
@app.call(env)
Expand Down

0 comments on commit 991a2e6

Please sign in to comment.