1
0
Fork 0
mirror of https://github.com/omniauth/omniauth.git synced 2022-11-09 12:31:49 -05:00

Adds .option method to Strategy for even more declarative configuration.

This commit is contained in:
Michael Bleigh 2011-09-26 12:11:41 -05:00
parent 53bc3f5741
commit ad873fda58
2 changed files with 31 additions and 0 deletions

View file

@ -51,6 +51,25 @@ module OmniAuth
yield default_options and return unless options
default_options.deep_merge!(options)
end
# Directly declare a default option for your class. This is a useful from
# a documentation perspective as it provides a simple line-by-line analysis
# of the kinds of options your strategy provides by default.
#
# @param name [Symbol] The key of the default option in your configuration hash.
# @param value [Object] The value your object defaults to. Nil if not provided.
#
# @example
#
# class MyStrategy
# include OmniAuth::Strategy
#
# option :foo, 'bar'
# option
# end
def option(name, value = nil)
default_options[name] = value
end
end
# Initializes the strategy by passing in the Rack endpoint,

View file

@ -59,6 +59,18 @@ describe OmniAuth::Strategy do
end
end
describe '.option' do
subject { klass = Class.new; klass.send :include, OmniAuth::Strategy; klass }
it 'should set a default value' do
subject.option :abc, 123
subject.default_options.abc.should == 123
end
it 'should set the default value to nil if none is provided' do
subject.option :abc
subject.default_options.abc.should be_nil
end
end
describe '#initialize' do
context 'options extraction' do