@@ -111,25 +111,27 @@ def parse_compare_key
111111 if ( match_values = OPERATION . match ( key ) )
112112 @compare_key = key
113113 @type , operator , @path = match_values . captures
114- @operation = "op_#{ operator . downcase } ?" . to_sym
114+ @operation = : "op_#{ operator . downcase } ?"
115115 @compare_predicate = parse_predicate ( type )
116116 break
117- end
118117 # e.g. (Is)(String)
119- if ( match_value = TYPE_CHECK . match ( key ) )
118+ elsif ( match_value = TYPE_CHECK . match ( key ) )
120119 @compare_key = key
121120 _operator , type = match_value . captures
122121 # type: nil means no runtime type checking.
123122 @type = @path = nil
124- @operation = "is_#{ type . downcase } ?" . to_sym
123+ @operation = : "is_#{ type . downcase } ?"
125124 @compare_predicate = parse_predicate ( "Boolean" )
126125 break
127126 end
128127 end
129128 parser_error! ( "requires a compare key" ) if compare_key . nil? || operation . nil?
130129 end
131130
132- # parse predicate at initilization time
131+ # parse predicate at initialization time
132+ # @param data_type [String] the data type of the variable
133+ # When parsing operations (IntegerGreaterThan), this will be the operation data type (e.g.: Integer)
134+ # When parsing type checks (IsString), this will always be a Boolean
133135 # @return the right predicate attached to the compare key
134136 def parse_predicate ( data_type )
135137 path ? parse_path ( compare_key ) : parse_field ( compare_key , data_type )
@@ -140,13 +142,13 @@ def compare_value(context, input)
140142 path ? fetch_path ( compare_key , compare_predicate , context , input ) : compare_predicate
141143 end
142144
143- # feth the variable value at runtime
144- # @return variable value (left hand side )
145+ # fetch the variable value at runtime
146+ # @return variable value (left hand side)
145147 def variable_value ( context , input )
146148 fetch_path ( "Variable" , variable , context , input )
147149 end
148150
149- # parse path at initilization time
151+ # parse path at initialization time
150152 # helper method to parse a path from the payload
151153 def parse_path ( field_name )
152154 value = payload [ field_name ]
@@ -155,6 +157,10 @@ def parse_path(field_name)
155157 end
156158
157159 # parse predicate field at initialization time
160+ # @param field_name [String] the compare key
161+ # @param data_type [String] the data type of the variable
162+ # When parsing operations (IntegerGreaterThan), this will be the operation data type (e.g.: Integer)
163+ # When parsing type checks (IsString), this will always be a Boolean
158164 def parse_field ( field_name , data_type )
159165 value = payload [ field_name ]
160166 return value if correct_type? ( value , data_type )
@@ -165,6 +171,7 @@ def parse_field(field_name, data_type)
165171 # fetch a path at runtime
166172 def fetch_path ( field_name , field_path , context , input )
167173 value = field_path . value ( context , input )
174+ # if this is an operation (GreaterThanPath), ensure the value is the correct type
168175 return value if type . nil? || correct_type? ( value , type )
169176
170177 runtime_field_error! ( field_name , field_path . to_s , "required to point to a #{ type } " )
@@ -173,7 +180,7 @@ def fetch_path(field_name, field_path, context, input)
173180 # if we have runtime checking, check against that type
174181 # otherwise assume checking a TYPE_CHECK predicate and check against Boolean
175182 def correct_type? ( value , data_type )
176- send ( "is_#{ data_type . downcase } ?" . to_sym , value )
183+ send ( : "is_#{ data_type . downcase } ?", value )
177184 end
178185 end
179186 end
0 commit comments