From 4a8e1cc3e0d7a183252fde3fe68bb8ae82dab4be Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Wed, 28 Sep 2011 13:06:03 -0500 Subject: [PATCH] Evaluate DSL methods in the context of the strategy instance. --- lib/omniauth/strategy.rb | 16 ++++++++-------- spec/omniauth/strategy_spec.rb | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/omniauth/strategy.rb b/lib/omniauth/strategy.rb index 0191dc4..b027b7e 100644 --- a/lib/omniauth/strategy.rb +++ b/lib/omniauth/strategy.rb @@ -91,15 +91,15 @@ module OmniAuth @#{fetcher}_proc = block end - def #{fetcher}_stack - compile_stack(self.ancestors, :#{fetcher}) + def #{fetcher}_stack(context) + compile_stack(self.ancestors, :#{fetcher}, context) end RUBY end - def compile_stack(ancestors, method) + def compile_stack(ancestors, method, context) stack = ancestors.inject([]) do |a, ancestor| - a << ancestor.send(method).call if ancestor.respond_to?(method) && ancestor.send(method) + a << context.instance_eval(&ancestor.send(method)) if ancestor.respond_to?(method) && ancestor.send(method) a end stack.reverse! @@ -275,19 +275,19 @@ module OmniAuth end def uid - self.class.uid_stack.last + self.class.uid_stack(self).last end def info - merge_stack(self.class.info_stack) + merge_stack(self.class.info_stack(self)) end def credentials - merge_stack(self.class.credentials_stack) + merge_stack(self.class.credentials_stack(self)) end def extra - merge_stack(self.class.extra_stack) + merge_stack(self.class.extra_stack(self)) end def auth_hash diff --git a/spec/omniauth/strategy_spec.rb b/spec/omniauth/strategy_spec.rb index 2af8a7c..677925b 100644 --- a/spec/omniauth/strategy_spec.rb +++ b/spec/omniauth/strategy_spec.rb @@ -123,9 +123,9 @@ describe OmniAuth::Strategy do subject{ fresh_strategy } %w(uid info credentials extra).each do |fetcher| it ".#{fetcher}_stack should be an array of called ancestral procs" do - proc = lambda{ "Hello" } - subject.send(fetcher, &proc) - subject.send(fetcher + "_stack").should == ["Hello"] + fetchy = Proc.new{ "Hello" } + subject.send(fetcher, &fetchy) + subject.send("#{fetcher}_stack", subject.new(app)).should == ["Hello"] end end end