Class: Reflect::Keyspace

Inherits:
Object
  • Object
show all
Defined in:
lib/reflect/keyspace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/reflect/keyspace.rb', line 7

def client
  @client
end

#created_atObject

Returns the value of attribute created_at.



15
16
17
# File 'lib/reflect/keyspace.rb', line 15

def created_at
  @created_at
end

#descriptionObject

Returns the value of attribute description.



12
13
14
# File 'lib/reflect/keyspace.rb', line 12

def description
  @description
end

#fieldsObject

Returns the value of attribute fields.



13
14
15
# File 'lib/reflect/keyspace.rb', line 13

def fields
  @fields
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/reflect/keyspace.rb', line 9

def name
  @name
end

#slugObject

Returns the value of attribute slug.



10
11
12
# File 'lib/reflect/keyspace.rb', line 10

def slug
  @slug
end

#statistics_keyObject

Returns the value of attribute statistics_key.



11
12
13
# File 'lib/reflect/keyspace.rb', line 11

def statistics_key
  @statistics_key
end

#statusObject

Returns the value of attribute status.



14
15
16
# File 'lib/reflect/keyspace.rb', line 14

def status
  @status
end

#updated_atObject

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.

Parameters:

  • String

    key the key to create

  • Array|Hash

    records the records to create



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._format_error_message(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.

Parameters:

  • String

    key the key to create

  • Array|Hash

    records the records to create

  • Array

    criteria an array of field names within a record to match



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._format_error_message(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.

Parameters:

  • String

    key the key to create

  • Array|Hash

    records the records to create



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._format_error_message(resp)
  end
end