Skip to content

Commit

Permalink
WIP: always expand additional link variables, codegram#84.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Aug 15, 2015
1 parent fbe7ba7 commit 0345d4d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/hyperclient/link.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'hyperclient/resource'
require 'uri_template'
require 'futuroscope'
require_relative '../uri_template/rfc6570/expression'

module Hyperclient
# Internal: The Link is used to let a Resource interact with the API.
Expand Down
24 changes: 24 additions & 0 deletions lib/uri_template/rfc6570/expression.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'uri_template/rfc6570/expression'

class URITemplate::RFC6570
class Expression < Token
def expand(vars)
unused_vars = vars.keys.dup
result = []
@variable_specs.each do |var, expand, max_length|
if Utils.def?(vars[var])
result.push(*expand_one(var, vars[var], expand, max_length))
end
unused_vars.delete(var)
end
unused_vars.each do |k|
result.push(*expand_one(k, vars[k], false, 0))
end
if result.any?
return (self.class::PREFIX + result.join(self.class::SEPARATOR))
else
return ''
end
end
end
end

0 comments on commit 0345d4d

Please sign in to comment.