Module: Incoming::Strategy::ClassMethods
- Defined in:
- lib/incoming/strategy.rb
Instance Method Summary collapse
-
#default_options ⇒ Object
Public Returns an inherited set of default options set at the class-level for each strategy.
-
#option(name, value = nil) ⇒ Object
Public: Defines a valid class-level option for strategy.
-
#receive(*args) ⇒ Object
Public: Global receiver.
-
#setup(opts = {}) ⇒ Object
Public: Configures strategy-specific options.
Instance Method Details
#default_options ⇒ Object
Public Returns an inherited set of default options set at the class-level for each strategy.
28 29 30 31 |
# File 'lib/incoming/strategy.rb', line 28 def return @default_options if @default_options @default_options = superclass.respond_to?(:default_options) ? superclass. : {} end |
#option(name, value = nil) ⇒ Object
Public: Defines a valid class-level option for strategy
Examples:
class Incoming::Strategies::MyStrategy
include Incoming::Strategy
option :api_key
option :mime, false
end
Returns nothing
44 45 46 |
# File 'lib/incoming/strategy.rb', line 44 def option(name, value = nil) [name] = value end |
#receive(*args) ⇒ Object
Public: Global receiver
args - Arguments used to initialize strategy. Should be defined
by `initialize` method in strategy class.
Returns nothing
20 21 22 23 |
# File 'lib/incoming/strategy.rb', line 20 def receive(*args) strategy = new(*args) strategy.authenticate and strategy.receive(strategy.) end |
#setup(opts = {}) ⇒ Object
Public: Configures strategy-specific options.
opts - A hash of valid options.
Examples:
class MailReceiver < Incoming::Strategies::MyStrategy
setup api_key: 'asdf', mime: true
end
Returns nothing
59 60 61 62 63 64 65 66 |
# File 'lib/incoming/strategy.rb', line 59 def setup(opts = {}) opts.keys.each do |key| next if .keys.include?(key) raise InvalidOptionError.new(":#{key} is not a valid option for #{self.superclass.name}.") end @default_options = .merge(opts) end |