find_or_create_on_scopes 1.4.0 → 1.4.1

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: 1784f803ef131acfbeb60df1674c17cb27c094c8
4
- data.tar.gz: 4e6f240d2fa16d2c38067623c05b2bf69643fc97
3
+ metadata.gz: e21b0d1d5374b9b0a8083be5c6caf98e6f976c9e
4
+ data.tar.gz: dcdf412fc3ebf6d9d9ede925559a0d313465e81b
5
5
  SHA512:
6
- metadata.gz: cb641ca46f1463e26aa6c928d13744a3a1010a1f4cad80a678f4bc12adb2795b6eb211fa673178602281c8680a405c6337fd1b31c58197c5561e9da17f34d4f2
7
- data.tar.gz: 3d88a8fedcad268bafddfd54bcd32c4b6de87d7d085016e3c3e17c2dc6f3a0a75c84855f5e8926ab23f789c2f6af37cc673a8beaf9ebe5bc3d5a150713c749e9
6
+ metadata.gz: c55f6f6afeb8540e399b9ebb0a6ec3d4dc493e09c98474e9f0bc938ec2c6c195ce5d36dc13078221dffa119a0202d5be75dfff05e05c89ebf335f0a1fd79db33
7
+ data.tar.gz: d3cf7432aa4b9f85cc090ca4dcee951b5b0f63323844a66551273e8cee49640a4b2d393ae6cdff0220effb6e5de8bb47bb0196158f1b7fc1a27149e04743726d
@@ -1,40 +1,43 @@
1
- h1. Deprecation Notice
1
+ find_or_create_on_scopes
2
+ ========================
2
3
 
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.
4
+ **Conditional creators for ActiveRecord**
5
5
 
6
- h1. find_or_create_on_scopes -- Conditional creators for ActiveRecord
6
+ | | |
7
+ |:------------|:--------------------------------|
8
+ | **Author** | Tim Morgan |
9
+ | **Version** | 1.2 (Sep 12, 2011) |
10
+ | **License** | Released under the MIT license. |
7
11
 
8
- | *Author* | Tim Morgan |
9
- | *Version* | 1.2 (Sep 12, 2011) |
10
- | *License* | Released under the MIT license. |
12
+ About
13
+ -----
11
14
 
12
- h2. About
13
-
14
- @find_or_create_on_scopes@ adds handy @find_or_create@-type methods to
15
- @ActiveRecord@. You can use these methods to conditionally create, initialize,
15
+ `find_or_create_on_scopes` adds handy `find_or_create`-type methods to
16
+ `ActiveRecord`. You can use these methods to conditionally create, initialize,
16
17
  or update records depending on the presence of similar records. They work on
17
18
  your base model class and any scopes derived therefrom. (See _Usage_ for
18
19
  examples.)
19
20
 
20
- h2. Installation
21
+ Installation
22
+ ------------
21
23
 
22
- *Important Note:* This gem requires Ruby 1.9. Ruby 1.8 is not and will never be
23
- supported.
24
+ **Important Note:** This gem requires Ruby 1.9+. Ruby 1.8 is not and will never
25
+ be supported.
24
26
 
25
- To install, simply add the @find_or_create_on_scopes@ gem to your Rails
26
- application's @Gemfile@:
27
+ To install, simply add the `find_or_create_on_scopes` gem to your Rails
28
+ application's `Gemfile`:
27
29
 
28
- <pre><code>
30
+ ```` ruby
29
31
  gem 'find_or_create_on_scopes'
30
- </code></pre>
32
+ ````
31
33
 
32
- h2. Usage
34
+ Usage
35
+ -----
33
36
 
34
37
  See the {FindOrCreateOnScopes} module documentation for the complete list of
35
38
  conditional creators/updaters. Some basic examples to give you an overview:
36
39
 
37
- <pre><code>
40
+ ```` ruby
38
41
  # Tries to find a user named 'riscfuture'. If such a User exists, returns it. If
39
42
  # not, creates a user and sets its password to '123'.
40
43
  User.where(login: 'riscfuture').find_or_create(password: '123')
@@ -43,4 +46,4 @@ User.where(login: 'riscfuture').find_or_create(password: '123')
43
46
  # password to '123'. If not, creates a new user and sets its password to '123'.
44
47
  # Raises an exception if validation fails.
45
48
  User.where(login: 'riscfuture').create_or_update!(password: '123')
46
- </code></pre>
49
+ ````
@@ -2,30 +2,31 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: find_or_create_on_scopes 1.4.1 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
8
  s.name = "find_or_create_on_scopes"
8
- s.version = "1.4.0"
9
+ s.version = "1.4.1"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
11
13
  s.authors = ["Tim Morgan"]
12
- s.date = "2013-07-09"
14
+ s.date = "2016-01-22"
13
15
  s.description = "Adds methods to ActiveRecord for conditionally finding, creating, or updating records."
14
16
  s.email = "git@timothymorgan.info"
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE",
17
- "README.textile"
19
+ "README.md"
18
20
  ]
19
21
  s.files = [
20
22
  "LICENSE",
21
- "README.textile",
23
+ "README.md",
22
24
  "find_or_create_on_scopes.gemspec",
23
25
  "lib/find_or_create_on_scopes.rb"
24
26
  ]
25
27
  s.homepage = "http://github.com/riscfuture/find_or_create_on_scopes"
26
- s.require_paths = ["lib"]
27
28
  s.required_ruby_version = Gem::Requirement.new(">= 1.9")
28
- s.rubygems_version = "2.0.3"
29
+ s.rubygems_version = "2.5.1"
29
30
  s.summary = "find_or_create-type methods on ActiveRecord scopes"
30
31
 
31
32
  if s.respond_to? :specification_version then
