Sha256: 1952bcbe50eaacf779fcef840760b97932818d6ef39df10ac315ee780a063854

Contents?: true

Size: 937 Bytes

Versions: 6

Compression:

Stored size: 937 Bytes

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.class.name.chomp('Controller').split('::').last.singularize.underscore
    end

    def interface_class
      self.interface_name.camelize.constantize
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
zertico-0.5.2 lib/zertico/service.rb
zertico-0.5.1 lib/zertico/service.rb
zertico-0.5.0 lib/zertico/service.rb
zertico-0.4.0 lib/zertico/service.rb
zertico-0.3.1 lib/zertico/service.rb
zertico-0.3.0 lib/zertico/service.rb