Module: PoliPage::Internal::Wire Private
- Defined in:
- lib/poli_page/internal/wire.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
snake_case ↔ camelCase translator (sdk-ruby-plan.md §5.4). Pure, no runtime dependency on metaprogramming DSLs. Outgoing: hash keys are stringified and camelized. Incoming: hash keys are snake_cased and symbolized.
Class Method Summary collapse
- .camel_to_snake(str) ⇒ Object private
- .from_wire(value) ⇒ Object private
- .snake_to_camel(str) ⇒ Object private
- .to_wire(value) ⇒ Object private
Class Method Details
.camel_to_snake(str) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 |
# File 'lib/poli_page/internal/wire.rb', line 44 def camel_to_snake(str) str.gsub(/([A-Z])/, '_\1').downcase end |
.from_wire(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/poli_page/internal/wire.rb', line 27 def from_wire(value) case value when Hash value.each_with_object({}) do |(k, v), h| h[camel_to_snake(k.to_s).to_sym] = from_wire(v) end when Array value.map { |v| from_wire(v) } else value end end |
.snake_to_camel(str) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 |
# File 'lib/poli_page/internal/wire.rb', line 40 def snake_to_camel(str) str.gsub(/_([a-z])/) { Regexp.last_match(1).upcase } end |
.to_wire(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/poli_page/internal/wire.rb', line 14 def to_wire(value) case value when Hash value.each_with_object({}) do |(k, v), h| h[snake_to_camel(k.to_s)] = to_wire(v) end when Array value.map { |v| to_wire(v) } else value end end |