Module: Dobby::Strategy::ClassMethods
- Defined in:
- lib/dobby/strategy.rb
Overview
Extensible configuration for implementers.
Instance Method Summary collapse
-
#args(args = nil) ⇒ Object
Sets (and retrieves) option key names for initializer arguments to be recorded as.
-
#cli_options ⇒ Object
By default, all args are automatically built out as k/v CLI options.
-
#configure(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 ⇒ Options
An inherited set of default options set at the class-level for each strategy.
-
#option(name, value = nil) ⇒ Object
Directly declare a default option for your class.
Instance Method Details
#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 Dobby Strategies. Dobby::Options will also use this, via #cli_options, to configure any command line options.
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/dobby/strategy.rb', line 97 def args(args = nil) if args @args = Array(args) return end existing = begin superclass.args rescue StandardError [] end (instance_variable_defined?(:@args) && @args) || existing end |
#cli_options ⇒ Object
By default, all args are automatically built out as k/v CLI options. For more advanced behavior, override cli_options in the implementing class. The return of this method is passed directly to Dobby::Options#options
113 114 115 |
# File 'lib/dobby/strategy.rb', line 113 def args.map { |arg| "--#{arg.to_s.tr('_', '-')} VALUE" } end |
#configure(options = nil) {|Options| ... } ⇒ Object
This allows for more declarative subclassing of strategies by allowing default options to be set using a simple configure call.
67 68 69 70 71 72 73 |
# File 'lib/dobby/strategy.rb', line 67 def configure( = nil) if block_given? yield else .deep_merge!() end end |
#default_options ⇒ Options
An inherited set of default options set at the class-level for each strategy.
35 36 37 38 39 40 41 42 |
# File 'lib/dobby/strategy.rb', line 35 def existing = begin superclass. rescue StandardError {} end @default_options ||= Dobby::Strategy::Options.new(existing) 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.
89 90 91 |
# File 'lib/dobby/strategy.rb', line 89 def option(name, value = nil) [name] = value end |