Skip to content
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

Adds accessor settings on instantiation via block or hash. #88

Merged
merged 3 commits into from Mar 10, 2015
Merged

Adds accessor settings on instantiation via block or hash. #88

merged 3 commits into from Mar 10, 2015

Conversation

cdcooksey
Copy link
Collaborator

Changes

Allows Patron::Session to set accessors via constructor hash or block.

Examples:

_via hash_

session = Patron::Session.new({ :timeout => 20,
                            :base_url => 'http://localhost:9000',
                            :headers => {'User-Agent' => 'myapp/1.0'} } )

session.timeout # => 20
session.base_url # => "http://localhost:9000"
session.headers # => {"User-Agent"=>"myapp/1.0"}

_via block_

session = Patron::Session.new do |patron|
  patron.timeout = 20
  patron.base_url = 'http://localhost:9000'
  patron.headers = {'User-Agent' => 'myapp/1.0'}
end

session.timeout # => 20
session.base_url # => "http://localhost:9000"
session.headers # => {"User-Agent"=>"myapp/1.0"}

New tests

rspec spec/session_spec.rb

Fixes .downcase being called on symbols.

Cleaned up

Cleans up hash setter. Adds block support

Adds tests for hash and block instantiation

Undoes string fix for patron/request.rb to keep with scope.
@cdcooksey cdcooksey changed the title Adds instantiation settings via block or hash. Adds accessor settings on instantiation via block or hash. Mar 10, 2015

# Allows accessors to be set via constructor hash. Ex: {:base_url => 'www.home.com'}
args.each do |attribute, value|
self.send("#{attribute}=", value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I suggested it, but you might not even need self here. I might try it without it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, sir. I just tested it. It doesn't need self. Update incoming.

@toland
Copy link
Owner

toland commented Mar 10, 2015

LGTM

toland pushed a commit that referenced this pull request Mar 10, 2015
Adds accessor settings on instantiation via block or hash.
@toland toland merged commit a524d18 into toland:master Mar 10, 2015
@toland
Copy link
Owner

toland commented Mar 10, 2015

@cdcooksey @jschairb I have added both of you as collaborators on the repo.

@cdcooksey
Copy link
Collaborator Author

Thanks!

If the need exists, I can update the README.md to show the new instantiation options.

@cdcooksey cdcooksey deleted the adds_constructor_args branch March 10, 2015 21:19
@toland
Copy link
Owner

toland commented Mar 10, 2015

That sounds like a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants