acts_as_shardable 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a53ce6365c603eec7d28711c14a33d9d6bab72c
4
- data.tar.gz: 44125788c882a34872266fbb06ebbfa0cb5c319a
3
+ metadata.gz: 11ce4ec7bf911d8b8eb80a615a3dc81a229f93b1
4
+ data.tar.gz: 1cd6cc539c4bb61e219e6d7e402b8accc75306ac
5
5
  SHA512:
6
- metadata.gz: db91ff73979130de3fdbe871450d068d7133432fda696f4cc23dd9df9080c22bb37389009cd8665a6f1db467f8b180462150f29f1c61fadcf1959f62aeb8030e
7
- data.tar.gz: fe6a36d12c538aa7e7cc0d9f323b37f2d9152274821d2e4c8d8e00a1769a8c40fb1efb578ea067c1e37db87a890754aecc753c83086f7154fd268ea74ef13fb4
6
+ metadata.gz: dea62a56bb346fe1616ca09af42773fec5fdf871b74371dcedfe7ed974d7e29f94a20981fa97bfd5c0778fe18e58d62a547a59c9a21ef0be11e335dab7692cd0
7
+ data.tar.gz: 7b1798568e693b7dcf7d05e723df46b1b641a3892570418a531bf18b488b5c2eeebecb9044d6e9726be5b04109eb4eb680b0c0d0b9f788d07654be24c46aad34
@@ -32,5 +32,5 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'minitest', '~> 5.0'
33
33
  spec.add_development_dependency 'sqlite3', '~> 1.0'
34
34
 
35
- spec.add_dependency 'activerecord', '~> 4.0'
35
+ spec.add_dependency 'activerecord', '>= 4.2'
36
36
  end
@@ -24,6 +24,7 @@ module ActsAsShardable
24
24
  # Updates the associated record with values matching those of the instance attributes.
25
25
  # Returns the number of affected rows.
26
26
  define_method :_update_record do |attribute_names = self.attribute_names|
27
+ attribute_names = keys_for_partial_write if self.class.base_class.partial_writes
27
28
 
28
29
  was, is = changes[self.class.base_class.shard_method]
29
30
 
@@ -66,19 +67,26 @@ module ActsAsShardable
66
67
  raise
67
68
  end
68
69
  else
69
- attribute_names = attributes_for_update(attribute_names)
70
-
71
- attributes_values = {}
72
- arel_table = shard.arel_table
70
+ if self.respond_to?(:attributes_with_values_for_update, true)
71
+ attributes_values = attributes_with_values_for_update(attribute_names)
72
+ else
73
+ attribute_names = attributes_for_update(attribute_names)
74
+ attributes_values = {}
75
+ arel_table = shard.arel_table
73
76
 
74
- attribute_names.each do |name|
75
- attributes_values[arel_table[name]] = typecasted_attribute_value(name)
77
+ attribute_names.each do |name|
78
+ attributes_values[arel_table[name]] = typecasted_attribute_value(name)
79
+ end
76
80
  end
77
81
 
78
82
  if attributes_values.empty?
79
83
  0
80
84
  else
81
- shard.unscoped._update_record attributes_values, id, id_was
85
+ if ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR >= 1
86
+ shard.unscoped._update_record(attributes_values, self.class.base_class.primary_key => id_in_database)
87
+ else
88
+ shard.unscoped._update_record(attributes_values, id, id_was)
89
+ end
82
90
  end
83
91
  end
84
92
  end
@@ -102,7 +110,16 @@ module ActsAsShardable
102
110
  changes[column] = write_attribute(column, current_time)
103
111
  end
104
112
 
105
- changes[self.class.locking_column] = increment_lock if locking_enabled?
113
+ if locking_enabled?
114
+ if self.respond_to?(:increment_lock)
115
+ changes[self.class.base_class.locking_column] = increment_lock
116
+ else
117
+ lock_col = self.class.base_class.locking_column
118
+ previous_lock_value = read_attribute(lock_col)
119
+ self[lock_col] = previous_lock_value + 1
120
+ changes[lock_col] = self[lock_col]
121
+ end
122
+ end
106
123
 
107
124
  clear_attribute_changes(changes.keys)
108
125
  primary_key = self.class.primary_key
@@ -115,13 +132,27 @@ module ActsAsShardable
115
132
  # Creates a record with values matching those of the instance attributes
116
133
  # and returns its id.
117
134
  define_method :_create_record do |attribute_names = self.attribute_names|
118
- attributes_values = arel_attributes_with_values_for_create(attribute_names)
135
+ _run_create_callbacks {
136
+ attribute_names = keys_for_partial_write if self.class.base_class.partial_writes
137
+ attribute_names |= [self.class.base_class.locking_column] if locking_enabled?
119
138
 
120
- new_id = shard.unscoped.insert attributes_values
121
- self.id ||= new_id if self.class.base_class.primary_key
139
+ if self.respond_to?(:attributes_with_values_for_create, true)
140
+ attributes_values = attributes_with_values_for_create(attribute_names)
141
+ else
142
+ attributes_values = arel_attributes_with_values_for_create(attribute_names)
143
+ end
122
144
 
123
- @new_record = false
124
- id
145
+ if shard.respond_to?(:_insert_record)
146
+ new_id = shard.unscoped._insert_record attributes_values
147
+ else
148
+ new_id = shard.unscoped.insert attributes_values
149
+ end
150
+
151
+ self.id ||= new_id if self.class.base_class.primary_key
152
+
153
+ @new_record = false
154
+ id
155
+ }
125
156
  end
126
157
 
127
158
  private :_create_record
@@ -1,3 +1,3 @@
1
1
  module ActsAsShardable
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_shardable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - scorix
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-16 00:00:00.000000000 Z
11
+ date: 2018-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: activerecord
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '4.0'
75
+ version: '4.2'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '4.0'
82
+ version: '4.2'
83
83
  description: Let subclasses of ActiveRecord::Base to be shardable.
84
84
  email:
85
85
  - scorix@gmail.com
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  requirements: []
121
121
  rubyforge_project:
122
- rubygems_version: 2.4.5.1
122
+ rubygems_version: 2.6.11
123
123
  signing_key:
124
124
  specification_version: 4
125
125
  summary: Let subclasses of ActiveRecord::Base to be shardable.