Sha256: bf36a3279e9cc89fa1c4afa1b82db68224c7670e08ab0d12db6bbfbfbbb806c5

Contents?: true

Size: 844 Bytes

Versions: 2

Compression:

Stored size: 844 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)
      object.update_attributes(attributes)
      { interface_name.to_sym => object }
    end

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

    protected

    def interface_name
      self.name.chomp("Service").underscore
    end

    def interface_class
      self.interface_name.constantize
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zertico-0.1.0 lib/zertico/service.rb
zertico-0.0.1.alpha1 lib/zertico/service.rb