Module: Dobby::Strategy Abstract
- Defined in:
- lib/dobby/strategy.rb
Overview
Include as a mixin to implement a Strategy compatible with the library
The Strategy provides base functionality for defining how Dobby takes in the data it needs to do its job. Each strategy should include this mixin to ensure compatibility with the rest of the library.
In particular, the mixin provides a DSL for configuring strategies and standardizes some strategy behavior (such as #inspect).
Much of this borrowed from Omniauth::Strategy https://github.com/omniauth/omniauth/blob/master/lib/omniauth/strategy.rb
Defined Under Namespace
Modules: ClassMethods Classes: Options
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) {|Options| ... } ⇒ Object
Initialize the strategy, creating an [Options] hash if the last argument is a Hash.
- #inspect ⇒ String
-
#log(level, message) ⇒ Object
Access to the Dobby logger, automatically prefixed with the strategy's name.
-
#setup ⇒ Object
Callback placeholder so that 'super' during initialize is unnecessary in implementing classes.
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
118 119 120 |
# File 'lib/dobby/strategy.rb', line 118 def @options end |
Class Method Details
.included(base) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/dobby/strategy.rb', line 19 def self.included(base) Dobby.strategies << base base.extend ClassMethods base.class_eval do option :setup, false option :test_mode, false end end |
Instance Method Details
#initialize(*args) {|Options| ... } ⇒ Object
Initialize the strategy, creating an [Options] hash if the last argument is a Hash.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/dobby/strategy.rb', line 126 def initialize(*args) @options = self.class..dup .deep_merge!(args.pop) if args.last.is_a?(Hash) [:name] ||= self.class.to_s.split('::').last.downcase self.class.args.each do |arg| break if args.empty? [arg] = args.shift end raise ArgumentError, "Received too many arguments. #{args.inspect}" unless args.empty? setup yield if block_given? end |
#inspect ⇒ String
150 151 152 |
# File 'lib/dobby/strategy.rb', line 150 def inspect "#<#{self.class}>" end |
#log(level, message) ⇒ Object
Access to the Dobby logger, automatically prefixed with the strategy's name.
164 165 166 |
# File 'lib/dobby/strategy.rb', line 164 def log(level, ) Dobby.logger.send(level, "(#{self.class.name}) #{}") end |
#setup ⇒ Object
Callback placeholder so that 'super' during initialize is unnecessary in implementing classes. This is the other 10% of the use case for overriding initialize.
147 |
# File 'lib/dobby/strategy.rb', line 147 def setup; end |