Class: CassandraIntegration::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/cassandra_integration/proxy.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance) ⇒ Proxy

Returns a new instance of Proxy.



6
7
8
# File 'lib/cassandra_integration/proxy.rb', line 6

def initialize(instance)
  @instance = instance
end

Instance Attribute Details

#instanceObject (readonly)

Returns the value of attribute instance.



4
5
6
# File 'lib/cassandra_integration/proxy.rb', line 4

def instance
  @instance
end

Class Method Details

.cassandraObject



44
45
46
# File 'lib/cassandra_integration/proxy.rb', line 44

def self.cassandra
  self.connect
end

.connectObject



36
37
38
39
40
41
42
# File 'lib/cassandra_integration/proxy.rb', line 36

def self.connect
  @@cassandra ||= Cassandra.new(CassandraIntegration::Config.keyspace,
                                CassandraIntegration::Config.host,
                                :retires => CassandraIntegration::Config.retries,
                                :timeout => CassandraIntegration::Config.timeout,
                                :connect_timeout => CassandraIntegration::Config.connect_timeout)
end

.set_apps_to_updateObject



16
17
18
19
20
21
22
# File 'lib/cassandra_integration/proxy.rb', line 16

def self.set_apps_to_update
  data = Hash.new
  CassandraIntegration::Config.other_apps_ids.split(',').each do |app|
    data[app.to_s] = app.to_s
  end
  data
end

Instance Method Details

#cassandra_columns_values_hashObject



28
29
30
31
32
33
34
# File 'lib/cassandra_integration/proxy.rb', line 28

def cassandra_columns_values_hash
  data = Hash.new
  @instance.class.cassandra_columns_values_hash.each do |key, value|
    data[key.to_s] = @instance.send(value).to_s
  end
  return data
end

#record_exists?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/cassandra_integration/proxy.rb', line 24

def record_exists?
  !self.class.connect.get(@instance.class.cassandra_column_family, @instance.cassandra_sync_identifier).blank?
end

#syncObject



10
11
12
13
14
# File 'lib/cassandra_integration/proxy.rb', line 10

def sync
  self.class.connect.insert(@instance.class.cassandra_column_family,
                    @instance.cassandra_sync_identifier,
                    cassandra_columns_values_hash.merge(CassandraIntegration::Proxy.set_apps_to_update)) unless record_exists?
end