mirror of
https://github.com/omniauth/omniauth.git
synced 2022-11-09 12:31:49 -05:00
Evaluate DSL methods in the context of the strategy instance.
This commit is contained in:
parent
af2226812a
commit
4a8e1cc3e0
2 changed files with 11 additions and 11 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue