Class: EverydayCliUtils::OptionTypes
- Defined in:
- lib/everyday-cli-utils/option.rb
Class Method Summary collapse
-
.def_option_type ⇒ Object
endregion.
-
.def_option_with_param_type ⇒ Object
endregion.
- .def_type(type, default_value_block, value_determine_block, name_mod_block = nil, value_transform_block = nil) ⇒ Object
- .default_value(type, settings = {}) ⇒ Object
- .mod_names(type, names, settings = {}) ⇒ Object
-
.option_default(_) ⇒ Object
region option procs.
- .option_name_mod(names, settings) ⇒ Object
- .option_value_determine(current_value, new_value, settings) ⇒ Object
- .option_value_transform(new_value, _) ⇒ Object
-
.param_option_default(settings) ⇒ Object
region option_with_param procs.
- .param_option_name_mod(names, settings) ⇒ Object
- .param_option_value_determine(current_value, new_value, settings) ⇒ Object
- .param_option_value_transform(new_value, settings) ⇒ Object
- .updated_value(type, current_value, new_value, settings = {}) ⇒ Object
Class Method Details
.def_option_type ⇒ Object
endregion
91 92 93 94 95 96 97 |
# File 'lib/everyday-cli-utils/option.rb', line 91 def def_option_type def_type(:option, method(:option_default), method(:option_value_determine), method(:option_name_mod), method(:option_value_transform)) end |
.def_option_with_param_type ⇒ Object
endregion
120 121 122 123 124 125 126 |
# File 'lib/everyday-cli-utils/option.rb', line 120 def def_option_with_param_type def_type(:option_with_param, method(:param_option_default), method(:param_option_value_determine), method(:param_option_name_mod), method(:param_option_value_transform)) end |
.def_type(type, default_value_block, value_determine_block, name_mod_block = nil, value_transform_block = nil) ⇒ Object
52 53 54 55 |
# File 'lib/everyday-cli-utils/option.rb', line 52 def def_type(type, default_value_block, value_determine_block, name_mod_block = nil, value_transform_block = nil) @types ||= {} @types[type] = OptionType.new(default_value_block, value_determine_block, name_mod_block, value_transform_block) end |
.default_value(type, settings = {}) ⇒ Object
57 58 59 60 |
# File 'lib/everyday-cli-utils/option.rb', line 57 def default_value(type, settings = {}) @types ||= {} @types.has_key?(type) ? @types[type].default_value(settings) : nil end |
.mod_names(type, names, settings = {}) ⇒ Object
67 68 69 70 |
# File 'lib/everyday-cli-utils/option.rb', line 67 def mod_names(type, names, settings = {}) @types ||= {} @types.has_key?(type) ? @types[type].mod_names(names, settings) : names end |
.option_default(_) ⇒ Object
region option procs
73 74 75 |
# File 'lib/everyday-cli-utils/option.rb', line 73 def option_default(_) false end |
.option_name_mod(names, settings) ⇒ Object
81 82 83 |
# File 'lib/everyday-cli-utils/option.rb', line 81 def option_name_mod(names, settings) settings.has_key?(:desc) ? (names + [settings[:desc]]) : names end |
.option_value_determine(current_value, new_value, settings) ⇒ Object
77 78 79 |
# File 'lib/everyday-cli-utils/option.rb', line 77 def option_value_determine(current_value, new_value, settings) new_value ? (!settings[:toggle] || !current_value) : current_value end |
.option_value_transform(new_value, _) ⇒ Object
85 86 87 |
# File 'lib/everyday-cli-utils/option.rb', line 85 def option_value_transform(new_value, _) !(!new_value) end |
.param_option_default(settings) ⇒ Object
region option_with_param procs
100 101 102 |
# File 'lib/everyday-cli-utils/option.rb', line 100 def param_option_default(settings) settings[:append] ? [] : nil end |
.param_option_name_mod(names, settings) ⇒ Object
108 109 110 111 112 |
# File 'lib/everyday-cli-utils/option.rb', line 108 def param_option_name_mod(names, settings) names[0] << ' PARAM' unless names.any? { |v| v.include?(' ') } names = settings.has_key?(:desc) ? (names + [settings[:desc]]) : names settings.has_key?(:type) ? (names + [settings[:type]]) : names end |
.param_option_value_determine(current_value, new_value, settings) ⇒ Object
104 105 106 |
# File 'lib/everyday-cli-utils/option.rb', line 104 def param_option_value_determine(current_value, new_value, settings) settings[:append] ? (current_value + new_value) : ((new_value.nil? || new_value == '') ? current_value : new_value) end |
.param_option_value_transform(new_value, settings) ⇒ Object
114 115 116 |
# File 'lib/everyday-cli-utils/option.rb', line 114 def param_option_value_transform(new_value, settings) new_value.is_a?(Array) ? (settings[:append] ? new_value : new_value[0]) : (settings[:append] ? [new_value] : new_value) end |
.updated_value(type, current_value, new_value, settings = {}) ⇒ Object
62 63 64 65 |
# File 'lib/everyday-cli-utils/option.rb', line 62 def updated_value(type, current_value, new_value, settings = {}) @types ||= {} @types.has_key?(type) ? @types[type].updated_value(current_value, new_value, settings) : current_value end |