Class: SeapigObject

Inherits:
Hash
  • Object
show all
Defined in:
lib/seapig-client-ruby/client.rb

Direct Known Subclasses

SeapigMasterObject, SeapigSlaveObject

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, id, options) ⇒ SeapigObject

Returns a new instance of SeapigObject.



196
197
198
199
200
201
202
203
204
# File 'lib/seapig-client-ruby/client.rb', line 196

def initialize(client, id, options)
  @client = client
  @id = id
  @destroyed = false
  @ondestroy_proc = nil
  @onstatuschange_proc = nil
  @initialized = !!options[:object]
  self.merge!(options[:object]) if options[:object].kind_of?(Hash)
end

Instance Attribute Details

#destroyedObject (readonly)

Returns the value of attribute destroyed.



193
194
195
# File 'lib/seapig-client-ruby/client.rb', line 193

def destroyed
  @destroyed
end

#idObject (readonly)

Returns the value of attribute id.



193
194
195
# File 'lib/seapig-client-ruby/client.rb', line 193

def id
  @id
end

#initializedObject (readonly)

Returns the value of attribute initialized.



193
194
195
# File 'lib/seapig-client-ruby/client.rb', line 193

def initialized
  @initialized
end

#versionObject (readonly)

Returns the value of attribute version.



193
194
195
# File 'lib/seapig-client-ruby/client.rb', line 193

def version
  @version
end

Instance Method Details

#destroy(id) ⇒ Object



207
208
209
210
211
# File 'lib/seapig-client-ruby/client.rb', line 207

def destroy(id)
  @destroyed = true
  @onstatuschange_proc.call(self) if @onstatuschange_proc
  @ondestroy_proc.call(self) if @ondestroy_proc
end

#matches(id) ⇒ Object



214
215
216
# File 'lib/seapig-client-ruby/client.rb', line 214

def matches(id)
  id =~ Regexp.new(Regexp.escape(@id).gsub('\*','.*?'))
end

#ondestroy(&block) ⇒ Object



224
225
226
227
# File 'lib/seapig-client-ruby/client.rb', line 224

def ondestroy(&block)
  @ondestroy_proc = block
  self
end

#onstatuschange(&block) ⇒ Object



230
231
232
233
# File 'lib/seapig-client-ruby/client.rb', line 230

def onstatuschange(&block)
  @onstatuschange_proc = block
  self
end

#sanitizedObject



219
220
221
# File 'lib/seapig-client-ruby/client.rb', line 219

def sanitized
  JSON.load(JSON.dump(self))
end


236
237
238
# File 'lib/seapig-client-ruby/client.rb', line 236

def unlink
  @client.unlink(@id)
end