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
- #+(other) ⇒ Object
-
#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
#+(other) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/typed_params/path.rb', line 15 def +(other) raise ArgumentError, 'must be a Path object or nil' unless other in Path | nil return self if other.nil? Path.new(*keys, *other.keys, casing:) end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/typed_params/path.rb', line 36 def inspect "#<#{self.class.name}: #{to_s.inspect} keys=#{keys.inspect} casing=#{casing.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
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/typed_params/path.rb', line 24 def to_s keys.map { transform_key(_1) }.reduce(+'') do |s, key| case key when Integer s << "[#{key}]" else s << '.' unless s.blank? s << key.to_s end end end |