-
Notifications
You must be signed in to change notification settings - Fork 0
[PDE-3241] accept dot notation #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f85db58
15b431c
7f737b2
e00c74c
5e4d80a
5ce0f1f
cf16645
22b4f17
5a148b1
a27bc70
73e1fcf
b8bb76b
e45b8a7
61e2cc8
7b3ba67
74f7ac1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| PATH | ||
| remote: . | ||
| specs: | ||
| payrix (1.0.0) | ||
| payrix (1.1.0) | ||
| faraday (~> 2.0.1) | ||
| faraday-follow_redirects | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,22 +22,31 @@ def initialize(field, operator, value) | |
| def construct(prefix = '') | ||
| raise ArgumentError, 'Prefix parameter must be a string' unless prefix.is_a?(String) | ||
|
|
||
| field = Payrix::Util.camel_case(@field.to_s) | ||
| formatted_field = rendered_field(prefix) | ||
|
|
||
| if prefix == '' | ||
| "#{field}[#{@operator}]=#{@value}" | ||
| if prefix.empty? | ||
| "#{formatted_field}[#{@operator}]=#{@value}" | ||
| elsif formatted_field.start_with?('[') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this branch for?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so the dot notation field will be formatted to something like |
||
| "#{prefix}#{formatted_field}[#{@operator}]=#{@value}" | ||
| else | ||
| "#{prefix}[#{field}][#{@operator}]=#{@value}" | ||
| "#{prefix}[#{formatted_field}][#{@operator}]=#{@value}" | ||
| end | ||
|
jazziining marked this conversation as resolved.
|
||
| end | ||
|
|
||
| private | ||
|
|
||
| def validate_field | ||
| return if @field.is_a?(Symbol) | ||
| return if @field.is_a?(String) && @field != '' | ||
| raise ArgumentError, 'Field parameter must be a symbol or a non-empty string' unless valid_string_field? | ||
| raise ArgumentError, 'Field parameter must not contain empty dot notation segments' if empty_dot_segment? | ||
| end | ||
|
|
||
| def valid_string_field? | ||
| @field.is_a?(String) && @field != '' | ||
| end | ||
|
|
||
| raise ArgumentError, 'Field parameter must be a symbol or a non-empty string' | ||
| def empty_dot_segment? | ||
| @field.include?('.') && @field.split('.').any?(&:empty?) | ||
| end | ||
|
|
||
| def validate_operator | ||
|
|
@@ -52,6 +61,20 @@ def validate_value | |
|
|
||
| raise ArgumentError, 'Value parameter must be a non-empty string' | ||
| end | ||
|
|
||
| def rendered_field(prefix) | ||
| return Payrix::Util.camel_case(@field.to_s) unless @field.is_a?(String) && @field.include?('.') | ||
|
|
||
| dot_field(prefix.empty?) | ||
| end | ||
|
|
||
| def dot_field(unprefixed) | ||
| parts = @field.split('.').map { |part| Payrix::Util.camel_case(part) } | ||
|
|
||
| return parts.map { |part| "[#{part}]" }.join unless unprefixed | ||
|
|
||
| [parts.first, *parts.drop(1).map { |part| "[#{part}]" }].join | ||
| end | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original implementation always wrapped the key with an [], which could lead to double-wrapping when the field was already partially formatted. The goal of this change is to treat string inputs using dot notation (e.g. "merchant.entity.login.division") as a structured field path. These strings are parsed into an array of segments and then consistently formatted into the expected bracketed query structure. This ensures:
|
||
| end | ||
| end | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Payrix | ||
| VERSION = '1.0.0' | ||
| VERSION = '1.1.0' | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not approve of this. LOL.