lib/haveapi/client/resource_instance.rb in haveapi-client-0.6.0 vs lib/haveapi/client/resource_instance.rb in haveapi-client-0.7.0

- old
+ new

@@ -20,15 +20,17 @@ if response if response.is_a?(Hash) @params = response @prepared_args = response[:_meta][:url_params] + @meta = response[:_meta] unless @meta else @response = response @params = response.response @prepared_args = response.meta[:url_params] + @meta = response.meta unless @meta end setup_from_clone(resource) define_attributes end @@ -110,14 +112,17 @@ case param[:type] when 'Resource' @resource_instances[name] = find_association(param, @params[name]) # id reader - ensure_method(:"#{name}_id") { @params[name][ param[:value_id].to_sym ] } + ensure_method(:"#{name}_id") do + @params[name] && @params[name][ param[:value_id].to_sym ] + end # id writer ensure_method(:"#{name}_id=") do |id| + @params[name] ||= {} @params[name][ param[:value_id].to_sym ] = id @resource_instances[name] = find_association( param, { @@ -137,9 +142,10 @@ @resource_instances[name] && @resource_instances[name].resolve end # value writer ensure_method(:"#{name}=") do |obj| + @params[name] ||= {} @params[name][ param[:value_id].to_sym ] = obj.method(param[:value_id]).call @params[name][ param[:value_label].to_sym ] = obj.method(param[:value_label]).call @resource_instances[name] = obj end