lib/zertico/service.rb in zertico-0.5.6 vs lib/zertico/service.rb in zertico-0.6.0

- old
+ new

@@ -1,21 +1,21 @@ module Zertico module Service def all - { interface_name.pluralize.to_sym => interface_class.all } + { interface_name.pluralize.to_sym => resource.all } end def build - { interface_name.to_sym => interface_class.new } + { interface_name.to_sym => resource.new } end def find(id) - { interface_name.to_sym => interface_class.find(id) } + { interface_name.to_sym => resource.find(id) } end def generate(attributes = {}) - { interface_name.to_sym => interface_class.create(attributes) } + { interface_name.to_sym => resource.create(attributes) } end def modify(id, attributes = {}) object = self.find(id)[interface_name.to_sym] object.update_attributes(attributes) @@ -26,10 +26,22 @@ object = self.find(id)[interface_name.to_sym] object.destroy { interface_name.to_sym => object } end + def resource + @resource ||= interface_class + end + + def resource=(resource_chain = []) + @resource = resource_chain.shift + @resource = @resource.constantize if @resource.respond_to?(:constantize) + resource_chain.each do |resource| + @resource = @resource.send(resource) + end + end + protected def interface_name self.interface_class.name.singularize.underscore end @@ -40,6 +52,6 @@ rescue NameError self.class.name.chomp('Controller').split('::').last.singularize.constantize end end end -end +end \ No newline at end of file