Module: TMS::InstanceResource::InstanceMethods

Defined in:
lib/tms_client/instance_resource.rb

Instance Method Summary collapse

Instance Method Details

#attributesObject



106
107
108
# File 'lib/tms_client/instance_resource.rb', line 106

def attributes
  @attributes
end

#deleteObject



133
134
135
# File 'lib/tms_client/instance_resource.rb', line 133

def delete
  process_response(client.delete(self.href), :delete)
end

#delete!Object



137
138
139
# File 'lib/tms_client/instance_resource.rb', line 137

def delete!
  process_response(client.delete(self.href), :delete) or raise TMS::Errors::InvalidDelete.new(self)
end

#getObject Also known as: get!



110
111
112
113
# File 'lib/tms_client/instance_resource.rb', line 110

def get
  raise TMS::Errors::InvalidGet if self.new_record?
  process_response(client.get(self.href), :get) && self
end

#initialize(client, href = nil, attrs = nil) ⇒ Object



100
101
102
103
104
# File 'lib/tms_client/instance_resource.rb', line 100

def initialize(client, href=nil, attrs=nil)
  super(client, href)
  @attributes = {}
  set_attributes_from_hash(attrs) if attrs
end

#postObject



116
117
118
119
# File 'lib/tms_client/instance_resource.rb', line 116

def post
  self.errors = nil
  process_response(client.post(self), :post)
end

#post!Object



121
122
123
# File 'lib/tms_client/instance_resource.rb', line 121

def post!
  self.post or raise TMS::Errors::InvalidPost.new(self)
end

#putObject



125
126
127
# File 'lib/tms_client/instance_resource.rb', line 125

def put
  process_response(client.put(self), :put)
end

#put!Object



129
130
131
# File 'lib/tms_client/instance_resource.rb', line 129

def put!
  process_response(client.put(self), :put) or raise TMS::Errors::InvalidPut.new(self)
end

#to_jsonObject



145
146
147
148
149
150
151
152
153
154
# File 'lib/tms_client/instance_resource.rb', line 145

def to_json
  json_hash = {}
  self.class.writeable_attributes.each do |attr|
    json_hash[attr] = self.send(attr)
  end
  self.class.collection_attributes.each do |coll|
    json_hash[coll] = self.send(coll).to_json
  end
  json_hash
end

#to_sObject



141
142
143
# File 'lib/tms_client/instance_resource.rb', line 141

def to_s
  "<#{self.class.inspect}#{' href=' + self.href if self.href} attributes=#{@attributes.inspect}>"
end