From ca258eac63b1e9588123323fdbcbcce552d8a265 Mon Sep 17 00:00:00 2001 From: guilherme silveira Date: Thu, 21 Oct 2010 00:39:20 -0200 Subject: [PATCH] interceptor stack in place --- lib/restfulie/client/dsl.rb | 28 +++++++++++++++++-- lib/restfulie/client/feature.rb | 17 +++++++++++ .../spec => spec}/integration/spec_helper.rb | 0 {tests/spec => spec}/integration/twitter.rb | 0 .../spec => spec}/integration/twitter_spec.rb | 0 spec/unit/restfulie_spec.rb | 4 +++ 6 files changed, 47 insertions(+), 2 deletions(-) rename {tests/spec => spec}/integration/spec_helper.rb (100%) rename {tests/spec => spec}/integration/twitter.rb (100%) rename {tests/spec => spec}/integration/twitter_spec.rb (100%) diff --git a/lib/restfulie/client/dsl.rb b/lib/restfulie/client/dsl.rb index 5bc23f4f..0c805203 100644 --- a/lib/restfulie/client/dsl.rb +++ b/lib/restfulie/client/dsl.rb @@ -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 \ No newline at end of file diff --git a/lib/restfulie/client/feature.rb b/lib/restfulie/client/feature.rb index c8f24f95..9d10c58a 100644 --- a/lib/restfulie/client/feature.rb +++ b/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 \ No newline at end of file diff --git a/tests/spec/integration/spec_helper.rb b/spec/integration/spec_helper.rb similarity index 100% rename from tests/spec/integration/spec_helper.rb rename to spec/integration/spec_helper.rb diff --git a/tests/spec/integration/twitter.rb b/spec/integration/twitter.rb similarity index 100% rename from tests/spec/integration/twitter.rb rename to spec/integration/twitter.rb diff --git a/tests/spec/integration/twitter_spec.rb b/spec/integration/twitter_spec.rb similarity index 100% rename from tests/spec/integration/twitter_spec.rb rename to spec/integration/twitter_spec.rb diff --git a/spec/unit/restfulie_spec.rb b/spec/unit/restfulie_spec.rb index 9e598031..6bb0f213 100644 --- a/spec/unit/restfulie_spec.rb +++ b/spec/unit/restfulie_spec.rb @@ -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