Class: TypedParams::Path
- Inherits:
-
Object
- Object
- TypedParams::Path
- Defined in:
- lib/typed_params/path.rb
Instance Attribute Summary collapse
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
Instance Method Summary collapse
-
#initialize(*keys, casing: TypedParams.config.path_transform) ⇒ Path
constructor
A new instance of Path.
- #inspect ⇒ Object
- #to_dot_notation ⇒ Object
- #to_json_pointer ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(*keys, casing: TypedParams.config.path_transform) ⇒ Path
Returns a new instance of Path.
7 8 9 10 |
# File 'lib/typed_params/path.rb', line 7 def initialize(*keys, casing: TypedParams.config.path_transform) @casing = casing @keys = keys end |
Instance Attribute Details
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
5 6 7 |
# File 'lib/typed_params/path.rb', line 5 def keys @keys end |
Instance Method Details
#inspect ⇒ Object
28 29 30 |
# File 'lib/typed_params/path.rb', line 28 def inspect "#<#{self.class.name}: #{to_s.inspect}>" end |
#to_dot_notation ⇒ Object
13 |
# File 'lib/typed_params/path.rb', line 13 def to_dot_notation = keys.map { transform_key(_1) }.join('.') |
#to_json_pointer ⇒ Object
12 |
# File 'lib/typed_params/path.rb', line 12 def to_json_pointer = '/' + keys.map { transform_key(_1) }.join('/') |
#to_s ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/typed_params/path.rb', line 15 def to_s keys.map { transform_key(_1) }.reduce(+'') do |s, key| next s << key if s.blank? case key when Integer s << "[#{key}]" else s << ".#{key}" end end end |