datastax_rails 2.0.12 → 2.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +5 -5
- data/lib/blankslate.rb +8 -11
- data/lib/cql-rb_extensions.rb +5 -3
- data/lib/datastax_rails/associations/association.rb +93 -101
- data/lib/datastax_rails/associations/association_scope.rb +7 -7
- data/lib/datastax_rails/associations/belongs_to_association.rb +46 -48
- data/lib/datastax_rails/associations/builder/association.rb +32 -31
- data/lib/datastax_rails/associations/builder/belongs_to.rb +19 -20
- data/lib/datastax_rails/associations/builder/collection_association.rb +32 -32
- data/lib/datastax_rails/associations/builder/has_and_belongs_to_many.rb +21 -21
- data/lib/datastax_rails/associations/builder/has_many.rb +39 -40
- data/lib/datastax_rails/associations/builder/has_one.rb +30 -31
- data/lib/datastax_rails/associations/builder/singular_association.rb +31 -33
- data/lib/datastax_rails/associations/collection_association.rb +129 -135
- data/lib/datastax_rails/associations/collection_proxy.rb +21 -21
- data/lib/datastax_rails/associations/has_and_belongs_to_many_association.rb +26 -26
- data/lib/datastax_rails/associations/has_many_association.rb +38 -38
- data/lib/datastax_rails/associations/has_one_association.rb +31 -32
- data/lib/datastax_rails/associations/singular_association.rb +31 -30
- data/lib/datastax_rails/associations.rb +27 -24
- data/lib/datastax_rails/attribute_assignment.rb +17 -17
- data/lib/datastax_rails/attribute_methods/definition.rb +4 -4
- data/lib/datastax_rails/attribute_methods/dirty.rb +34 -33
- data/lib/datastax_rails/attribute_methods/primary_key.rb +3 -8
- data/lib/datastax_rails/attribute_methods/read.rb +10 -12
- data/lib/datastax_rails/attribute_methods/typecasting.rb +36 -35
- data/lib/datastax_rails/attribute_methods/write.rb +5 -6
- data/lib/datastax_rails/attribute_methods.rb +52 -56
- data/lib/datastax_rails/base.rb +122 -125
- data/lib/datastax_rails/callbacks.rb +15 -9
- data/lib/datastax_rails/cassandra_only_model.rb +6 -6
- data/lib/datastax_rails/collection.rb +5 -7
- data/lib/datastax_rails/column.rb +130 -118
- data/lib/datastax_rails/connection/statement_cache.rb +3 -3
- data/lib/datastax_rails/connection.rb +42 -33
- data/lib/datastax_rails/cql/alter_column_family.rb +19 -21
- data/lib/datastax_rails/cql/base.rb +8 -11
- data/lib/datastax_rails/cql/column_family.rb +11 -10
- data/lib/datastax_rails/cql/consistency.rb +2 -2
- data/lib/datastax_rails/cql/create_column_family.rb +15 -15
- data/lib/datastax_rails/cql/create_index.rb +5 -5
- data/lib/datastax_rails/cql/create_keyspace.rb +7 -7
- data/lib/datastax_rails/cql/delete.rb +16 -29
- data/lib/datastax_rails/cql/drop_column_family.rb +2 -2
- data/lib/datastax_rails/cql/drop_index.rb +2 -2
- data/lib/datastax_rails/cql/drop_keyspace.rb +2 -2
- data/lib/datastax_rails/cql/insert.rb +10 -16
- data/lib/datastax_rails/cql/select.rb +21 -33
- data/lib/datastax_rails/cql/truncate.rb +2 -2
- data/lib/datastax_rails/cql/update.rb +16 -24
- data/lib/datastax_rails/cql/use_keyspace.rb +2 -2
- data/lib/datastax_rails/cql.rb +2 -2
- data/lib/datastax_rails/dynamic_model.rb +32 -29
- data/lib/datastax_rails/errors.rb +6 -6
- data/lib/datastax_rails/grouped_collection.rb +3 -3
- data/lib/datastax_rails/inheritance.rb +9 -9
- data/lib/datastax_rails/payload_model.rb +24 -20
- data/lib/datastax_rails/persistence.rb +116 -110
- data/lib/datastax_rails/railtie.rb +7 -7
- data/lib/datastax_rails/reflection.rb +61 -59
- data/lib/datastax_rails/relation/batches.rb +12 -13
- data/lib/datastax_rails/relation/facet_methods.rb +44 -33
- data/lib/datastax_rails/relation/finder_methods.rb +95 -91
- data/lib/datastax_rails/relation/modification_methods.rb +5 -5
- data/lib/datastax_rails/relation/search_methods.rb +102 -102
- data/lib/datastax_rails/relation/spawn_methods.rb +25 -24
- data/lib/datastax_rails/relation/stats_methods.rb +9 -8
- data/lib/datastax_rails/relation.rb +165 -170
- data/lib/datastax_rails/rsolr_client_wrapper.rb +3 -3
- data/lib/datastax_rails/schema/cassandra.rb +44 -43
- data/lib/datastax_rails/schema/migrator.rb +52 -52
- data/lib/datastax_rails/schema/solr.rb +55 -47
- data/lib/datastax_rails/schema_cache.rb +1 -3
- data/lib/datastax_rails/scoping/default.rb +2 -3
- data/lib/datastax_rails/scoping/named.rb +3 -5
- data/lib/datastax_rails/scoping.rb +11 -12
- data/lib/datastax_rails/serialization.rb +34 -31
- data/lib/datastax_rails/serializers/xml_serializer.rb +178 -175
- data/lib/datastax_rails/timestamps.rb +4 -4
- data/lib/datastax_rails/types/dirty_collection.rb +57 -57
- data/lib/datastax_rails/types/dynamic_list.rb +1 -1
- data/lib/datastax_rails/types/dynamic_map.rb +5 -7
- data/lib/datastax_rails/types/dynamic_set.rb +2 -2
- data/lib/datastax_rails/util/solr_repair.rb +3 -3
- data/lib/datastax_rails/validations/associated.rb +8 -6
- data/lib/datastax_rails/validations/uniqueness.rb +8 -8
- data/lib/datastax_rails/validations.rb +9 -10
- data/lib/datastax_rails/version.rb +2 -1
- data/lib/datastax_rails/wide_storage_model.rb +6 -6
- data/lib/datastax_rails.rb +13 -9
- data/lib/schema_migration.rb +3 -3
- data/spec/datastax_rails/associations/belongs_to_association_spec.rb +2 -2
- data/spec/datastax_rails/associations/collection_association_spec.rb +14 -14
- data/spec/datastax_rails/associations/has_many_association_spec.rb +20 -20
- data/spec/datastax_rails/associations_spec.rb +11 -11
- data/spec/datastax_rails/attribute_methods_spec.rb +25 -25
- data/spec/datastax_rails/base_spec.rb +24 -24
- data/spec/datastax_rails/callbacks_spec.rb +21 -21
- data/spec/datastax_rails/column_spec.rb +133 -132
- data/spec/datastax_rails/connection/statement_cache_spec.rb +2 -2
- data/spec/datastax_rails/cql/base_spec.rb +4 -4
- data/spec/datastax_rails/cql/delete_spec.rb +19 -0
- data/spec/datastax_rails/cql/select_spec.rb +8 -8
- data/spec/datastax_rails/cql/update_spec.rb +8 -10
- data/spec/datastax_rails/dynamic_model_spec.rb +36 -22
- data/spec/datastax_rails/inheritance_spec.rb +11 -14
- data/spec/datastax_rails/persistence_spec.rb +73 -74
- data/spec/datastax_rails/relation/batches_spec.rb +13 -13
- data/spec/datastax_rails/relation/facet_methods_spec.rb +43 -35
- data/spec/datastax_rails/relation/finder_methods_spec.rb +77 -78
- data/spec/datastax_rails/relation/modification_methods_spec.rb +19 -19
- data/spec/datastax_rails/relation/search_methods_spec.rb +160 -160
- data/spec/datastax_rails/relation/spawn_methods_spec.rb +18 -18
- data/spec/datastax_rails/relation_spec.rb +119 -116
- data/spec/datastax_rails/schema/migrator_spec.rb +30 -30
- data/spec/datastax_rails/schema/solr_spec.rb +15 -15
- data/spec/datastax_rails/scoping/default_spec.rb +9 -9
- data/spec/datastax_rails/types/dynamic_list_spec.rb +12 -12
- data/spec/datastax_rails/types/dynamic_map_spec.rb +10 -10
- data/spec/datastax_rails/types/dynamic_set_spec.rb +22 -10
- data/spec/datastax_rails/validations/uniqueness_spec.rb +25 -25
- data/spec/datastax_rails/wide_storage_model_spec.rb +11 -0
- data/spec/datastax_rails_spec.rb +2 -2
- data/spec/dummy/config/application.rb +2 -3
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environments/development.rb +3 -3
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/spec/factories/audit_logs.rb +6 -0
- data/spec/factories/hobbies.rb +6 -0
- data/spec/factories/people.rb +5 -0
- data/spec/feature/dynamic_fields_spec.rb +4 -4
- data/spec/feature/overloaded_tables_spec.rb +11 -12
- data/spec/spec_helper.rb +17 -14
- data/spec/support/datastax_test_hook.rb +2 -2
- data/spec/support/default_consistency_shared_examples.rb +11 -11
- data/spec/support/models.rb +31 -32
- metadata +40 -6
- data/lib/datastax_rails/attribute_methods/before_type_cast.rb +0 -71
- data/lib/datastax_rails/log_subscriber.rb +0 -0
- data/spec/dummy/ks/migrate/20111117224534_models.rb +0 -20
@@ -1,30 +1,30 @@
|
|
1
|
-
module DatastaxRails#:nodoc:
|
1
|
+
module DatastaxRails #:nodoc:
|
2
2
|
module Cql #:nodoc:
|
3
3
|
class CreateKeyspace < Base #:nodoc:
|
4
4
|
def initialize(ks_name)
|
5
5
|
@ks_name = ks_name
|
6
6
|
@strategy_options = {}
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def strategy_class(sc)
|
10
10
|
@strategy_class = sc
|
11
11
|
self
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def strategy_options(so)
|
15
15
|
@strategy_options.merge!(so)
|
16
16
|
self
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def to_cql
|
20
20
|
stmt = "CREATE KEYSPACE #{@ks_name} WITH REPLICATION = {'class' : '#{@strategy_class}'"
|
21
|
-
|
21
|
+
|
22
22
|
@strategy_options.each do |key, value|
|
23
|
-
stmt << ", '#{key
|
23
|
+
stmt << ", '#{key}' : '#{value}'"
|
24
24
|
end
|
25
25
|
stmt << '}'
|
26
26
|
stmt
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
@@ -1,53 +1,40 @@
|
|
1
1
|
module DatastaxRails
|
2
2
|
module Cql
|
3
|
+
# Generates CQL to delete a record from Cassandra
|
3
4
|
class Delete < Base
|
4
|
-
def initialize(klass,
|
5
|
+
def initialize(klass, key)
|
5
6
|
@klass = klass
|
6
|
-
@
|
7
|
+
@key = key
|
7
8
|
@timestamp = nil
|
8
9
|
@columns = []
|
9
|
-
@conditions = {}
|
10
|
-
@key_name = @klass.primary_key
|
11
10
|
super
|
12
11
|
end
|
13
|
-
|
12
|
+
|
14
13
|
def columns(columns)
|
15
14
|
@columns = columns
|
16
15
|
self
|
17
16
|
end
|
18
|
-
|
19
|
-
def conditions(conditions)
|
20
|
-
@conditions.merge!(conditions)
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
17
|
+
|
24
18
|
def timestamp(timestamp)
|
25
19
|
@timestamp = timestamp
|
26
20
|
self
|
27
21
|
end
|
28
|
-
|
29
|
-
def key_name(key_name)
|
30
|
-
@key_name = key_name
|
31
|
-
self
|
32
|
-
end
|
33
|
-
|
22
|
+
|
34
23
|
def to_cql
|
35
|
-
@values =
|
24
|
+
@values = []
|
36
25
|
stmt = "DELETE #{@columns.join(',')} FROM #{@klass.column_family} "
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
stmt << "WHERE \"#{@key_name}\" IN (?)"
|
43
|
-
|
44
|
-
@conditions.each do |col,val|
|
45
|
-
stmt << " AND #{col} = ?"
|
26
|
+
stmt << "AND TIMESTAMP #{@timestamp} " if @timestamp
|
27
|
+
conditions = []
|
28
|
+
|
29
|
+
@key.each do |col, val|
|
30
|
+
conditions << "\"#{col}\" = ?"
|
46
31
|
@values << val
|
47
32
|
end
|
48
|
-
|
33
|
+
|
34
|
+
stmt << "WHERE #{conditions.join(' AND ')}"
|
35
|
+
|
49
36
|
stmt
|
50
37
|
end
|
51
38
|
end
|
52
39
|
end
|
53
|
-
end
|
40
|
+
end
|
@@ -8,40 +8,34 @@ module DatastaxRails
|
|
8
8
|
@columns = {}
|
9
9
|
super
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def columns(columns)
|
13
13
|
@columns.merge!(columns)
|
14
14
|
self
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def ttl(ttl)
|
18
18
|
@ttl = ttl
|
19
19
|
self
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def timestamp(timestamp)
|
23
23
|
@timestamp = timestamp
|
24
24
|
self
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def to_cql
|
28
28
|
keys = []
|
29
|
-
@columns.each do |k,v|
|
29
|
+
@columns.each do |k, v|
|
30
30
|
keys << k.to_s
|
31
31
|
@values << v
|
32
32
|
end
|
33
|
-
stmt =
|
34
|
-
|
35
|
-
if
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
if(@timestamp)
|
40
|
-
stmt << "AND TIMESTAMP #{@timestamp}"
|
41
|
-
end
|
42
|
-
|
33
|
+
stmt = "INSERT INTO #{@klass.column_family} (#{keys.join(',')}) "
|
34
|
+
stmt << "VALUES (#{('?' * keys.size).split(//).join(',')}) "
|
35
|
+
stmt << "AND TTL #{@ttl} " if @ttl
|
36
|
+
stmt << "AND TIMESTAMP #{@timestamp}" if @timestamp
|
43
37
|
stmt.force_encoding('UTF-8')
|
44
38
|
end
|
45
39
|
end
|
46
40
|
end
|
47
|
-
end
|
41
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module DatastaxRails#:nodoc:
|
1
|
+
module DatastaxRails #:nodoc:
|
2
2
|
module Cql #:nodoc:
|
3
3
|
class Select < Base #:nodoc:
|
4
4
|
def initialize(klass, select)
|
5
5
|
@klass = klass
|
6
|
-
@select = select.join(
|
6
|
+
@select = select.join(',')
|
7
7
|
@limit = nil
|
8
8
|
@conditions = {}
|
9
9
|
@order = nil
|
@@ -11,74 +11,62 @@ module DatastaxRails#:nodoc:
|
|
11
11
|
@allow_filtering = nil
|
12
12
|
super
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def allow_filtering
|
16
16
|
@allow_filtering = true
|
17
17
|
self
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
def using(consistency)
|
21
21
|
@consistency = consistency
|
22
22
|
self
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def paginate(start)
|
26
26
|
@paginate = start
|
27
27
|
self
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def conditions(conditions)
|
31
31
|
@conditions.merge!(conditions)
|
32
32
|
self
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def limit(limit)
|
36
36
|
@limit = limit
|
37
37
|
self
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def order(order)
|
41
41
|
@order = order
|
42
42
|
self
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def to_cql
|
46
46
|
conditions = []
|
47
47
|
stmt = "SELECT #{@select} FROM #{@klass.column_family} "
|
48
|
-
|
48
|
+
|
49
49
|
if @paginate
|
50
50
|
conditions << "token(#{@klass.primary_key}) > token(?)"
|
51
51
|
@values << @paginate
|
52
52
|
end
|
53
|
-
|
54
|
-
@conditions.each do |k,v|
|
55
|
-
if v.
|
56
|
-
conditions << "\"#{k
|
53
|
+
|
54
|
+
@conditions.each do |k, v|
|
55
|
+
if v.is_a?(Array)
|
56
|
+
conditions << "\"#{k}\" IN (#{('?' * v.size).split(//).join(',')})"
|
57
57
|
@values += v
|
58
58
|
else
|
59
|
-
conditions << "\"#{k
|
59
|
+
conditions << "\"#{k}\" = ?"
|
60
60
|
@values << v
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
64
|
-
unless conditions.empty?
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
if @order
|
69
|
-
stmt << "ORDER BY #{@order} "
|
70
|
-
end
|
71
|
-
|
72
|
-
if @limit
|
73
|
-
stmt << "LIMIT #{@limit} "
|
74
|
-
end
|
75
|
-
|
76
|
-
if @allow_filtering
|
77
|
-
stmt << "ALLOW FILTERING "
|
78
|
-
end
|
79
|
-
|
63
|
+
|
64
|
+
stmt << "WHERE #{conditions.join(' AND ')} " unless conditions.empty?
|
65
|
+
stmt << "ORDER BY #{@order} " if @order
|
66
|
+
stmt << "LIMIT #{@limit} " if @limit
|
67
|
+
stmt << 'ALLOW FILTERING ' if @allow_filtering
|
80
68
|
stmt
|
81
69
|
end
|
82
70
|
end
|
83
71
|
end
|
84
|
-
end
|
72
|
+
end
|
@@ -7,58 +7,50 @@ module DatastaxRails
|
|
7
7
|
@columns = {}
|
8
8
|
super
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def columns(columns)
|
12
12
|
@columns.merge!(columns)
|
13
13
|
self
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def limit(limit)
|
17
17
|
@limit = limit
|
18
18
|
self
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def ttl(ttl)
|
22
22
|
@ttl = ttl
|
23
23
|
self
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def timestamp(timestamp)
|
27
27
|
@timestamp = timestamp
|
28
28
|
self
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def to_cql
|
32
|
-
column_names = @columns.keys
|
33
|
-
|
34
32
|
stmt = "update #{@klass.column_family} "
|
35
|
-
|
36
|
-
if
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
if(@timestamp)
|
41
|
-
stmt << "AND TIMESTAMP #{@timestamp}"
|
42
|
-
end
|
43
|
-
|
33
|
+
stmt << "AND TTL #{@ttl} " if @ttl
|
34
|
+
stmt << "AND TIMESTAMP #{@timestamp}" if @timestamp
|
35
|
+
|
44
36
|
unless @columns.empty?
|
45
|
-
stmt <<
|
37
|
+
stmt << 'SET '
|
46
38
|
updates = []
|
47
|
-
@columns.each do |k,v|
|
39
|
+
@columns.each do |k, v|
|
48
40
|
@values << v
|
49
41
|
updates << "\"#{k}\" = ?"
|
50
42
|
end
|
51
|
-
|
52
|
-
stmt << updates.join(
|
43
|
+
|
44
|
+
stmt << updates.join(', ')
|
53
45
|
end
|
54
46
|
conditions = []
|
55
|
-
@key.each do |k,v|
|
56
|
-
conditions << "\"#{k
|
47
|
+
@key.each do |k, v|
|
48
|
+
conditions << "\"#{k}\" = ?"
|
57
49
|
@values << v
|
58
50
|
end
|
59
|
-
stmt << " WHERE #{conditions.join(
|
51
|
+
stmt << " WHERE #{conditions.join(' AND ')}"
|
60
52
|
stmt.force_encoding('UTF-8')
|
61
53
|
end
|
62
54
|
end
|
63
55
|
end
|
64
|
-
end
|
56
|
+
end
|
data/lib/datastax_rails/cql.rb
CHANGED
@@ -7,7 +7,7 @@ module DatastaxRails
|
|
7
7
|
@cql[klass] ||= DatastaxRails::Cql::ColumnFamily.new(klass)
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
autoload :AlterColumnFamily
|
12
12
|
autoload :Base
|
13
13
|
autoload :ColumnFamily
|
@@ -25,4 +25,4 @@ module DatastaxRails
|
|
25
25
|
autoload :Update
|
26
26
|
autoload :UseKeyspace
|
27
27
|
end
|
28
|
-
end
|
28
|
+
end
|
@@ -31,7 +31,7 @@ module DatastaxRails
|
|
31
31
|
# exception of timestamps, it is simply the first letter of the type
|
32
32
|
# followed by an underscore (_). So s_ for strings. Timestamp has a
|
33
33
|
# ts_ prefix to differentiate it from texts.
|
34
|
-
#
|
34
|
+
#
|
35
35
|
# class Item < DatastaxRails::DynamicModel
|
36
36
|
# self.grouping = 'item'
|
37
37
|
# timestamps
|
@@ -77,75 +77,78 @@ module DatastaxRails
|
|
77
77
|
# assist with search.
|
78
78
|
class DynamicModel < WideStorageModel
|
79
79
|
self.abstract_class = true
|
80
|
-
|
81
|
-
PREFIXES = {string: :s_, text: :t_, boolean: :b_, date: :d_,
|
82
|
-
|
83
|
-
|
80
|
+
|
81
|
+
PREFIXES = { string: :s_, text: :t_, boolean: :b_, date: :d_,
|
82
|
+
timestamp: :ts_, integer: :i_, float: :f_, uuid: :u_ }.with_indifferent_access
|
83
|
+
|
84
84
|
class_attribute :group_by_attribute
|
85
85
|
class_attribute :virtual_attributes
|
86
|
-
|
86
|
+
|
87
87
|
class << self
|
88
88
|
def grouping=(group)
|
89
89
|
self.group_by_attribute = group
|
90
|
-
|
91
|
-
default_scope -> {where('group' => group)}
|
90
|
+
attribute_definitions['group'].default = group
|
91
|
+
default_scope -> { where('group' => group) }
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
alias_method :_attribute, :attribute
|
95
|
-
|
95
|
+
|
96
96
|
def attribute(name, options)
|
97
97
|
options.symbolize_keys!
|
98
|
-
unless [:map
|
98
|
+
unless [:map, :list, :set].include?(options[:type].to_sym)
|
99
99
|
# Only type supported for now
|
100
100
|
options.assert_valid_keys(:type)
|
101
|
-
|
102
|
-
|
101
|
+
unless PREFIXES.key?(options[:type])
|
102
|
+
fail(ArgumentError, "Invalid type specified for dynamic attribute: '#{name}: #{options[:type]}'")
|
103
|
+
end
|
104
|
+
virtual_attributes[name.to_s] = PREFIXES[options[:type]].to_s + name.to_s
|
103
105
|
end
|
104
106
|
super
|
105
107
|
end
|
106
|
-
|
108
|
+
|
107
109
|
def inherited(child)
|
108
110
|
super
|
109
|
-
child.virtual_attributes =
|
111
|
+
child.virtual_attributes =
|
112
|
+
child.virtual_attributes.nil? ? {}.with_indifferent_access : child.virtual_attributes.dup
|
110
113
|
child.column_family = 'dynamic_model'
|
111
114
|
child.primary_key = 'id'
|
112
115
|
child.cluster_by = 'group'
|
113
|
-
child._attribute :id, :
|
114
|
-
child._attribute :group, :
|
115
|
-
PREFIXES.each do |k,v|
|
116
|
+
child._attribute :id, type: :uuid
|
117
|
+
child._attribute :group, type: :string
|
118
|
+
PREFIXES.each do |k, v|
|
116
119
|
child._attribute v, holds: k.to_sym, type: :map
|
117
|
-
child.instance_eval { alias_attribute k.to_s.pluralize, v}
|
120
|
+
child.instance_eval { alias_attribute k.to_s.pluralize, v }
|
118
121
|
end
|
119
122
|
end
|
120
|
-
|
123
|
+
|
121
124
|
def solr_field_name(attr, type = nil)
|
122
|
-
type ||=
|
123
|
-
|
124
|
-
|
125
|
+
type ||= attribute_definitions[attr].try(:type)
|
126
|
+
fail(UnknownAttributeError, 'Collections cannot be mapped') if [:map, :list, :set].include?(type)
|
127
|
+
fail(UnknownAttributeError, "Unknown attribute: #{attr}. You must specify a type.") unless type
|
125
128
|
PREFIXES[type].to_s + attr.to_s
|
126
129
|
end
|
127
130
|
end
|
128
|
-
|
131
|
+
|
129
132
|
def write_attribute(attr_name, val)
|
130
133
|
if virtual_attributes.include?(attr_name.to_s)
|
131
134
|
type = self.class.attribute_definitions[attr_name].type
|
132
|
-
|
135
|
+
send(PREFIXES[type])[attr_name] = val
|
133
136
|
else
|
134
137
|
super
|
135
138
|
end
|
136
139
|
end
|
137
|
-
|
140
|
+
|
138
141
|
def read_attribute(attr_name)
|
139
142
|
if virtual_attributes.include?(attr_name.to_s)
|
140
143
|
type = self.class.attribute_definitions[attr_name].type
|
141
|
-
|
144
|
+
send(PREFIXES[type])[attr_name]
|
142
145
|
else
|
143
146
|
super
|
144
147
|
end
|
145
148
|
end
|
146
|
-
|
149
|
+
|
147
150
|
def solr_field_name(attr, type = nil)
|
148
151
|
self.class.solr_field_name(attr, type)
|
149
152
|
end
|
150
153
|
end
|
151
|
-
end
|
154
|
+
end
|