Skip to content

Commit

Permalink
interceptor stack in place
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Oct 21, 2010
1 parent 2a6bf5c commit ca258ea
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
28 changes: 26 additions & 2 deletions lib/restfulie/client/dsl.rb
Expand Up @@ -2,16 +2,40 @@ module Restfulie::Client
class Dsl

def initialize
@traits = []
@requests = []
base
end

def method_missing(sym, *args)
request = "Restfulie::Client::Feature::#{sym.to_s.classify}Request".constantize
@requests << request

trait = "Restfulie::Client::Feature::#{sym.to_s.classify}".constantize
@traits << trait
self.extend trait
self
end

def request_flow
Parser.new(@requests).continue(self)
end

end

class Parser

def initialize(stack)
@stack = stack.dup
@following = @stack.shift
end

def continue(request)
current = @following
if @following==nil
return "finished"
end
@following = @stack.shift
current.new.execute(self, @request)
end

end
end
17 changes: 17 additions & 0 deletions lib/restfulie/client/feature.rb
@@ -1,9 +1,26 @@
module Restfulie::Client
module Feature

module Base

def at(uri)
@uri = uri
self
end

def get
request_flow
end

end

class BaseRequest

def execute(flow, request)
flow.continue(request)
end

end

end
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions spec/unit/restfulie_spec.rb
Expand Up @@ -12,6 +12,10 @@ module Restfulie::Client::Feature::Custom
def custom_history
end
end
class Restfulie::Client::Feature::CustomRequest
def custom_history
end
end

it "should allow adding extra methods by usage" do
Restfulie.use{custom}.respond_to?(:custom_history).should be_true
Expand Down

0 comments on commit ca258ea

Please sign in to comment.