Module: Antrapol::ToolRack::ArgUtils::ClassMethods
- Includes:
- ConditionUtils
- Defined in:
- lib/toolrack/arg_utils.rb
Instance Method Summary collapse
- #aliases ⇒ Object
- #arg_options ⇒ Object
- #arg_spec(&block) ⇒ Object
- #callback(evt, opts = {}, &block) ⇒ Object
- #callbacks ⇒ Object
- #is_all_required_satisfy?(arr) ⇒ Boolean
- #logger ⇒ Object
- #opt(key, desc, opts = {}, &block) ⇒ Object
- #opt_alias(existing, new) ⇒ Object
- #required ⇒ Object
-
#set_value_separator(val) ⇒ Object
def value_separator=(val) logger.debug “Setting value separator #val” @_valSep = val end.
- #value_separator ⇒ Object
Instance Method Details
#aliases ⇒ Object
76 77 78 79 80 81 |
# File 'lib/toolrack/arg_utils.rb', line 76 def aliases if @_aliases.nil? @_aliases = {} end @_aliases end |
#arg_options ⇒ Object
69 70 71 72 73 74 |
# File 'lib/toolrack/arg_utils.rb', line 69 def if @_arg_options.nil? @_arg_options = {} end @_arg_options end |
#arg_spec(&block) ⇒ Object
17 18 19 |
# File 'lib/toolrack/arg_utils.rb', line 17 def arg_spec(&block) class_eval(&block) end |
#callback(evt, opts = {}, &block) ⇒ Object
57 58 59 60 |
# File 'lib/toolrack/arg_utils.rb', line 57 def callback(evt, opts = {}, &block) raise ArgParsingException, "Event should not be nil" if evt.nil? callbacks[evt] = { opts: opts, cb: block } end |
#callbacks ⇒ Object
83 84 85 86 87 88 |
# File 'lib/toolrack/arg_utils.rb', line 83 def callbacks if @_cb.nil? @_cb = {} end @_cb end |
#is_all_required_satisfy?(arr) ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/toolrack/arg_utils.rb', line 35 def is_all_required_satisfy?(arr) if arr.is_a?(Array) res = true required.each do |f| res = arr.include?(f) if not res al = aliases.invert[f] res = arr.include?(al) raise RequiredFieldEmpty, "Required parameter '#{f}' is not given" if not res end end res else raise ArgParsingException, "Given array to check for required fields is not an array. Got #{arr}" if arr.is_a?(ArgParsingException) STDERR.puts "Error throwing into the method was : #{arr.}" end end end |
#logger ⇒ Object
105 106 107 |
# File 'lib/toolrack/arg_utils.rb', line 105 def logger Antrapol::ToolRack.logger(:c_arg_utils) end |
#opt(key, desc, opts = {}, &block) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/toolrack/arg_utils.rb', line 21 def opt(key, desc, opts = {}, &block) raise RequiredFieldEmpty, "Key field cannot be empty" if is_empty?(key) raise DuplicatedField, "Given key '#{key}' already exist" if .keys.include?(key) raise RequiredFieldEmpty, "Block is require" if not block [key] = { key: key, desc: desc, arg_options: opts, callback: block } required << key if opts[:required] == true end |
#opt_alias(existing, new) ⇒ Object
30 31 32 33 |
# File 'lib/toolrack/arg_utils.rb', line 30 def opt_alias(existing, new) raise InvalidKey, "Existing key '#{existing}'to map to new key '#{new}' not found" if not .keys.include?(existing) aliases[new] = existing end |
#required ⇒ Object
62 63 64 65 66 67 |
# File 'lib/toolrack/arg_utils.rb', line 62 def required if @_req.nil? @_req = [] end @_req end |
#set_value_separator(val) ⇒ Object
def value_separator=(val)
logger.debug "Setting value separator #{val}"
@_valSep = val
end
94 95 96 |
# File 'lib/toolrack/arg_utils.rb', line 94 def set_value_separator(val) @_valSep = val end |
#value_separator ⇒ Object
98 99 100 101 102 103 |
# File 'lib/toolrack/arg_utils.rb', line 98 def value_separator if @_valSep.nil? @_valSep = " " end @_valSep end |