lib/zertico/service.rb in zertico-1.0.0 vs lib/zertico/service.rb in zertico-1.1.0

- old
+ new

@@ -1,58 +1,54 @@ module Zertico module Service def all - @responder = resource.all - instance_variable_set("@#{interface_name.pluralize}", @responder) - @options = {} + instance_variable_set("@#{interface_name.pluralize}", resource.all) end def build - @responder = resource.new - instance_variable_set("@#{interface_name}", @responder) - @options = {} + instance_variable_set("@#{interface_name}", resource.new) end def find - @responder = resource.find(params[interface_id.to_sym]) - instance_variable_set("@#{interface_name}", @responder) - @options = {} + instance_variable_set("@#{interface_name}", resource.find(params[interface_id.to_sym])) end def generate - @responder = resource.create(params[interface_name.to_sym]) - instance_variable_set("@#{interface_name}", @responder) - @options = {} + instance_variable_set("@#{interface_name}", resource.create(params[interface_name.to_sym])) end def modify find - @responder.update_attributes(params[interface_name.to_sym]) - @options = {} + instance_variable_get("@#{interface_name}").update_attributes(params[interface_name.to_sym]) + instance_variable_get("@#{interface_name}") end def delete find - @responder.destroy - @options = {} + instance_variable_get("@#{interface_name}").destroy + instance_variable_get("@#{interface_name}") end def resource - @resource ||= interface_class + @resource_object ||= interface_class end def resource=(resource_chain = []) - @resource = resource_chain.shift - @resource = @resource.constantize if @resource.respond_to?(:constantize) + @resource_object = resource_chain.shift + @resource_object = @resource_object.constantize if @resource_object.respond_to?(:constantize) resource_chain.each do |resource| - @resource = @resource.send(resource) + @resource_object = @resource_object.send(resource) end end protected def interface_id - return "#{interface_name}_id" if self.class.name.chomp('Controller').split('::').size > 1 + begin + return "#{interface_name}_id" if self.class.name.chomp('Controller').split('::').size > 1 + rescue NameError + 'id' + end 'id' end def interface_name self.interface_class.name.singularize.underscore \ No newline at end of file