@@ -7,6 +7,7 @@ class EndpointProviderClass < View
7
7
# @option options [required, Service] :service
8
8
# @option options [required, Hash] :endpoint_rules
9
9
def initialize ( options )
10
+ @assigned_variables = [ ]
10
11
@service = options . fetch ( :service )
11
12
@endpoint_rules = @service . endpoint_rules
12
13
# Used to collect metrics in the generated endpoint provider
@@ -33,10 +34,6 @@ def module_name
33
34
34
35
def endpoint_rules_code
35
36
res = StringIO . new
36
- # map parameters first
37
- @endpoint_rules [ "parameters" ] . each do |k , _v |
38
- res << indent ( "#{ underscore ( k ) } = parameters.#{ underscore ( k ) } \n " , 3 )
39
- end
40
37
41
38
# map rules
42
39
@endpoint_rules [ "rules" ] . each do |rule |
@@ -164,6 +161,7 @@ def conditions(conditions, level)
164
161
165
162
def condition ( condition )
166
163
if condition [ 'assign' ]
164
+ @assigned_variables << condition [ 'assign' ]
167
165
"(#{ underscore ( condition [ 'assign' ] ) } = #{ fn ( condition ) } )"
168
166
else
169
167
fn ( condition )
@@ -173,7 +171,11 @@ def condition(condition)
173
171
def str ( s )
174
172
if s . is_a? ( Hash )
175
173
if s [ 'ref' ]
176
- underscore ( s [ 'ref' ] )
174
+ if @assigned_variables . include? ( s [ 'ref' ] )
175
+ underscore ( s [ 'ref' ] )
176
+ else
177
+ "parameters.#{ underscore ( s [ 'ref' ] ) } "
178
+ end
177
179
elsif s [ 'fn' ]
178
180
fn ( s )
179
181
else
@@ -195,7 +197,12 @@ def template_str(string, wrap=true)
195
197
196
198
def template_replace ( value )
197
199
indexes = value . split ( "#" )
198
- res = underscore ( indexes . shift )
200
+ variable = indexes . shift
201
+ res = if @assigned_variables . include? ( variable )
202
+ underscore ( variable )
203
+ else
204
+ "parameters.#{ underscore ( variable ) } "
205
+ end
199
206
res += indexes . map do |index |
200
207
"['#{ index } ']"
201
208
end . join ( "" )
@@ -210,7 +217,11 @@ def fn(fn)
210
217
def fn_arg ( arg )
211
218
if arg . is_a? ( Hash )
212
219
if arg [ 'ref' ]
213
- underscore ( arg [ 'ref' ] )
220
+ if @assigned_variables . include? ( arg [ 'ref' ] )
221
+ underscore ( arg [ 'ref' ] )
222
+ else
223
+ "parameters.#{ underscore ( arg [ 'ref' ] ) } "
224
+ end
214
225
elsif arg [ 'fn' ]
215
226
fn ( arg )
216
227
else
0 commit comments