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

Minor fixes to example docs #547

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,23 +270,23 @@ SEMIAN_PARAMETERS = {
dynamic: true,
}

class CurrentSemianSubResource < ActiveSupport::Attributes
attribute :name
class CurrentSemianSubResource < ActiveSupport::CurrentAttributes
attribute :sub_name
end

Semian::NetHTTP.semian_configuration = proc do |host, port|
name = "#{host}_#{port}"
if (sub_resource_name = CurrentSemianSubResource.name)
name << "_#{name}"
if (sub_resource_name = CurrentSemianSubResource.sub_name)
name << "_#{sub_resource_name}"
end
SEMIAN_PARAMETERS.merge(name: name)
end

# Two requests to example.com can use two different semian resources,
# as long as `CurrentSemianSubResource.name` is set accordingly:
# CurrentSemianSubResource.set(name: "sub_resource_1") { Net::HTTP.get_response(URI("http://example.com")) }
# as long as `CurrentSemianSubResource.sub_name` is set accordingly:
# CurrentSemianSubResource.set(sub_name: "sub_resource_1") { Net::HTTP.get_response(URI("http://example.com")) }
# and:
# CurrentSemianSubResource.set(name: "sub_resource_2") { Net::HTTP.get_response(URI("http://example.com")) }
# CurrentSemianSubResource.set(sub_name: "sub_resource_2") { Net::HTTP.get_response(URI("http://example.com")) }
```

For most purposes, `"#{host}_#{port}"` is a good default `name`. Custom `name` formats
Expand Down
Loading