Skip to content

Commit

Permalink
Merge pull request #547 from Shopify/bostonaholic/fix-dynamic-example
Browse files Browse the repository at this point in the history
Minor fixes to example docs
  • Loading branch information
bostonaholic authored Aug 29, 2024
2 parents 333fbca + cb73050 commit d7c89d2
Showing 1 changed file with 7 additions and 7 deletions.
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

0 comments on commit d7c89d2

Please sign in to comment.