Module: TMS::InstanceResource::InstanceMethods
- Defined in:
- lib/tms_client/instance_resource.rb
Instance Method Summary collapse
- #attributes ⇒ Object
- #delete ⇒ Object
- #delete! ⇒ Object
- #get ⇒ Object (also: #get!)
- #initialize(client, href = nil, attrs = nil) ⇒ Object
- #post ⇒ Object
- #post! ⇒ Object
- #put ⇒ Object
- #put! ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#attributes ⇒ Object
106 107 108 |
# File 'lib/tms_client/instance_resource.rb', line 106 def attributes @attributes end |
#delete ⇒ Object
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 |
#get ⇒ Object 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 |
#post ⇒ Object
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 |
#put ⇒ Object
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_json ⇒ Object
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_s ⇒ Object
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 |