Module: DDSL::Functions
- Extended by:
- Transproc::Registry
- Defined in:
- lib/ddsl/functions.rb
Class Method Summary collapse
- .expand_options(hash) ⇒ Object
- .idempotency(value) ⇒ Object
- .map_keys_matching(hash, regex, func) ⇒ Object
- .optionize_keys(hash) ⇒ Object
Class Method Details
.expand_options(hash) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ddsl/functions.rb', line 36 def self.(hash) hash.map do |key, value| case value when String [key, value] when TrueClass, FalseClass key when Array value.map { |v| [key, v] } when Hash value.map { |sub_key, v| [key, "#{sub_key}=#{v}"] } end end.flatten end |
.idempotency(value) ⇒ Object
12 13 14 |
# File 'lib/ddsl/functions.rb', line 12 def self.idempotency(value) value end |
.map_keys_matching(hash, regex, func) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/ddsl/functions.rb', line 16 def self.map_keys_matching(hash, regex, func) hash.map do |key, value| if regex&.match(key) [func.call(key), value] else [key, value] end end.to_h end |
.optionize_keys(hash) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/ddsl/functions.rb', line 26 def self.optionize_keys(hash) [ [:map_keys_matching, /\w+_\w+/, ->(x) { x.tr('_', '-') }], [:map_keys_matching, /^.{2,}$/, ->(x) { '--' + x }], [:map_keys_matching, /^.{1}$/, ->(x) { '-' + x }] ].inject(Functions[:idempotency]) do |pipe, args| pipe >> Functions[*args] end.call(hash) end |