Module: Doorkeeper::Config::Option
- Included in:
- Doorkeeper::Config
- Defined in:
- lib/doorkeeper/config.rb
Instance Method Summary collapse
- #extended(base) ⇒ Object
-
#option(name, options = {}) ⇒ Object
Defines configuration option.
Instance Method Details
#extended(base) ⇒ Object
130 131 132 |
# File 'lib/doorkeeper/config.rb', line 130 def extended(base) base.send(:private, :option) end |
#option(name, options = {}) ⇒ Object
Defines configuration option
When you call option, it defines two methods. One method will take place in the Config
class and the other method will take place in the Builder
class.
The name
parameter will set both builder method and config attribute. If the :as
option is defined, the builder method will be the specified option while the config attribute will be the name
parameter.
If you want to introduce another level of config DSL you can define builder_class
parameter. Builder should take a block as the initializer parameter and respond to function build
that returns the value of the config attribute.
Options
- :
as
-
Set the builder method that goes inside
configure
block
- :
:default
-
The default value in case no option was set
Examples
option :name
option :name, :as => :set_name
option :name, :default => "My Name"
option :scopes :builder_class => ScopesBuilder
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/doorkeeper/config.rb', line 102 def option(name, = {}) attribute = [:as] || name attribute_builder = [:builder_class] Builder.instance_eval do define_method name do |*args, &block| # TODO: is builder_class option being used? value = unless attribute_builder block ? block : args.first else attribute_builder.new(&block).build end @config.instance_variable_set(:"@#{attribute}", value) end end define_method attribute do |*args| if instance_variable_defined?(:"@#{attribute}") instance_variable_get(:"@#{attribute}") else [:default] end end public attribute end |