Sha256: d09a798fc7bc042f19af78e995f085ba046082b1df1862831043ddbc41620009

Contents?: true

Size: 678 Bytes

Versions: 2

Compression:

Stored size: 678 Bytes

Contents

module Masheri
  class ApiObjectBase
    mattr_accessor :type_name

    def self.create(fields = {})
      # XXX: only send fields that aren't read-only
      new(Masheri.client.call_remote(method('create'), fields))
    end

    def self.fetch(id)
      data = Masheri.rpc.call_remote(method('fetch'), id)
      data.nil?? nil : new(data)
    end

    def self.delete(id)
      Masheri.client.call_remote(method('delete'), id)
    end

    def self.method(basename)
      "#{name.split(/\:\:/).last.downcase}.#{basename}"
    end

    def initialize(data)
      # XXX: use setter methods
      data.each_pair {|k, v| instance_variable_set("@#{k}".to_sym, v)}
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
masheri-0.3.5 lib/masheri/api_object_base.rb
masheri-0.3.4 lib/masheri/api_object_base.rb