-
Notifications
You must be signed in to change notification settings - Fork 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
Support for named parameters #4
Open
mapuo
wants to merge
8
commits into
fxposter:master
Choose a base branch
from
mapuo:support-for-named-parameters
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5935d02
api change to support named parameter
9d669f7
refactored to use block for setting options
9f7c32f
rafactored to be as simple as can be
232f0ca
fix when just one non-hash, non-array param is provided
53fc5c5
fix for when the user provides array - we should not extract it
edbda85
make sure that nested params are accepted and processed well
4fb817e
refactor for params type selection from the user
8056246
check for the args.size == 1
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,25 @@ def self.decode_options | |
@decode_options = {} | ||
|
||
class Helper | ||
NAMED = :named | ||
POSITIONAL = :positional | ||
|
||
def initialize(options) | ||
@options = options | ||
@options[:content_type] ||= 'application/json' | ||
@params_type = POSITIONAL | ||
@params_type = NAMED if @options.delete(:named_params) == true | ||
@connection = @options.delete(:connection) | ||
end | ||
|
||
def positional_params? | ||
@params_type == POSITIONAL | ||
end | ||
|
||
def named_params? | ||
@params_type == NAMED | ||
end | ||
|
||
def options(additional_options = nil) | ||
if additional_options | ||
additional_options.merge(@options) | ||
|
@@ -91,7 +104,11 @@ def initialize(url, opts = {}) | |
|
||
def method_missing(sym, *args, &block) | ||
if @alive | ||
request = ::JSONRPC::Request.new(sym.to_s, args) | ||
if @helper.named_params? && args.first.is_a?(::Hash) | ||
request = ::JSONRPC::Request.new(sym.to_s, *args) | ||
else | ||
request = ::JSONRPC::Request.new(sym.to_s, args) | ||
end | ||
push_batch_request(request) | ||
else | ||
super | ||
|
@@ -141,7 +158,11 @@ def send_batch | |
|
||
class Client < Base | ||
def method_missing(method, *args, &block) | ||
invoke(method, args) | ||
if @helper.named_params? && args.first.is_a?(::Hash) | ||
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. Same here. |
||
invoke(method, *args) | ||
else | ||
invoke(method, args) | ||
end | ||
end | ||
|
||
def invoke(method, args, options = nil) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You need to check for the args.size == 1, because it can be [{foo: 'bar'}, 2]