@@ -35,14 +36,14 @@ Gem::Specification.new do |s|
35
36
  s.add_runtime_dependency(%q<activerecord>, [">= 3.1"])
36
37
  s.add_development_dependency(%q<jeweler>, [">= 0"])
37
38
  s.add_development_dependency(%q<yard>, [">= 0"])
38
- s.add_development_dependency(%q<RedCloth>, [">= 0"])
39
+ s.add_development_dependency(%q<redcarpet>, [">= 0"])
39
40
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
40
41
  s.add_development_dependency(%q<rspec>, [">= 0"])
41
42
  else
42
43
  s.add_dependency(%q<activerecord>, [">= 3.1"])
43
44
  s.add_dependency(%q<jeweler>, [">= 0"])
44
45
  s.add_dependency(%q<yard>, [">= 0"])
45
- s.add_dependency(%q<RedCloth>, [">= 0"])
46
+ s.add_dependency(%q<redcarpet>, [">= 0"])
46
47
  s.add_dependency(%q<sqlite3>, [">= 0"])
47
48
  s.add_dependency(%q<rspec>, [">= 0"])
48
49
  end
@@ -50,7 +51,7 @@ Gem::Specification.new do |s|
50
51
  s.add_dependency(%q<activerecord>, [">= 3.1"])
51
52
  s.add_dependency(%q<jeweler>, [">= 0"])
52
53
  s.add_dependency(%q<yard>, [">= 0"])
53
- s.add_dependency(%q<RedCloth>, [">= 0"])
54
+ s.add_dependency(%q<redcarpet>, [">= 0"])
54
55
  s.add_dependency(%q<sqlite3>, [">= 0"])
55
56
  s.add_dependency(%q<rspec>, [">= 0"])
56
57
  end
@@ -1,4 +1,4 @@
1
- # Adds @find_or_create@-type methods to named scopes.
1
+ # Adds `find_or_create`-type methods to named scopes.
2
2
 
3
3
  module FindOrCreateOnScopes
4
4
 
@@ -6,7 +6,7 @@ module FindOrCreateOnScopes
6
6
  # found. If not found, creates a new record with the attributes of the current
7
7
  # scope and the provided attributes.
8
8
  #
9
- # @param [Array] *args Arguments to pass to the @create@ method.
9
+ # @param [Array] args Arguments to pass to the `create` method.
10
10
  # @yield [record] Yields the record before it is saved.
11
11
  # @yieldparam [ActiveRecord::Base] record The found or created record before
12
12
  # it is saved.
@@ -16,7 +16,7 @@ module FindOrCreateOnScopes
16
16
  find_or_initialize_and_do :save, *args, &block
17
17
  end
18
18
 
19
- # Same as {#find_or_create} but calls @save!@ instead of @save@ on the record.
19
+ # Same as {#find_or_create} but calls `save!` instead of `save` on the record.
20
20
  #
21
21
  # @see #find_or_create
22
22
 
@@ -38,7 +38,7 @@ module FindOrCreateOnScopes
38
38
  # the provided attributes if found. If not found, creates a new record with
39
39
  # the current scope's attributes and the provided attributes.
40
40
  #
41
- # @param [Array] *args Arguments to pass to the @assign_attributes@ method.
41
+ # @param [Array] args Arguments to pass to the `assign_attributes` method.
42
42
  # @yield [record] Yields the record before it is saved.
43
43
  # @yieldparam [ActiveRecord::Base] record The found or created record before
44
44
  # it is saved.
@@ -48,7 +48,7 @@ module FindOrCreateOnScopes
48
48
  create_or_update_and_do :save, *args, &block
49
49
  end
50
50
 
51
- # Same as {#create_or_update} but calls @save!@ instead of @save@ on the
51
+ # Same as {#create_or_update} but calls `save!` instead of `save` on the
52
52
  # record.
53
53
  #
54
54
  # @see #create_or_update
@@ -113,7 +113,20 @@ module FindOrCreateOnScopes
113
113
  if err.to_s.include?('duplicate key value violates unique constraint') ||
114
114
  err.to_s.start_with?('Duplicate entry') ||
115
115
  err.kind_of?(ActiveRecord::RecordNotUnique)
116
- retry
116
+
117
+ # sadly there's no way to tell which keys are the duplicate ones from a
118
+ # SQL error, so we just retry 3 times and then give up :/
119
+ if @_focos_retries
120
+ if @_focos_retries > 3
121
+ raise
122
+ else
123
+ @_focos_retries += 1
124
+ retry
125
+ end
126
+ else
127
+ @_focos_retries = 1
128
+ retry
129
+ end
117
130
  else
118
131
  raise err
119
132
  end
metadata CHANGED
@@ -1,97 +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.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-09 00:00:00.000000000 Z
11
+ date: 2016-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jeweler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: yard
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: RedCloth
56
+ name: redcarpet
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: Adds methods to ActiveRecord for conditionally finding, creating, or
@@ -101,10 +101,10 @@ executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files:
103
103
  - LICENSE
104
- - README.textile
104
+ - README.md
105
105
  files:
106
106
  - LICENSE
107
- - README.textile
107
+ - README.md
108
108
  - find_or_create_on_scopes.gemspec
109
109
  - lib/find_or_create_on_scopes.rb
110
110
  homepage: http://github.com/riscfuture/find_or_create_on_scopes
@@ -116,17 +116,17 @@ require_paths:
116
116
  - lib
117
117
  required_ruby_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
- - - '>='
119
+ - - ">="
120
120
  - !ruby/object:Gem::Version
121
121
  version: '1.9'
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - '>='
124
+ - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
128
  rubyforge_project:
129
- rubygems_version: 2.0.3
129
+ rubygems_version: 2.5.1
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: find_or_create-type methods on ActiveRecord scopes