find_or_create_on_scopes 1.4.1 → 1.5.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: e21b0d1d5374b9b0a8083be5c6caf98e6f976c9e
4
- data.tar.gz: dcdf412fc3ebf6d9d9ede925559a0d313465e81b
3
+ metadata.gz: e02fbd2dde3e73f06a09a4537ef772333b7eb16a
4
+ data.tar.gz: 444d64b0f515a81f26c914f3819b3ba30ab7986d
5
5
  SHA512:
6
- metadata.gz: c55f6f6afeb8540e399b9ebb0a6ec3d4dc493e09c98474e9f0bc938ec2c6c195ce5d36dc13078221dffa119a0202d5be75dfff05e05c89ebf335f0a1fd79db33
7
- data.tar.gz: d3cf7432aa4b9f85cc090ca4dcee951b5b0f63323844a66551273e8cee49640a4b2d393ae6cdff0220effb6e5de8bb47bb0196158f1b7fc1a27149e04743726d
6
+ metadata.gz: 22727b20c04b72f74e880ada52e751286957f0b5b262908a0f02a5415c4c28184e9c5804e341656c83c4b8e90ae21a91045cbb347f5658b3f85ef070a49bb8ef
7
+ data.tar.gz: a0e59d1ddb21206af1d8c5ca98fa6d32ae6950a686e6956b22ef28c0103b0d322efe2255582970a926d82d73a3ed22361630177a948a86309a7cb03b937edb34
@@ -1,19 +1,19 @@
1
- # Generated by jeweler
1
+ # Generated by juwelier
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
3
+ # Instead, edit Juwelier::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
+ # stub: find_or_create_on_scopes 1.5.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = "find_or_create_on_scopes"
9
- s.version = "1.4.1"
8
+ s.name = "find_or_create_on_scopes".freeze
9
+ s.version = "1.5.0"
10
10
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Tim Morgan"]
14
- s.date = "2016-01-22"
15
- s.description = "Adds methods to ActiveRecord for conditionally finding, creating, or updating records."
16
- s.email = "git@timothymorgan.info"
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Tim Morgan".freeze]
14
+ s.date = "2016-05-07"
15
+ s.description = "Adds methods to ActiveRecord for conditionally finding, creating, or updating records.".freeze
16
+ s.email = "git@timothymorgan.info".freeze
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE",
19
19
  "README.md"
@@ -24,36 +24,39 @@ Gem::Specification.new do |s|
24
24
  "find_or_create_on_scopes.gemspec",
25
25
  "lib/find_or_create_on_scopes.rb"
26
26
  ]
27
- s.homepage = "http://github.com/riscfuture/find_or_create_on_scopes"
28
- s.required_ruby_version = Gem::Requirement.new(">= 1.9")
29
- s.rubygems_version = "2.5.1"
30
- s.summary = "find_or_create-type methods on ActiveRecord scopes"
27
+ s.homepage = "http://github.com/riscfuture/find_or_create_on_scopes".freeze
28
+ s.required_ruby_version = Gem::Requirement.new(">= 1.9".freeze)
29
+ s.rubygems_version = "2.6.3".freeze
30
+ s.summary = "find_or_create-type methods on ActiveRecord scopes".freeze
31
31
 
32
32
  if s.respond_to? :specification_version then
33
33
  s.specification_version = 4
34
34
 
35
35
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
36
- s.add_runtime_dependency(%q<activerecord>, [">= 3.1"])
37
- s.add_development_dependency(%q<jeweler>, [">= 0"])
38
- s.add_development_dependency(%q<yard>, [">= 0"])
39
- s.add_development_dependency(%q<redcarpet>, [">= 0"])
40
- s.add_development_dependency(%q<sqlite3>, [">= 0"])
41
- s.add_development_dependency(%q<rspec>, [">= 0"])
36
+ s.add_runtime_dependency(%q<activerecord>.freeze, [">= 3.1"])
37
+ s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
38
+ s.add_development_dependency(%q<yard>.freeze, [">= 0"])
39
+ s.add_development_dependency(%q<redcarpet>.freeze, [">= 0"])
40
+ s.add_development_dependency(%q<sqlite3>.freeze, [">= 0"])
41
+ s.add_development_dependency(%q<activerecord-jdbcsqlite3-adapter>.freeze, [">= 0"])
42
+ s.add_development_dependency(%q<rspec>.freeze, [">= 0"])
42
43
  else
