Class: Leadlight::LinkTemplate
- Extended by:
- Forwardable
- Defined in:
- lib/leadlight/link_template.rb
Constant Summary
Constants inherited from Link
Leadlight::Link::HTTP_METHODS, Leadlight::Link::HTTP_METHODS_WITHOUT_BODY, Leadlight::Link::HTTP_METHODS_WITH_BODY
Constants included from Leadlight
Instance Attribute Summary
Attributes inherited from Link
#aliases, #expansion_params, #href, #options, #rel, #rev, #service, #title
Instance Method Summary collapse
Methods inherited from Link
#[], #follow, #initialize, #params, #to_s
Methods included from Leadlight
ParamHash, build_connection_common, build_service, common_connection_stack
Constructor Details
This class inherits a constructor from Leadlight::Link
Instance Method Details
#expand(*args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/leadlight/link_template.rb', line 22 def (*args) return self if args.empty? mapping = args.last.is_a?(Hash) ? args.pop : {} mapping = mapping.inject({}) { |result, (k,v)| result.merge!(k.to_s => v) } mapping = href_template.variables.inject(mapping) do |mapping, var| mapping.merge!(var => args.shift) unless args.empty? mapping end full_mapping = mapping.dup extra_keys = (mapping.keys.map(&:to_s) - href_template.variables) extra_params = extra_keys.inject({}) do |params, key| params[key] = mapping.delete(key) params end assert_all_variables_mapped(href_template, mapping) uri = href_template.(mapping) = (uri, extra_params) Link.new(service, , rel, title, rev: rev, aliases: aliases, expansion_params: full_mapping) end |
#href_template ⇒ Object
11 12 13 |
# File 'lib/leadlight/link_template.rb', line 11 def href_template @href_template ||= Addressable::Template.new(href.to_s) end |