Class: SkyDB::Table
- Inherits:
-
Object
- Object
- SkyDB::Table
- Defined in:
- lib/skydb/table.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
The client this table is associated with.
-
#name ⇒ Object
The name of the table.
Instance Method Summary collapse
-
#add_event(object_id, event, options = {}) ⇒ Event
Adds an event to an object.
- #as_json(*a) ⇒ Object
-
#create_property(property, options = {}) ⇒ Object
Creates a property on a table.
-
#delete_event(object_id, event, options = {}) ⇒ Object
Deletes an event for an object on a table.
-
#delete_property(property, options = {}) ⇒ Object
Deletes a property on a table.
-
#from_hash(hash, *a) ⇒ Object
Decodes a hash into a table.
-
#get_event(object_id, timestamp, options = {}) ⇒ Event
Retrieves the event that occurred at a given point in time for an object.
-
#get_events(object_id, options = {}) ⇒ Array
Retrieves all events for a given object.
-
#get_properties(options = {}) ⇒ Array
Retrieves a list of all properties for the table.
-
#get_property(name, options = {}) ⇒ Array
Retrieves a single property by name from the table.
-
#initialize(options = {}) ⇒ Table
constructor
Initializes the table.
-
#query(q) ⇒ Results
Runs a query against a given table.
-
#to_hash(*a) ⇒ Object
Encodes the table into a hash.
- #to_json(*a) ⇒ Object
-
#update_property(property, options = {}) ⇒ Object
Updates a property on a table.
Constructor Details
#initialize(options = {}) ⇒ Table
Initializes the table.
10 11 12 13 |
# File 'lib/skydb/table.rb', line 10 def initialize(={}) self.client = [:client] self.name = [:name] end |
Instance Attribute Details
#client ⇒ Object
The client this table is associated with.
23 24 25 |
# File 'lib/skydb/table.rb', line 23 def client @client end |
#name ⇒ Object
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.
108 109 110 111 |
# File 'lib/skydb/table.rb', line 108 def add_event(object_id, event, ={}) raise ArgumentError.new("Table not associated with client") if client.nil? return client.add_event(self, object_id, event, ) 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.
60 61 62 63 |
# File 'lib/skydb/table.rb', line 60 def create_property(property, ={}) raise ArgumentError.new("Table not associated with client") if client.nil? return client.create_property(self, property, ) end |
#delete_event(object_id, event, options = {}) ⇒ Object
Deletes an event for an object on a table.
117 118 119 120 |
# File 'lib/skydb/table.rb', line 117 def delete_event(object_id, event, ={}) raise ArgumentError.new("Table not associated with client") if client.nil? return client.delete_event(self, object_id, event, ) end |
#delete_property(property, options = {}) ⇒ Object
Deletes a property on a table.
76 77 78 79 |
# File 'lib/skydb/table.rb', line 76 def delete_property(property, ={}) raise ArgumentError.new("Table not associated with client") if client.nil? return client.delete_property(self, property, ) 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.
97 98 99 100 |
# File 'lib/skydb/table.rb', line 97 def get_event(object_id, , ={}) raise ArgumentError.new("Table not associated with client") if client.nil? return client.get_event(self, object_id, , ) end |
#get_events(object_id, options = {}) ⇒ Array
Retrieves all events for a given object.
89 90 91 92 |
# File 'lib/skydb/table.rb', line 89 def get_events(object_id, ={}) raise ArgumentError.new("Table not associated with client") if client.nil? return client.get_events(self, object_id, ) end |
#get_properties(options = {}) ⇒ Array
Retrieves a list of all properties for the table.
42 43 44 45 |
# File 'lib/skydb/table.rb', line 42 def get_properties(={}) raise ArgumentError.new("Table not associated with client") if client.nil? return client.get_properties(self, ) end |
#get_property(name, options = {}) ⇒ Array
Retrieves a single property by name from the table.
52 53 54 55 |
# File 'lib/skydb/table.rb', line 52 def get_property(name, ={}) raise ArgumentError.new("Table not associated with client") if client.nil? return client.get_property(self, name, ) end |
#query(q) ⇒ Results
Runs a query against a given table.
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.
68 69 70 71 |
# File 'lib/skydb/table.rb', line 68 def update_property(property, ={}) raise ArgumentError.new("Table not associated with client") if client.nil? return client.update_property(self, property, ) end |