find_or_create_on_scopes 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1784f803ef131acfbeb60df1674c17cb27c094c8
4
+ data.tar.gz: 4e6f240d2fa16d2c38067623c05b2bf69643fc97
5
+ SHA512:
6
+ metadata.gz: cb641ca46f1463e26aa6c928d13744a3a1010a1f4cad80a678f4bc12adb2795b6eb211fa673178602281c8680a405c6337fd1b31c58197c5561e9da17f34d4f2
7
+ data.tar.gz: 3d88a8fedcad268bafddfd54bcd32c4b6de87d7d085016e3c3e17c2dc6f3a0a75c84855f5e8926ab23f789c2f6af37cc673a8beaf9ebe5bc3d5a150713c749e9
data/README.textile CHANGED
@@ -1,3 +1,8 @@
1
+ h1. Deprecation Notice
2
+
3
+ In Rails 3.2, the `first_or_create`, `first_or_create!`, and
4
+ `first_or_initialize` methods were introduced, obviating the need for this gem.
5
+
1
6
  h1. find_or_create_on_scopes -- Conditional creators for ActiveRecord
2
7
 
3
8
  | *Author* | Tim Morgan |
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "find_or_create_on_scopes"
8
- s.version = "1.3.0"
8
+ s.version = "1.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tim Morgan"]
12
- s.date = "2013-02-19"
12
+ s.date = "2013-07-09"
13
13
  s.description = "Adds methods to ActiveRecord for conditionally finding, creating, or updating records."
14
14
  s.email = "git@timothymorgan.info"
15
15
  s.extra_rdoc_files = [
@@ -25,11 +25,11 @@ Gem::Specification.new do |s|
25
25
  s.homepage = "http://github.com/riscfuture/find_or_create_on_scopes"
26
26
  s.require_paths = ["lib"]
27
27
  s.required_ruby_version = Gem::Requirement.new(">= 1.9")
28
- s.rubygems_version = "1.8.25"
28
+ s.rubygems_version = "2.0.3"
29
29
  s.summary = "find_or_create-type methods on ActiveRecord scopes"
30
30
 
31
31
  if s.respond_to? :specification_version then
32
- s.specification_version = 3
32
+ s.specification_version = 4
33
33
 
34
34
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
35
35
  s.add_runtime_dependency(%q<activerecord>, [">= 3.1"])
@@ -56,13 +56,13 @@ module FindOrCreateOnScopes
56
56
  def create_or_update!(*args, &block)
57
57
  create_or_update_and_do :save!, *args, &block
58
58
  end
59
-
59
+
60
60
  # Same as {#create_or_update} but does not save the record. Please note that
61
61
  # unless this method is called in a transaction, you might have a race
62
62
  # condition when trying to save the record.
63
63
  #
64
64
  # @see #create_or_update
65
-
65
+
66
66
  def initialize_or_update(*args, &block)
67
67
  create_or_update_and_do nil, *args, &block
68
68
  end
@@ -73,10 +73,27 @@ module FindOrCreateOnScopes
73
73
  record = nil
74
74
  transaction do
75
75
  record = first || new(*args)
76
- yield record if block_given? && record.new_record?
77
- record.send(meth) if meth
76
+ if record.new_record?
77
+ yield record if block_given?
78
+ record.send(meth) if meth
79
+ end
78
80
  end
79
81
  return record
82
+ rescue => err
83
+ if (defined?(Mysql2::Error) && err.kind_of?(Mysql2::Error)) ||
84
+ (defined?(PG::Error) && err.kind_of?(PG::Error)) ||
85
+ (defined?(ActiveRecord::JDBCError) && err.kind_of?(ActiveRecord::JDBCError)) ||
86
+ err.kind_of?(ActiveRecord::ActiveRecordError)
87
+ if err.to_s.include?('duplicate key value violates unique constraint') ||
88
+ err.to_s.start_with?('Duplicate entry') ||
89
+ err.kind_of?(ActiveRecord::RecordNotUnique)
90
+ retry
91
+ else
92
+ raise
93
+ end
94
+ else
95
+ raise
96
+ end
80
97
  end
81
98
 
82
99
  def create_or_update_and_do(meth, *args)
@@ -88,7 +105,22 @@ module FindOrCreateOnScopes
88
105
  record.send(meth) if meth
89
106
  end
90
107
  return record
108
+ rescue => err
109
+ if (defined?(Mysql2::Error) && err.kind_of?(Mysql2::Error)) ||
110
+ (defined?(PG::Error) && err.kind_of?(PG::Error)) ||
111
+ (defined?(ActiveRecord::JDBCError) && err.kind_of?(ActiveRecord::JDBCError)) ||
112
+ err.kind_of?(ActiveRecord::ActiveRecordError)
113
+ if err.to_s.include?('duplicate key value violates unique constraint') ||
114
+ err.to_s.start_with?('Duplicate entry') ||
115
+ err.kind_of?(ActiveRecord::RecordNotUnique)
116
+ retry
117
+ else
118
+ raise err
119
+ end
120
+ else
121
+ raise err
122
+ end
91
123
  end
92
124
  end
93
125
 
94
- ActiveRecord::Relation.send :include, FindOrCreateOnScopes
126
+ ActiveRecord::Relation.send :include, FindOrCreateOnScopes
metadata CHANGED
@@ -1,110 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: find_or_create_on_scopes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
5
- prerelease:
4
+ version: 1.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tim Morgan
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-19 00:00:00.000000000 Z
11
+ date: 2013-07-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.1'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '3.1'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: jeweler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: yard
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: RedCloth
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: sqlite3
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rspec
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  description: Adds methods to ActiveRecord for conditionally finding, creating, or
@@ -122,26 +109,25 @@ files:
122
109
  - lib/find_or_create_on_scopes.rb
123
110
  homepage: http://github.com/riscfuture/find_or_create_on_scopes
124
111
  licenses: []
112
+ metadata: {}
125
113
  post_install_message:
126
114
  rdoc_options: []
127
115
  require_paths:
128
116
  - lib
129
117
  required_ruby_version: !ruby/object:Gem::Requirement
130
- none: false
131
118
  requirements:
132
- - - ! '>='
119
+ - - '>='
133
120
  - !ruby/object:Gem::Version
134
121
  version: '1.9'
135
122
  required_rubygems_version: !ruby/object:Gem::Requirement
136
- none: false
137
123
  requirements:
138
- - - ! '>='
124
+ - - '>='
139
125
  - !ruby/object:Gem::Version
140
126
  version: '0'
141
127
  requirements: []
142
128
  rubyforge_project:
143
- rubygems_version: 1.8.25
129
+ rubygems_version: 2.0.3
144
130
  signing_key:
145
- specification_version: 3
131
+ specification_version: 4
146
132
  summary: find_or_create-type methods on ActiveRecord scopes
147
133
  test_files: []