Module: OmniHooks::Strategy
- Included in:
- OmniHooks::Strategies::Developer
- Defined in:
- lib/omnihooks/strategy.rb
Overview
The Strategy is the base unit of OmniHooks’s ability to wrangle multiple providers. Each strategy provided by OmniHooks includes this mixin to gain the default functionality necessary to be compatible with the OmniHooks library.
Defined Under Namespace
Modules: ClassMethods Classes: Namespace, NotificationAdapter, Options
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.included(base) ⇒ Object
rubocop:disable ModuleLength.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Duplicates this instance and runs #call! on it.
-
#call!(env) ⇒ Object
The logic for dispatching any additional actions that need to be taken.
-
#initialize(app, *args) {|Class, Options| ... } ⇒ Object
Initializes the strategy by passing in the Rack endpoint, the unique URL segment name for this strategy, and any additional arguments.
- #inspect ⇒ Object
- #request ⇒ Object
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
173 174 175 |
# File 'lib/omnihooks/strategy.rb', line 173 def @options end |
Class Method Details
.included(base) ⇒ Object
rubocop:disable ModuleLength
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/omnihooks/strategy.rb', line 9 def self.included(base) OmniHooks.strategies << base base.extend ClassMethods base.class_eval do option :backend, ActiveSupport::Notifications option :adapter, OmniHooks::Strategy::NotificationAdapter option :namespace_delimiter, '.' end end |
Instance Method Details
#call(env) ⇒ Object
Duplicates this instance and runs #call! on it.
214 215 216 |
# File 'lib/omnihooks/strategy.rb', line 214 def call(env) dup.call!(env) end |
#call!(env) ⇒ Object
The logic for dispatching any additional actions that need to be taken. For instance, calling the request phase if the request path is recognized.
222 223 224 225 226 227 |
# File 'lib/omnihooks/strategy.rb', line 222 def call!(env) # rubocop:disable CyclomaticComplexity, PerceivedComplexity @env = env return instrument if on_request_path? && OmniHooks.config.allowed_request_methods.include?(request.request_method.downcase.to_sym) @app.call(env) end |
#new(app, options = {}) ⇒ Object #new(app, *args, options = {}) ⇒ Object
Initializes the strategy by passing in the Rack endpoint, the unique URL segment name for this strategy, and any additional arguments. An ‘options` hash is automatically created from the last argument if it is a hash.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/omnihooks/strategy.rb', line 190 def initialize(app, *args, &block) # rubocop:disable UnusedMethodArgument @app = app @env = nil @options = self.class..dup .deep_merge!(args.pop) if args.last.is_a?(Hash) self.class.args.each do |arg| break if args.empty? [arg] = args.shift end # Make sure that all of the args have been dealt with, otherwise error out. fail(ArgumentError.new("Received wrong number of arguments. #{args.inspect}")) unless args.empty? yield self.class, if block_given? end |
#inspect ⇒ Object
208 209 210 |
# File 'lib/omnihooks/strategy.rb', line 208 def inspect "#<#{self.class}>" end |
#request ⇒ Object
229 230 231 |
# File 'lib/omnihooks/strategy.rb', line 229 def request @request ||= Rack::Request.new(@env) end |