lib/flexirest/request.rb in flexirest-1.2.17 vs lib/flexirest/request.rb in flexirest-1.2.18
- old
+ new
@@ -11,12 +11,13 @@
def initialize(method, object, params = {})
@method = method
@method[:options] ||= {}
@method[:options][:lazy] ||= []
+ @method[:options][:array] ||= []
@method[:options][:has_one] ||= {}
- @overridden_name = @method[:options][:overridden_name]
+ @overridden_name = @method[:options][:overridden_name]
@object = object
@response_delegate = Flexirest::RequestDelegator.new(nil)
@params = params
@headers = HeadersList.new
end
@@ -438,11 +439,15 @@
if @method[:options][:lazy].include?(k)
object._attributes[k] = Flexirest::LazyAssociationLoader.new(overridden_name, v, self, overridden_name:(overridden_name))
elsif v.is_a? Hash
object._attributes[k] = new_object(v, overridden_name )
elsif v.is_a? Array
- object._attributes[k] = Flexirest::ResultIterator.new
+ if @method[:options][:array].include?(k)
+ object._attributes[k] = Array.new
+ else
+ object._attributes[k] = Flexirest::ResultIterator.new
+ end
v.each do |item|
if item.is_a? Hash
object._attributes[k] << new_object(item, overridden_name)
else
object._attributes[k] << item
@@ -512,10 +517,10 @@
def select_name(name, parent_name)
if @method[:options][:has_many][name] || @method[:options][:has_one][name]
return name
end
-
+
parent_name || name
end
def is_json_response?
@response.response_headers['Content-Type'].nil? || @response.response_headers['Content-Type'].include?('json')