delta_attributes 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -11,13 +11,13 @@
11
11
  It replaces it with
12
12
 
13
13
  UPDATE users
14
- SET money = money + d
14
+ SET money = money + delta
15
15
  WHERE id = 1;
16
16
 
17
- where d is difference between old value and new value of that field.
17
+ where delta is difference between old value and new value of that field.
18
18
 
19
19
  This solves problem with simultaneous updating of same field by different threads
20
- without locking record.
20
+ without locking record (problem known as race condition http://en.wikipedia.org/wiki/Race_condition).
21
21
 
22
22
  ## Installation
23
23
 
@@ -35,7 +35,7 @@ Or install it yourself as:
35
35
 
36
36
  ## Usage
37
37
 
38
- To mark numeric field to be updated by "field = field + d" way you just need to add field
38
+ To mark numeric field to be updated by "field = field + delta" way you just need to add field
39
39
  name to delta_attributes like this:
40
40
 
41
41
  class User < ActiveRecord::Base
@@ -50,11 +50,35 @@ Or install it yourself as:
50
50
  u.money = 5
51
51
  u.save
52
52
 
53
- will generate
53
+ rails will generate
54
54
 
55
55
  UPDATE users SET money = money + 2 where id = 1
56
56
 
57
- Tested with rails 3.2.0, 3.2.8, 3.2.9.
57
+ and if
58
+
59
+ u = User.first # money = 5, id = 1
60
+ u.money = 1
61
+ u.money += 3
62
+ u.save
63
+
64
+ rails will generate
65
+
66
+ UPDATE users SET money = money - 1 where id = 1
67
+
68
+ You can use any operations with numeric field like:
69
+
70
+ u.money -= 10
71
+
72
+ u.money += 7
73
+
74
+ u.money = u.money * 2
75
+
76
+ etc.
77
+
78
+ It doesn't matter as delta is calculated as difference between original value received from database and new value
79
+ before update.
80
+
81
+ Tested with rails 3.1.0, 3.2.0, 3.2.8, 3.2.9.
58
82
 
59
83
  ## Contributing
60
84
 
@@ -6,7 +6,7 @@ require 'delta_attributes/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "delta_attributes"
8
8
  gem.version = DeltaAttributes::VERSION
9
- gem.authors = ["Oleh Novosad, Yuriy Lavryk, Arya"]
9
+ gem.authors = ["Oleh (izbor) Novosad, Yuriy Lavryk, Arya"]
10
10
  gem.email = ["oleh.novosad@gmail.com"]
11
11
  gem.description = %q{
12
12
  This gem makes updating specified number fields by ActiveRecord in unusual way.
@@ -20,12 +20,13 @@ Gem::Specification.new do |gem|
20
20
  It replaces it with
21
21
 
22
22
  UPDATE users
23
- SET money = money + d
23
+ SET money = money + delta
24
24
  WHERE id = 1;
25
25
 
26
- where d is difference between old value and new value of that field.
26
+ where delta is difference between old value and new value of that field.
27
27
 
28
- This solves problem with simultaneous updating of the same field by different threads.
28
+ This solves problem with simultaneous updating of the same field by different threads
29
+ (problem known as race condition).
29
30
 
30
31
  Source code: https://github.com/izbor/delta_attributes
31
32
  }
@@ -36,5 +37,5 @@ Gem::Specification.new do |gem|
36
37
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
37
38
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
38
39
  gem.require_paths = ["lib"]
39
- gem.add_dependency "rails", "~> 3.2.0"
40
+ gem.add_dependency "rails", ">= 3.1.0"
40
41
  end
@@ -14,16 +14,6 @@ module Arel
14
14
  ].compact.join ' '
15
15
  end
16
16
 
17
- # original
18
- #def visit_Arel_Nodes_UpdateStatement o
19
- # [
20
- # "UPDATE #{visit o.relation}",
21
- # ("SET #{o.values.map { |value| visit value }.join ', '}" unless o.values.empty?),
22
- # ("WHERE #{o.wheres.map { |x| visit x }.join ' AND '}" unless o.wheres.empty?),
23
- # ("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
24
- # (visit(o.limit) if o.limit),
25
- # ].compact.join ' '
26
- #end
27
17
  end
28
18
  end
29
19
  end
@@ -1,3 +1,3 @@
1
1
  module DeltaAttributes
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -18,8 +18,6 @@ module Arel
18
18
  retry
19
19
  end
20
20
 
21
- #alias_method_chain :visit, :delta_attribute
22
-
23
21
  alias_method :visit_without_delta_attribute, :visit
24
22
  alias_method :visit, :visit_with_delta_attribute
25
23
  end
metadata CHANGED
@@ -1,21 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delta_attributes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
- - Oleh Novosad, Yuriy Lavryk, Arya
13
+ - Oleh (izbor) Novosad, Yuriy Lavryk, Arya
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-20 00:00:00 +02:00
18
+ date: 2012-11-21 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,17 +24,17 @@ dependencies:
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 15
29
+ hash: 3
30
30
  segments:
31
31
  - 3
32
- - 2
32
+ - 1
33
33
  - 0
34
- version: 3.2.0
34
+ version: 3.1.0
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
- description: "\n This gem makes updating specified number fields by ActiveRecord in unusual way.\n\n Instead of generating sql script to update value in usual way like this:\n\n UPDATE users\n SET money = 10\n WHERE id = 1;\n\n It replaces it with\n\n UPDATE users\n SET money = money + d\n WHERE id = 1;\n\n where d is difference between old value and new value of that field.\n\n This solves problem with simultaneous updating of the same field by different threads.\n\n Source code: https://github.com/izbor/delta_attributes\n "
37
+ description: "\n This gem makes updating specified number fields by ActiveRecord in unusual way.\n\n Instead of generating sql script to update value in usual way like this:\n\n UPDATE users\n SET money = 10\n WHERE id = 1;\n\n It replaces it with\n\n UPDATE users\n SET money = money + delta\n WHERE id = 1;\n\n where delta is difference between old value and new value of that field.\n\n This solves problem with simultaneous updating of the same field by different threads\n (problem known as race condition).\n\n Source code: https://github.com/izbor/delta_attributes\n "
38
38
  email:
39
39
  - oleh.novosad@gmail.com
40
40
  executables: []