gotime-cassandra_object 2.2.2 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,10 +1,2 @@
1
- pkg
2
- .yardoc
3
- doc/
4
- bin/*
5
- vendor/gems/*
6
- !vendor/gems/cache/
7
- .bundle
8
-
9
- *.swp
10
- *.swo
1
+ Gemfile.lock
2
+ *.gem
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'gotime-cassandra_object'
5
- s.version = '2.2.2'
5
+ s.version = '2.2.3'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
@@ -12,7 +12,6 @@ module CassandraObject
12
12
  autoload :Callbacks
13
13
  autoload :Validations
14
14
  autoload :Identity
15
- autoload :Indexes
16
15
  autoload :Serialization
17
16
  autoload :Associations
18
17
  autoload :Migrations
@@ -87,11 +87,11 @@ module CassandraObject
87
87
 
88
88
  private
89
89
  def attribute(name)
90
- read_attribute(name.to_sym)
90
+ read_attribute(name)
91
91
  end
92
92
 
93
93
  def attribute=(name, value)
94
- write_attribute(name.to_sym, value)
94
+ write_attribute(name, value)
95
95
  end
96
96
  end
97
97
  end
@@ -35,7 +35,6 @@ module CassandraObject
35
35
  include Attributes
36
36
  include Persistence
37
37
  include Callbacks
38
- include Indexes
39
38
  include Dirty
40
39
  include Validations
41
40
  include Associations
@@ -9,11 +9,11 @@ module CassandraObject
9
9
  module ClassMethods
10
10
  DEFAULT_OPTIONS = {
11
11
  servers: "127.0.0.1:9160",
12
- thrift: {}
12
+ thrift: {}
13
13
  }
14
14
  def establish_connection(spec)
15
15
  spec.reverse_merge!(DEFAULT_OPTIONS)
16
- self.connection = Cassandra.new(spec[:keyspace], spec[:servers], spec[:thrift])
16
+ self.connection = Cassandra.new(spec[:keyspace], spec[:servers], spec[:thrift].symbolize_keys!)
17
17
  end
18
18
  end
19
19
  end
@@ -33,14 +33,14 @@ module CassandraObject
33
33
  def instantiate(key, attributes)
34
34
  # remove any attributes we don't know about. we would do this earlier, but we want to make such
35
35
  # attributes available to migrations
36
- attributes.delete_if{|k,_| !model_attributes.keys.include?(k)}
36
+ attributes.delete_if { |k,_| model_attributes[k].nil? }
37
37
 
38
38
  allocate.tap do |object|
39
39
  object.instance_variable_set("@schema_version", attributes.delete('schema_version'))
40
40
  object.instance_variable_set("@key", parse_key(key))
41
41
  object.instance_variable_set("@new_record", false)
42
42
  object.instance_variable_set("@destroyed", false)
43
- object.instance_variable_set("@attributes", decode_columns_hash(attributes).with_indifferent_access)
43
+ object.instance_variable_set("@attributes", decode_columns_hash(attributes))
44
44
  end
45
45
  end
46
46
 
@@ -55,10 +55,7 @@ module CassandraObject
55
55
  end
56
56
 
57
57
  def decode_columns_hash(attributes)
58
- attributes.inject(Hash.new) do |memo, (column_name, value)|
59
- memo[column_name.to_s] = model_attributes[column_name].converter.decode(value)
60
- memo
61
- end
58
+ Hash[attributes.map { |k, v| [k.to_s, model_attributes[k].converter.decode(v)] }]
62
59
  end
63
60
 
64
61
  def column_family_configuration
@@ -14,7 +14,7 @@ class CassandraObject::ConnectionTest < CassandraObject::TestCase
14
14
  assert_not_equal CassandraObject::Base.connection, TestObject.connection
15
15
  assert_equal 'place_directory_development', TestObject.connection.keyspace
16
16
  assert_equal ["192.168.0.100:9160"], TestObject.connection.servers
17
- assert_equal 10, TestObject.connection.thrift_client_options['timeout']
17
+ assert_equal 10, TestObject.connection.thrift_client_options[:timeout]
18
18
  end
19
19
 
20
20
  test 'establish_connection defaults' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gotime-cassandra_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-07-27 00:00:00.000000000Z
13
+ date: 2011-07-29 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &2152750980 !ruby/object:Gem::Requirement
17
+ requirement: &2169327880 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2152750980
25
+ version_requirements: *2169327880
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: cassandra
28
- requirement: &2152750520 !ruby/object:Gem::Requirement
28
+ requirement: &2169327380 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 0.11.3
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2152750520
36
+ version_requirements: *2169327380
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &2152750060 !ruby/object:Gem::Requirement
39
+ requirement: &2169326780 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 1.0.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2152750060
47
+ version_requirements: *2169326780
48
48
  description: Cassandra ActiveModel
49
49
  email: gems@gotime.com
50
50
  executables: []
@@ -55,7 +55,6 @@ files:
55
55
  - .gitignore
56
56
  - CHANGELOG
57
57
  - Gemfile
58
- - Gemfile.lock
59
58
  - LICENSE
60
59
  - MIT-LICENSE
61
60
  - README.markdown
@@ -85,7 +84,6 @@ files:
85
84
  - lib/cassandra_object/identity/key.rb
86
85
  - lib/cassandra_object/identity/natural_key_factory.rb
87
86
  - lib/cassandra_object/identity/uuid_key_factory.rb
88
- - lib/cassandra_object/indexes.rb
89
87
  - lib/cassandra_object/log_subscriber.rb
90
88
  - lib/cassandra_object/migrations.rb
91
89
  - lib/cassandra_object/migrations/migration.rb
data/Gemfile.lock DELETED
@@ -1,91 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- gotime-cassandra_object (2.2.1)
5
- cassandra (~> 0.11.3)
6
- rails (~> 3.0)
7
-
8
- GEM
9
- remote: http://rubygems.org/
10
- specs:
11
- abstract (1.0.0)
12
- actionmailer (3.0.9)
13
- actionpack (= 3.0.9)
14
- mail (~> 2.2.19)
15
- actionpack (3.0.9)
16
- activemodel (= 3.0.9)
17
- activesupport (= 3.0.9)
18
- builder (~> 2.1.2)
19
- erubis (~> 2.6.6)
20
- i18n (~> 0.5.0)
21
- rack (~> 1.2.1)
22
- rack-mount (~> 0.6.14)
23
- rack-test (~> 0.5.7)
24
- tzinfo (~> 0.3.23)
25
- activemodel (3.0.9)
26
- activesupport (= 3.0.9)
27
- builder (~> 2.1.2)
28
- i18n (~> 0.5.0)
29
- activerecord (3.0.9)
30
- activemodel (= 3.0.9)
31
- activesupport (= 3.0.9)
32
- arel (~> 2.0.10)
33
- tzinfo (~> 0.3.23)
34
- activeresource (3.0.9)
35
- activemodel (= 3.0.9)
36
- activesupport (= 3.0.9)
37
- activesupport (3.0.9)
38
- arel (2.0.10)
39
- builder (2.1.2)
40
- cassandra (0.11.3)
41
- json
42
- rake
43
- simple_uuid (>= 0.1.0)
44
- thrift_client (>= 0.6.3)
45
- erubis (2.6.6)
46
- abstract (>= 1.0.0)
47
- i18n (0.5.0)
48
- json (1.5.3)
49
- mail (2.2.19)
50
- activesupport (>= 2.3.6)
51
- i18n (>= 0.4.0)
52
- mime-types (~> 1.16)
53
- treetop (~> 1.4.8)
54
- mime-types (1.16)
55
- polyglot (0.3.1)
56
- rack (1.2.3)
57
- rack-mount (0.6.14)
58
- rack (>= 1.0.0)
59
- rack-test (0.5.7)
60
- rack (>= 1.0)
61
- rails (3.0.9)
62
- actionmailer (= 3.0.9)
63
- actionpack (= 3.0.9)
64
- activerecord (= 3.0.9)
65
- activeresource (= 3.0.9)
66
- activesupport (= 3.0.9)
67
- bundler (~> 1.0)
68
- railties (= 3.0.9)
69
- railties (3.0.9)
70
- actionpack (= 3.0.9)
71
- activesupport (= 3.0.9)
72
- rake (>= 0.8.7)
73
- rdoc (~> 3.4)
74
- thor (~> 0.14.4)
75
- rake (0.9.2)
76
- rdoc (3.8)
77
- simple_uuid (0.1.1)
78
- thor (0.14.6)
79
- thrift (0.6.0)
80
- thrift_client (0.6.3)
81
- thrift (~> 0.6.0)
82
- treetop (1.4.9)
83
- polyglot (>= 0.3.1)
84
- tzinfo (0.3.29)
85
-
86
- PLATFORMS
87
- ruby
88
-
89
- DEPENDENCIES
90
- bundler (~> 1.0.0)
91
- gotime-cassandra_object!
@@ -1,129 +0,0 @@
1
- module CassandraObject
2
- module Indexes
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- class_inheritable_accessor :indexes
7
- end
8
-
9
- class UniqueIndex
10
- def initialize(attribute_name, model_class, options)
11
- @attribute_name = attribute_name
12
- @model_class = model_class
13
- end
14
-
15
- def find(attribute_value)
16
- # first find the key value
17
- key = @model_class.connection.get(column_family, attribute_value.to_s, 'key')
18
- # then pass to get
19
- if key
20
- @model_class.get(key.to_s)
21
- else
22
- @model_class.connection.remove(column_family, attribute_value.to_s)
23
- nil
24
- end
25
- end
26
-
27
- def write(record)
28
- @model_class.connection.insert(column_family, record.send(@attribute_name).to_s, {'key'=>record.key.to_s})
29
- end
30
-
31
- def remove(record)
32
- @model_class.connection.remove(column_family, record.send(@attribute_name).to_s)
33
- end
34
-
35
- def column_family
36
- @model_class.column_family + "By" + @attribute_name.to_s.camelize
37
- end
38
-
39
- def column_family_configuration
40
- {:Name=>column_family, :CompareWith=>"UTF8Type"}
41
- end
42
- end
43
-
44
- class Index
45
- def initialize(attribute_name, model_class, options)
46
- @attribute_name = attribute_name
47
- @model_class = model_class
48
- @reversed = options[:reversed]
49
- end
50
-
51
- def find(attribute_value, options = {})
52
- cursor = CassandraObject::Cursor.new(@model_class, column_family, attribute_value.to_s, @attribute_name.to_s, :start_after=>options[:start_after], :reversed=>@reversed)
53
- cursor.validator do |object|
54
- object.send(@attribute_name) == attribute_value
55
- end
56
- cursor.find(options[:limit] || 100)
57
- end
58
-
59
- def write(record)
60
- @model_class.connection.insert(column_family, record.send(@attribute_name).to_s, {@attribute_name.to_s=>{new_key=>record.key.to_s}})
61
- end
62
-
63
- def remove(record)
64
- end
65
-
66
- def column_family
67
- @model_class.column_family + "By" + @attribute_name.to_s.camelize
68
- end
69
-
70
- def new_key
71
- SimpleUUID::UUID.new
72
- end
73
-
74
- def column_family_configuration
75
- {:Name=>column_family, :CompareWith=>"UTF8Type", :ColumnType=>"Super", :CompareSubcolumnsWith=>"TimeUUIDType"}
76
- end
77
-
78
- end
79
-
80
- module ClassMethods
81
- def column_family_configuration
82
- if indexes
83
- super + indexes.values.map(&:column_family_configuration)
84
- else
85
- super
86
- end
87
- end
88
-
89
- def index(attribute_name, options = {})
90
- self.indexes ||= {}.with_indifferent_access
91
- if options.delete(:unique)
92
- self.indexes[attribute_name] = UniqueIndex.new(attribute_name, self, options)
93
- class_eval <<-eom
94
- def self.find_by_#{attribute_name}(value)
95
- indexes[:#{attribute_name}].find(value)
96
- end
97
-
98
- after_save do |record|
99
- self.indexes[:#{attribute_name}].write(record)
100
- true
101
- end
102
-
103
- after_destroy do |record|
104
- record.class.indexes[:#{attribute_name}].remove(record)
105
- true
106
- end
107
- eom
108
- else
109
- self.indexes[attribute_name] = Index.new(attribute_name, self, options)
110
- class_eval <<-eom
111
- def self.find_all_by_#{attribute_name}(value, options = {})
112
- self.indexes[:#{attribute_name}].find(value, options)
113
- end
114
-
115
- after_save do |record|
116
- record.class.indexes[:#{attribute_name}].write(record)
117
- true
118
- end
119
-
120
- after_destroy do |record|
121
- record.class.indexes[:#{attribute_name}].remove(record)
122
- true
123
- end
124
- eom
125
- end
126
- end
127
- end
128
- end
129
- end