Class: Reflect::Keyspace
- Inherits:
-
Object
- Object
- Reflect::Keyspace
- Defined in:
- lib/reflect/keyspace.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#description ⇒ Object
Returns the value of attribute description.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#name ⇒ Object
Returns the value of attribute name.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#statistics_key ⇒ Object
Returns the value of attribute statistics_key.
-
#status ⇒ Object
Returns the value of attribute status.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
-
#append(key, records) ⇒ Object
Appends records to a tablet.
-
#initialize(client, attrs = {}) ⇒ Keyspace
constructor
A new instance of Keyspace.
-
#patch(key, records, criteria) ⇒ Object
Patches the existing records in a tablet with a net set of records.
-
#replace(key, records) ⇒ Object
Replaces the existing records in a tablet with a net set of records.
Constructor Details
#initialize(client, attrs = {}) ⇒ Keyspace
Returns a new instance of Keyspace.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/reflect/keyspace.rb', line 18 def initialize(client, attrs={}) @client = client # If we have fields, we'll need to populate them individually. fields = attrs.delete("fields") attrs['updated_at'] = Time.parse(attrs['updated_at']) if attrs['updated_at'] attrs['created_at'] = Time.parse(attrs['created_at']) if attrs['created_at'] attrs.each do |k, v| self.send("#{k}=".to_s, v) end if fields self.fields = fields.map { |f| Field.new(f) } end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/reflect/keyspace.rb', line 7 def client @client end |
#created_at ⇒ Object
Returns the value of attribute created_at.
15 16 17 |
# File 'lib/reflect/keyspace.rb', line 15 def created_at @created_at end |
#description ⇒ Object
Returns the value of attribute description.
12 13 14 |
# File 'lib/reflect/keyspace.rb', line 12 def description @description end |
#fields ⇒ Object
Returns the value of attribute fields.
13 14 15 |
# File 'lib/reflect/keyspace.rb', line 13 def fields @fields end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/reflect/keyspace.rb', line 9 def name @name end |
#slug ⇒ Object
Returns the value of attribute slug.
10 11 12 |
# File 'lib/reflect/keyspace.rb', line 10 def slug @slug end |
#statistics_key ⇒ Object
Returns the value of attribute statistics_key.
11 12 13 |
# File 'lib/reflect/keyspace.rb', line 11 def statistics_key @statistics_key end |
#status ⇒ Object
Returns the value of attribute status.
14 15 16 |
# File 'lib/reflect/keyspace.rb', line 14 def status @status end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
16 17 18 |
# File 'lib/reflect/keyspace.rb', line 16 def updated_at @updated_at end |
Instance Method Details
#append(key, records) ⇒ Object
Appends records to a tablet. If the tablet doesn’t exist it will be created. records can be either a single object or an array of objects. A single object represents a single row.
43 44 45 46 47 48 49 |
# File 'lib/reflect/keyspace.rb', line 43 def append(key, records) resp = client.put("/v1/keyspaces/"+self.slug+"/tablets/"+CGI.escape(key), records) if resp.response.code != "202" raise Reflect::RequestError, Reflect.(resp) end end |
#patch(key, records, criteria) ⇒ Object
Patches the existing records in a tablet with a net set of records. The criteria parameter indicates which records to match existing records on. In the Reflect API, if no existing records match the supplied records then those records are dropped.
75 76 77 78 79 80 81 |
# File 'lib/reflect/keyspace.rb', line 75 def patch(key, records, criteria) resp = client.patch("/v1/keyspaces/"+self.slug+"/tablets/"+CGI.escape(key), records, "X-Criteria" => criteria.join(", ")) if resp.response.code != "202" raise Reflect::RequestError, Reflect.(resp) end end |
#replace(key, records) ⇒ Object
Replaces the existing records in a tablet with a net set of records. records can be either a single object or an array of objects. A single object represents a single row.
58 59 60 61 62 63 64 |
# File 'lib/reflect/keyspace.rb', line 58 def replace(key, records) resp = client.post("/v1/keyspaces/"+self.slug+"/tablets/"+CGI.escape(key), records) if resp.response.code != "202" raise Reflect::RequestError, Reflect.(resp) end end |