Skip to content

new client from a resource #3#7

Open
0000marcell wants to merge 2 commits intoserradura:masterfrom
0000marcell:master
Open

new client from a resource #3#7
0000marcell wants to merge 2 commits intoserradura:masterfrom
0000marcell:master

Conversation

@0000marcell
Copy link
Copy Markdown

Hi @serradura, learning a lot about functional ruby reading your code, i'm still not sure about the naming question, but i think "map" is just fine, maybe it would be a problem in the future if we wanted to map something else with the client, map the ports for example and create a new client based on the port, what do you think ?

@serradura
Copy link
Copy Markdown
Owner

serradura commented Jan 12, 2018

Thanks, @0000marcell for your contribution! 🎉

I'm glad to see the first feature made by another contributor! 👏

Comment thread lib/request_via/client.rb Outdated

class Client
attr_reader :address, :net_http
attr_accessor :address
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This little change affects the immutability principle because you are mutating the object state.

Look this http://dustinzeisler.com/refactoring/2017/12/11/refactor-towards-immutable-objects-ruby.html article/video to see how do you can achieve the same result keeping an immutable operation.

Comment thread lib/request_via/client.rb Outdated
attr_reader :net_http, :map

Map = -> (client, path) {
client.clone.tap { |c| c.address = BuildURL.(c.address, path) }
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Avoid the usage of a setter, building a new object.

Related to the previous comment.

@0000marcell
Copy link
Copy Markdown
Author

Thx for the feedback and resource, i'm still not sure if that's the best approach, i'm not very familiar with fp, learning as i go, one thing that i've wished we could do is to map by other param, like port or anything else really, using the same Map, does that make sense ? something like

[4200, 3000].map(Request::Client.Map(client, port: port)

I know that this syntax is broken, just trying to communicate the 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.

2 participants