vendored/puppet/lib/puppet/pops/evaluator/evaluator_impl.rb in bolt-0.8.0 vs vendored/puppet/lib/puppet/pops/evaluator/evaluator_impl.rb in bolt-0.9.0

- old
+ new

@@ -402,11 +402,13 @@ unless ARITHMETIC_OPERATORS.include?(operator) fail(Issues::UNSUPPORTED_OPERATOR, bin_expr, {:operator => operator}) end left_o = bin_expr.left_expr - if (left.is_a?(Array) || left.is_a?(Hash)) && COLLECTION_OPERATORS.include?(operator) + if left.is_a?(URI) && operator == '+' + concatenate(left, right) + elsif (left.is_a?(Array) || left.is_a?(Hash)) && COLLECTION_OPERATORS.include?(operator) # Handle operation on collections case operator when '+' concatenate(left, right) when '-' @@ -943,11 +945,11 @@ end name = name.value # the string function name obj = receiver[0] receiver_type = Types::TypeCalculator.infer(obj) - if receiver_type.is_a?(Types::PObjectType) + if receiver_type.is_a?(Types::TypeWithMembers) member = receiver_type[name] unless member.nil? args = unfold([], o.arguments || [], scope) return o.lambda.nil? ? member.invoke(obj, scope, args) : member.invoke(obj, scope, args, &proc_from_lambda(o.lambda, scope)) end @@ -1126,12 +1128,16 @@ # # * Array => merge of array interpreted as `[key, value, key, value,...]` # * Hash => a merge, where entries in `y` overrides # * any other => error # - # When x is something else, wrap it in an array first. + # When x is a URI, y of type produces: # + # * String => merge of URI interpreted x + URI(y) using URI merge semantics + # * URI => merge of URI interpreted x + y using URI merge semantics + # * any other => error + # # When x is nil, an empty array is used instead. # # @note to concatenate an Array, nest the array - i.e. `[1,2], [[2,3]]` # # @overload concatenate(obj_x, obj_y) @@ -1156,15 +1162,22 @@ # @return [Hash] new hash with `hsh_x` merged with `ary_y` interpreted as hash in array form # @overload concatenate(hsh_x, hsh_y) # @param hsh_x [Hash] the hash to merge to # @param hsh_y [Hash] hash merged with `hsh_x` # @return [Hash] new hash with `hsh_x` merged with `hsh_y` + # @overload concatenate(uri_x, uri_y) + # @param uri_x [URI] the uri to merge to + # @param uri_y [URI] uri to merged with `uri_x` + # @return [URI] new uri with `uri_x` merged with `uri_y` + # @overload concatenate(uri_x, string_y) + # @param uri_x [URI] the uri to merge to + # @param string_y [String] string to merge with `uri_x` + # @return [URI] new uri with `uri_x` merged with `string_y` # @raise [ArgumentError] when `xxx_x` is neither an Array nor a Hash # @raise [ArgumentError] when `xxx_x` is a Hash, and `xxx_y` is neither Array nor Hash. # def concatenate(x, y) - x = [x] unless x.is_a?(Array) || x.is_a?(Hash) case x when Array y = case y when Array then y when Hash then y.to_a @@ -1187,14 +1200,17 @@ Hash[y] else Hash[*y] end else - raise ArgumentError.new(_("Can only append Array or Hash to a Hash")) + raise ArgumentError.new(_('Can only append Array or Hash to a Hash')) end x.merge y # new hash with overwrite + when URI + raise ArgumentError.new(_('An URI can only be merged with an URI or String')) unless y.is_a?(String) || y.is_a?(URI) + x + y else - raise ArgumentError.new(_("Can only append to an Array or a Hash.")) + concatenate([x], y) end end # Produces the result x \ y (set difference) # When `x` is an Array, `y` is transformed to an array and then all matching elements removed from x.