Module: OmniHooks::Strategy::ClassMethods
- Defined in:
- lib/omnihooks/strategy.rb
Instance Attribute Summary collapse
-
#namespace ⇒ Object
writeonly
Sets the attribute namespace.
Instance Method Summary collapse
- #all(callable = Proc.new) ⇒ Object
-
#args(args = nil) ⇒ Object
Sets (and retrieves) option key names for initializer arguments to be recorded as.
- #configure(&block) ⇒ Object (also: #setup)
-
#configure_options(options = nil) {|Options| ... } ⇒ Object
This allows for more declarative subclassing of strategies by allowing default options to be set using a simple configure call.
-
#default_options ⇒ Object
Returns an inherited set of default options set at the class-level for each strategy.
- #instrument(event_type, event_object) ⇒ Object
- #listening?(name) ⇒ Boolean
-
#option(name, value = nil) ⇒ Object
Directly declare a default option for your class.
- #subscribe(name, callable = Proc.new) ⇒ Object
Instance Attribute Details
#namespace=(value) ⇒ Object
Sets the attribute namespace
21 22 23 |
# File 'lib/omnihooks/strategy.rb', line 21 def namespace=(value) @namespace = value end |
Instance Method Details
#all(callable = Proc.new) ⇒ Object
100 101 102 |
# File 'lib/omnihooks/strategy.rb', line 100 def all(callable = Proc.new) backend.subscribe(nil, callable) end |
#args(args = nil) ⇒ Object
Sets (and retrieves) option key names for initializer arguments to be recorded as. This takes care of 90% of the use cases for overriding the initializer in OmniAuth Strategies.
52 53 54 55 56 57 58 59 |
# File 'lib/omnihooks/strategy.rb', line 52 def args(args = nil) if args @args = Array(args) return end existing = superclass.respond_to?(:args) ? superclass.args : [] (instance_variable_defined?(:@args) && @args) || existing end |
#configure(&block) ⇒ Object Also known as: setup
90 91 92 93 |
# File 'lib/omnihooks/strategy.rb', line 90 def configure(&block) raise ArgumentError, "must provide a block" unless block_given? block.arity.zero? ? instance_eval(&block) : yield(self) end |
#configure_options(options = nil) {|Options| ... } ⇒ Object
This allows for more declarative subclassing of strategies by allowing default options to be set using a simple configure call.
82 83 84 85 86 87 88 |
# File 'lib/omnihooks/strategy.rb', line 82 def ( = nil) if block_given? yield else .deep_merge!() end end |
#default_options ⇒ Object
Returns an inherited set of default options set at the class-level for each strategy.
24 25 26 27 28 |
# File 'lib/omnihooks/strategy.rb', line 24 def return @default_options if instance_variable_defined?(:@default_options) && @default_options existing = superclass.respond_to?(:default_options) ? superclass. : {} @default_options = OmniHooks::Strategy::Options.new(existing) end |
#instrument(event_type, event_object) ⇒ Object
123 124 125 |
# File 'lib/omnihooks/strategy.rb', line 123 def instrument(event_type, event_object) backend.instrument(namespace.call(event_type), event_object) end |
#listening?(name) ⇒ Boolean
104 105 106 107 |
# File 'lib/omnihooks/strategy.rb', line 104 def listening?(name) namespaced_name = namespace.call(name) backend.notifier.listening?(namespaced_name) end |
#option(name, value = nil) ⇒ Object
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.
45 46 47 |
# File 'lib/omnihooks/strategy.rb', line 45 def option(name, value = nil) [name] = value end |
#subscribe(name, callable = Proc.new) ⇒ Object
96 97 98 |
# File 'lib/omnihooks/strategy.rb', line 96 def subscribe(name, callable = Proc.new) backend.subscribe(namespace.to_regexp(name), adapter.call(callable)) end |