Skip to content

Commit a016242

Browse files
committed
WIP: always expand additional link variables, #84.
1 parent fc1f3e6 commit a016242

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

.rubocop_todo.yml

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2015-08-15 17:01:12 -0400 using RuboCop version 0.33.0.
3+
# on 2015-08-15 17:12:38 -0400 using RuboCop version 0.33.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9+
# Offense count: 1
10+
Metrics/AbcSize:
11+
Max: 19
12+
913
# Offense count: 1
1014
# Configuration parameters: CountComments.
1115
Metrics/ClassLength:
@@ -16,10 +20,10 @@ Metrics/ClassLength:
1620
Metrics/LineLength:
1721
Max: 142
1822

19-
# Offense count: 3
23+
# Offense count: 4
2024
# Configuration parameters: CountComments.
2125
Metrics/MethodLength:
22-
Max: 14
26+
Max: 16
2327

2428
# Offense count: 3
2529
# Configuration parameters: CountComments.
@@ -31,21 +35,23 @@ Style/AsciiComments:
3135
Exclude:
3236
- 'lib/hyperclient/collection.rb'
3337

34-
# Offense count: 2
38+
# Offense count: 3
3539
# Configuration parameters: EnforcedStyle, SupportedStyles.
3640
Style/ClassAndModuleChildren:
3741
Exclude:
3842
- 'features/steps/api_navigation.rb'
3943
- 'features/steps/default_config.rb'
44+
- 'lib/uri_template/rfc6570/expression.rb'
4045

41-
# Offense count: 14
46+
# Offense count: 15
4247
Style/Documentation:
4348
Exclude:
4449
- 'features/steps/api_navigation.rb'
4550
- 'features/steps/default_config.rb'
4651
- 'features/support/api.rb'
4752
- 'features/support/fixtures.rb'
4853
- 'lib/hyperclient/version.rb'
54+
- 'lib/uri_template/rfc6570/expression.rb'
4955
- 'test/faraday/connection_test.rb'
5056
- 'test/hyperclient/attributes_test.rb'
5157
- 'test/hyperclient/collection_test.rb'

lib/hyperclient/link.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'hyperclient/resource'
22
require 'uri_template'
33
require 'futuroscope'
4+
require_relative '../uri_template/rfc6570/expression'
45

56
module Hyperclient
67
# Internal: The Link is used to let a Resource interact with the API.
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'uri_template/rfc6570/expression'
2+
3+
class URITemplate::RFC6570
4+
class Expression < Token
5+
def expand(vars)
6+
unused_vars = vars.keys.dup
7+
result = []
8+
@variable_specs.each do |var, expand, max_length|
9+
if Utils.def?(vars[var])
10+
result.push(*expand_one(var, vars[var], expand, max_length))
11+
end
12+
unused_vars.delete(var)
13+
end
14+
unused_vars.each do |k|
15+
result.push(*expand_one(k, vars[k], false, 0))
16+
end
17+
if result.any?
18+
return (self.class::PREFIX + result.join(self.class::SEPARATOR))
19+
else
20+
return ''
21+
end
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)