class Nucleus::LinkGenerator
Public Class Methods
new(env, api_version)
click to toggle source
# File lib/nucleus/core/common/link_generator.rb, line 3 def initialize(env, api_version) @env = env @version = api_version end
Public Instance Methods
api_root()
click to toggle source
Create a link to the API root node.
@return [String] link to the API root
# File lib/nucleus/core/common/link_generator.rb, line 25 def api_root root_url << '/api' end
resource(namespaces, id)
click to toggle source
Generate the link that references the resource. @param [Array<String>] namespaces nested namespaces that must be joined to access the resource @param [String] id id of the resource @return [String] URL to the resource
# 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()
click to toggle source
Get the root URL of the Nucleus
API (scheme + host)
# File lib/nucleus/core/common/link_generator.rb, line 30 def root_url "#{@env['rack.url_scheme']}://#{@env['HTTP_HOST']}" end
Private Instance Methods
namespace(namespaces)
click to toggle source
# File lib/nucleus/core/common/link_generator.rb, line 36 def namespace(namespaces) if namespaces.is_a?(String) && !namespaces.empty? "/#{namespaces}" elsif !namespaces.nil? && !namespaces.empty? "/#{namespaces.join('/')}" else '' end end