Class: Optioning
- Inherits:
-
Object
- Object
- Optioning
- Defined in:
- lib/optioning.rb,
lib/optioning/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Method Summary collapse
-
#deprecate(option, replacement, version_or_year = nil, month = nil) ⇒ Optioning
Creates a deprecation for an option, stores info about it’s replacement and time or version to its removal.
-
#deprecation_warn(called_from = nil) ⇒ Optioning
Issues all deprecation messages to the $stderr.
-
#initialize(args) ⇒ Optioning
constructor
Receives a varargs to extract the values (anything before a last parameter ‘Hash`) and the options (last parameter instance_of `Hash`).
-
#on(option) ⇒ Object
Return the value for a specific option.
-
#process(called_from = nil) ⇒ Optioning
Issues the deprecation warnings and the unrecognized warnings.
-
#raw ⇒ Array
Return all values passed as varargs to the constructor.
-
#recognize(*options) ⇒ Optioning
Provides a way to inform which options can be used and which will be ignored by an instance of Optioning.
-
#unrecognized_warn(called_from = nil) ⇒ Optioning
Issues all unrecognized messages and the recognized_options message to the $stderr.
-
#values ⇒ Array
Return all the values passed before the last one (if this one is a ‘Hash` instance).
Constructor Details
#initialize(args) ⇒ Optioning
19 20 21 22 23 |
# File 'lib/optioning.rb', line 19 def initialize(args) @args = args @values = @args.dup @options = @values.pop.dup if @args.last.is_a? Hash end |
Instance Method Details
#deprecate(option, replacement, version_or_year = nil, month = nil) ⇒ Optioning
Creates a deprecation for an option, stores info about it’s replacement and time or version to its removal.
52 53 54 55 56 |
# File 'lib/optioning.rb', line 52 def deprecate(option, replacement, version_or_year = nil, month = nil) deprecations << Deprecation.new(option, replacement, version_or_year, month) recognize(replacement) self end |
#deprecation_warn(called_from = nil) ⇒ Optioning
Issues all deprecation messages to the $stderr
77 78 79 80 81 82 83 |
# File 'lib/optioning.rb', line 77 def deprecation_warn(called_from = nil) set_caller_on_deprecations(called_from) deprecations.select { |deprecation| deprecated_but_used.include? deprecation.option }.each { |deprecation| $stderr.write deprecation.warn } self end |
#on(option) ⇒ Object
Return the value for a specific option
34 35 36 37 |
# File 'lib/optioning.rb', line 34 def on(option) replace_deprecations .fetch option, nil end |
#process(called_from = nil) ⇒ Optioning
Issues the deprecation warnings and the unrecognized warnings. Let the current Optioning in a ‘ready to use` state.
102 103 104 105 106 |
# File 'lib/optioning.rb', line 102 def process(called_from = nil) deprecation_warn called_from unrecognized_warn called_from self end |
#raw ⇒ Array
Return all values passed as varargs to the constructor.
111 112 113 |
# File 'lib/optioning.rb', line 111 def raw @args end |
#recognize(*options) ⇒ Optioning
Provides a way to inform which options can be used and which will be ignored by an instance of Optioning
67 68 69 70 71 |
# File 'lib/optioning.rb', line 67 def recognize(*) @recognized ||= [] @recognized += self end |
#unrecognized_warn(called_from = nil) ⇒ Optioning
Issues all unrecognized messages and the recognized_options message to the $stderr
89 90 91 92 93 94 95 |
# File 'lib/optioning.rb', line 89 def unrecognized_warn(called_from = nil) .each do |unrecognized| $stderr.write "NOTE: unrecognized option `:#{unrecognized}` used.\n" end (called_from) if .count > 0 self end |
#values ⇒ Array
Return all the values passed before the last one (if this one is a ‘Hash` instance).
119 120 121 |
# File 'lib/optioning.rb', line 119 def values @values end |