Class: SkyDB::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/skydb/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Table

Initializes the table.



10
11
12
13
# File 'lib/skydb/table.rb', line 10

def initialize(options={})
  self.client = options[:client]
  self.name = options[:name]
end

Instance Attribute Details

#clientObject

The client this table is associated with.



23
24
25
# File 'lib/skydb/table.rb', line 23

def client
  @client
end

#nameObject

The name of the table.



26
27
28
# File 'lib/skydb/table.rb', line 26

def name
  @name
end

Instance Method Details

#add_event(object_id, event, options = {}) ⇒ Event

Adds an event to an object.

Parameters:

  • object_id (String)

    the object’s identifier.

  • event (Event)

    the event to add.

Returns:

Raises:

  • (ArgumentError)


108
109
110
111
# File 'lib/skydb/table.rb', line 108

def add_event(object_id, event, options={})
  raise ArgumentError.new("Table not associated with client") if client.nil?
  return client.add_event(self, object_id, event, options)
end

#as_json(*a) ⇒ Object



153
# File 'lib/skydb/table.rb', line 153

def as_json(*a); return to_hash(*a); end

#create_property(property, options = {}) ⇒ Object

Creates a property on a table.

Parameters:

  • property (Property)

    the property to create.

Raises:

  • (ArgumentError)


60
61
62
63
# File 'lib/skydb/table.rb', line 60

def create_property(property, options={})
  raise ArgumentError.new("Table not associated with client") if client.nil?
  return client.create_property(self, property, options)
end

#delete_event(object_id, event, options = {}) ⇒ Object

Deletes an event for an object on a table.

Parameters:

  • object_id (String)

    the object’s identifier.

  • event (Event)

    the event to delete.

Raises:

  • (ArgumentError)


117
118
119
120
# File 'lib/skydb/table.rb', line 117

def delete_event(object_id, event, options={})
  raise ArgumentError.new("Table not associated with client") if client.nil?
  return client.delete_event(self, object_id, event, options)
end

#delete_property(property, options = {}) ⇒ Object

Deletes a property on a table.

Parameters:

  • property (Property)

    the property to delete.

Raises:

  • (ArgumentError)


76
77
78
79
# File 'lib/skydb/table.rb', line 76

def delete_property(property, options={})
  raise ArgumentError.new("Table not associated with client") if client.nil?
  return client.delete_property(self, property, options)
end

#from_hash(hash, *a) ⇒ Object

Decodes a hash into a table.



148
149
150
151
# File 'lib/skydb/table.rb', line 148

def from_hash(hash, *a)
  self.name = hash.nil? ? '' : hash['name']
  return self
end

#get_event(object_id, timestamp, options = {}) ⇒ Event

Retrieves the event that occurred at a given point in time for an object.

Returns:

Raises:

  • (ArgumentError)


97
98
99
100
# File 'lib/skydb/table.rb', line 97

def get_event(object_id, timestamp, options={})
  raise ArgumentError.new("Table not associated with client") if client.nil?
  return client.get_event(self, object_id, timestamp, options)
end

#get_events(object_id, options = {}) ⇒ Array

Retrieves all events for a given object.

Returns:

  • (Array)

    the list of events on the table.

Raises:

  • (ArgumentError)


89
90
91
92
# File 'lib/skydb/table.rb', line 89

def get_events(object_id, options={})
  raise ArgumentError.new("Table not associated with client") if client.nil?
  return client.get_events(self, object_id, options)
end

#get_properties(options = {}) ⇒ Array

Retrieves a list of all properties for the table.

Returns:

  • (Array)

    the list of properties on the table.

Raises:

  • (ArgumentError)


42
43
44
45
# File 'lib/skydb/table.rb', line 42

def get_properties(options={})
  raise ArgumentError.new("Table not associated with client") if client.nil?
  return client.get_properties(self, options)
end

#get_property(name, options = {}) ⇒ Array

Retrieves a single property by name from the table.

Parameters:

  • name (String)

    The name of the property to retrieve.

Returns:

  • (Array)

    the list of properties on the table.

Raises:

  • (ArgumentError)


52
53
54
55
# File 'lib/skydb/table.rb', line 52

def get_property(name, options={})
  raise ArgumentError.new("Table not associated with client") if client.nil?
  return client.get_property(self, name, options)
end

#query(q) ⇒ Results

Runs a query against a given table.

Parameters:

  • q (Hash)

    The query definition to run.

Returns:

  • (Results)

    the results of the query.

Raises:

  • (ArgumentError)


132
133
134
135
# File 'lib/skydb/table.rb', line 132

def query(q)
  raise ArgumentError.new("Table not associated with client") if client.nil?
  return client.query(self, q)
end

#to_hash(*a) ⇒ Object

Encodes the table into a hash.



143
144
145
# File 'lib/skydb/table.rb', line 143

def to_hash(*a)
  {'name' => name}
end

#to_json(*a) ⇒ Object



154
# File 'lib/skydb/table.rb', line 154

def to_json(*a); return as_json(*a).to_json; end

#update_property(property, options = {}) ⇒ Object

Updates a property on a table.

Parameters:

  • property (Property)

    the property to update.

Raises:

  • (ArgumentError)


68
69
70
71
# File 'lib/skydb/table.rb', line 68

def update_property(property, options={})
  raise ArgumentError.new("Table not associated with client") if client.nil?
  return client.update_property(self, property, options)
end