43
- s.add_dependency(%q<activerecord>, [">= 3.1"])
44
- s.add_dependency(%q<jeweler>, [">= 0"])
45
- s.add_dependency(%q<yard>, [">= 0"])
46
- s.add_dependency(%q<redcarpet>, [">= 0"])
47
- s.add_dependency(%q<sqlite3>, [">= 0"])
48
- s.add_dependency(%q<rspec>, [">= 0"])
44
+ s.add_dependency(%q<activerecord>.freeze, [">= 3.1"])
45
+ s.add_dependency(%q<juwelier>.freeze, [">= 0"])
46
+ s.add_dependency(%q<yard>.freeze, [">= 0"])
47
+ s.add_dependency(%q<redcarpet>.freeze, [">= 0"])
48
+ s.add_dependency(%q<sqlite3>.freeze, [">= 0"])
49
+ s.add_dependency(%q<activerecord-jdbcsqlite3-adapter>.freeze, [">= 0"])
50
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
49
51
  end
50
52
  else
51
- s.add_dependency(%q<activerecord>, [">= 3.1"])
52
- s.add_dependency(%q<jeweler>, [">= 0"])
53
- s.add_dependency(%q<yard>, [">= 0"])
54
- s.add_dependency(%q<redcarpet>, [">= 0"])
55
- s.add_dependency(%q<sqlite3>, [">= 0"])
56
- s.add_dependency(%q<rspec>, [">= 0"])
53
+ s.add_dependency(%q<activerecord>.freeze, [">= 3.1"])
54
+ s.add_dependency(%q<juwelier>.freeze, [">= 0"])
55
+ s.add_dependency(%q<yard>.freeze, [">= 0"])
56
+ s.add_dependency(%q<redcarpet>.freeze, [">= 0"])
57
+ s.add_dependency(%q<sqlite3>.freeze, [">= 0"])
58
+ s.add_dependency(%q<activerecord-jdbcsqlite3-adapter>.freeze, [">= 0"])
59
+ s.add_dependency(%q<rspec>.freeze, [">= 0"])
57
60
  end
58
61
  end
59
62
 
@@ -2,6 +2,10 @@
2
2
 
3
3
  module FindOrCreateOnScopes
4
4
 
5
+ # Return this in a block from `find_or_create` or `create_or_update` to abort
6
+ # the creation/updating of a record.
7
+ ABORT_SAVE = Object.new
8
+
5
9
  # Locates a record according to the current scope. Returns the record if
6
10
  # found. If not found, creates a new record with the attributes of the current
7
11
  # scope and the provided attributes.
@@ -10,6 +14,7 @@ module FindOrCreateOnScopes
10
14
  # @yield [record] Yields the record before it is saved.
11
15
  # @yieldparam [ActiveRecord::Base] record The found or created record before
12
16
  # it is saved.
17
+ # @yieldreturn [ABORT_SAVE, nil] If `ABORT_SAVE` the record is not saved.
13
18
  # @return [ActiveRecord::Base] The found or created record.
14
19
 
15
20
  def find_or_create(*args, &block)
@@ -42,6 +47,7 @@ module FindOrCreateOnScopes
42
47
  # @yield [record] Yields the record before it is saved.
43
48
  # @yieldparam [ActiveRecord::Base] record The found or created record before
44
49
  # it is saved.
50
+ # @yieldreturn [ABORT_SAVE, nil] If `ABORT_SAVE` the record is not saved.
45
51
  # @return [ActiveRecord::Base] The found or created record.
46
52
 
47
53
  def create_or_update(*args, &block)
@@ -74,8 +80,8 @@ module FindOrCreateOnScopes
74
80
  transaction do
75
81
  record = first || new(*args)
76
82
  if record.new_record?
77
- yield record if block_given?
78
- record.send(meth) if meth
83
+ result = block_given? ? yield(record) : nil
84
+ record.send(meth) if meth && result != ABORT_SAVE
79
85
  end
80
86
  end
81
87
  return record
@@ -101,8 +107,8 @@ module FindOrCreateOnScopes
101
107
  transaction do
102
108
  record = first || new
103
109
  record.assign_attributes(*args) unless args.empty?
104
- yield record if block_given?
105
- record.send(meth) if meth
110
+ result = block_given? ? yield(record) : nil
111
+ record.send(meth) if meth && result != ABORT_SAVE
106
112
  end
107
113
  return record
108
114
  rescue => err
metadata CHANGED
@@ -1,14 +1,14 @@
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.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-22 00:00:00.000000000 Z
11
+ date: 2016-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: jeweler
28
+ name: juwelier
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activerecord-jdbcsqlite3-adapter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rspec
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -126,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
140
  version: '0'
127
141
  requirements: []
128
142
  rubyforge_project:
129
- rubygems_version: 2.5.1
143
+ rubygems_version: 2.6.3
130
144
  signing_key:
131
145
  specification_version: 4
132
146
  summary: find_or_create-type methods on ActiveRecord scopes