diff --git a/lib/omniauth/strategy.rb b/lib/omniauth/strategy.rb index 53842b9..5949e0c 100644 --- a/lib/omniauth/strategy.rb +++ b/lib/omniauth/strategy.rb @@ -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, diff --git a/spec/omniauth/strategy_spec.rb b/spec/omniauth/strategy_spec.rb index 4895c23..03a9430 100644 --- a/spec/omniauth/strategy_spec.rb +++ b/spec/omniauth/strategy_spec.rb @@ -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