Class: Nucleus::LinkGenerator
- Inherits:
-
Object
- Object
- Nucleus::LinkGenerator
- Defined in:
- lib/nucleus/core/common/link_generator.rb
Instance Method Summary collapse
-
#api_root ⇒ String
Create a link to the API root node.
-
#initialize(env, api_version) ⇒ LinkGenerator
constructor
A new instance of LinkGenerator.
-
#resource(namespaces, id) ⇒ String
Generate the link that references the resource.
-
#root_url ⇒ Object
Get the root URL of the Nucleus API (scheme + host).
Constructor Details
#initialize(env, api_version) ⇒ LinkGenerator
Returns a new instance of LinkGenerator.
3 4 5 6 |
# File 'lib/nucleus/core/common/link_generator.rb', line 3 def initialize(env, api_version) @env = env @version = api_version end |
Instance Method Details
#api_root ⇒ String
Create a link to the API root node.
25 26 27 |
# File 'lib/nucleus/core/common/link_generator.rb', line 25 def api_root root_url << '/api' end |
#resource(namespaces, id) ⇒ String
Generate the link that references the resource.
12 13 14 15 16 17 18 19 20 |
# File 'lib/nucleus/core/common/link_generator.rb', line 12 def resource(namespaces, id) # resource can only exist for an API version link = api_root # combine namespace and entity ID link << namespace(namespaces) link << "/#{id}" unless id.nil? || id.empty? # return the created link link end |
#root_url ⇒ Object
Get the root URL of the Nucleus API (scheme + host)
30 31 32 |
# File 'lib/nucleus/core/common/link_generator.rb', line 30 def root_url "#{@env['rack.url_scheme']}://#{@env['HTTP_HOST']}" end |