Class: CassandraIntegration::Proxy
- Inherits:
-
Object
- Object
- CassandraIntegration::Proxy
- Defined in:
- lib/cassandra_integration/proxy.rb
Instance Attribute Summary collapse
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
Class Method Summary collapse
Instance Method Summary collapse
- #cassandra_columns_values_hash ⇒ Object
-
#initialize(instance) ⇒ Proxy
constructor
A new instance of Proxy.
- #record_exists? ⇒ Boolean
- #sync ⇒ Object
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
#instance ⇒ Object (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
.cassandra ⇒ Object
44 45 46 |
# File 'lib/cassandra_integration/proxy.rb', line 44 def self.cassandra self.connect end |
.connect ⇒ Object
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_update ⇒ Object
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_hash ⇒ Object
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
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 |
#sync ⇒ Object
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 |