Sha256: be9bb8cd95ad66b4fc5a7e09277090bc7074eada14c38661602b15e35b4ea66d

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

module Zertico
  module Service
    def all
      { interface_name.pluralize.to_sym => interface_class.all }
    end

    def build
      { interface_name.to_sym => interface_class.new }
    end

    def find(id)
      { interface_name.to_sym => interface_class.find(id) }
    end

    def generate(attributes = {})
      { interface_name.to_sym => interface_class.create(attributes) }
    end

    def modify(id, attributes = {})
      object = self.find(id)[interface_name.to_sym]
      object.update_attributes(attributes)
      { interface_name.to_sym => object }
    end

    def delete(id)
      object = self.find(id)[interface_name.to_sym]
      object.destroy
      { interface_name.to_sym => object }
    end

    protected

    def interface_name
      self.interface_class.name.singularize.underscore
    end

    def interface_class
      begin
        self.class.name.chomp('Controller').constantize
      rescue NameError
        self.class.name.chomp('Controller').split('::').last.constantize
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zertico-0.5.5 lib/zertico/service.rb
zertico-0.5.4 lib/zertico/service.rb
zertico-0.5.3 lib/zertico/service.rb