active_record-events 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTljYzhjZWM1OGRmODA4YjIzYjYyYzMwMDg3YmMxOWVmMWM5ZTMwOA==
4
+ YWIyMzk2ODkyNDRlMGE2ZjA0ZmNhOGM1YmM5YjVjYjQ2ZWM0NmVhMQ==
5
5
  data.tar.gz: !binary |-
6
- ZDljYzhkYTk1ZjI1ZjIyNWRlYmZmZTVhNDIzNDNhNjFiNmRlZjA5Ng==
6
+ YTAyZGNhYTU5NTcxOWE1OTM3NTg2YmMzZjA2OGEwNzBjN2U5YjJlZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Nzg4ODRhMzRiNzFiMjUwZjkzNWNiNTFmZmE5MjAzZDZjNGE1YzkzNmI5MWQx
10
- NDVhZjJlOGM2YzNlNGFhZjc2ZjgzNzMwN2Y1YzU5MjVmOTU3OTMyMzJjY2Zl
11
- Y2NiZDU1ZTk4M2UxYjdlOTRjNzM1ZTUwZjMwMjQ0Njk1MWMzOTk=
9
+ OTUyZDQxYzdhOGIwMTU1ZGE3MGI3NDAwNzM4ZDEwMjE1YzVmNjA5MGFhN2Jm
10
+ M2UxZGQxMmRmYzU3MjVlNGY4ZWY0ODdjZmE0MzQ5OGEyMzY3N2U3NjIyODYx
11
+ OTVmNTRmYjhiMjYyNTIzZDIwYTQxZjdmODkzMTI4MWVkM2RjODU=
12
12
  data.tar.gz: !binary |-
13
- ODYzYjIyZTNjM2I2NDNhNTk0YWFmOTkxZGU4NjQwZjQ1YzdjODJjM2M4OTkz
14
- YzUzZjZmMWM4ZWVhZTNmYWEwYzZkZjA0YzFjNDZhY2Q5MDVhOTk2ODk1ODA3
15
- NjE2ZmI5NzdiYzcxN2IyOTFiNjU3NWJkNTA3OWFmYjIxMWMyNzY=
13
+ YjYxMzgyNmExNmQxNjI1Y2VmZTgzNTNjOGVkN2M1Y2MzODAyZWIyN2NlMWI2
14
+ MmNiMjQyYmQ1MGJlYjk5NDYwMzAxZGQxZTMwZDMwNGUxMzY3MzY4NTM3MDhh
15
+ ZjliZGY3MzZmZjU5MzVjMjVkYWUwMWVjMWE2NTdjYjQ5ZTBlYjI=
data/README.md CHANGED
@@ -31,12 +31,16 @@ Consider a `Task` model with a `completed_at` field and the following methods:
31
31
 
32
32
  ```ruby
33
33
  class Task < ActiveRecord::Base
34
+ def not_completed?
35
+ !completed?
36
+ end
37
+
34
38
  def completed?
35
39
  completed_at.present?
36
40
  end
37
41
 
38
42
  def complete
39
- complete! unless completed?
43
+ complete! if not_completed?
40
44
  end
41
45
 
42
46
  def complete!
@@ -45,7 +49,7 @@ class Task < ActiveRecord::Base
45
49
  end
46
50
  ```
47
51
 
48
- Instead of defining these three methods explicitly, you can use a macro provided by the gem.
52
+ Instead of defining these four methods explicitly, you can use a macro provided by the gem.
49
53
 
50
54
  ```ruby
51
55
  class Task < ActiveRecord::Base
@@ -80,7 +84,7 @@ class User < ActiveRecord::Base
80
84
  end
81
85
  ```
82
86
 
83
- This will generate `email_confirmed?`, `confirm_email` and `confirm_email!` methods.
87
+ This will generate `email_not_confirmed?`, `email_confirmed?`, `confirm_email` and `confirm_email!` methods.
84
88
 
85
89
  ## See also
86
90
 
@@ -15,6 +15,10 @@ module ActiveRecord
15
15
  self[naming.field].present?
16
16
  end
17
17
 
18
+ define_method("#{naming.inverse_predicate}?") do
19
+ self[naming.field].blank?
20
+ end
21
+
18
22
  define_method(naming.action) do
19
23
  touch(naming.field) if self[naming.field].blank?
20
24
  end
@@ -16,6 +16,10 @@ module ActiveRecord
16
16
  [@object, past_participle].compact.join('_')
17
17
  end
18
18
 
19
+ def inverse_predicate
20
+ [@object, 'not', past_participle].compact.join('_')
21
+ end
22
+
19
23
  def action
20
24
  [@infinitive, @object].compact.join('_')
21
25
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Events
3
- VERSION = '2.0.0'
3
+ VERSION = '2.1.0'
4
4
  end
5
5
  end
@@ -12,6 +12,10 @@ RSpec.describe ActiveRecord::Events::Naming do
12
12
  expect(subject.predicate).to eq('completed')
13
13
  end
14
14
 
15
+ it 'generates an inverse predicate name' do
16
+ expect(subject.inverse_predicate).to eq('not_completed')
17
+ end
18
+
15
19
  it 'generates an action name' do
16
20
  expect(subject.action).to eq('complete')
17
21
  end
@@ -36,6 +40,10 @@ RSpec.describe ActiveRecord::Events::Naming do
36
40
  expect(subject.predicate).to eq('email_confirmed')
37
41
  end
38
42
 
43
+ it 'generates an inverse predicate name' do
44
+ expect(subject.inverse_predicate).to eq('email_not_confirmed')
45
+ end
46
+
39
47
  it 'generates an action name' do
40
48
  expect(subject.action).to eq('confirm_email')
41
49
  end
@@ -7,6 +7,8 @@ RSpec.describe ActiveRecord::Events do
7
7
  task.complete
8
8
 
9
9
  expect(task).to be_completed
10
+ expect(task).not_to be_not_completed
11
+
10
12
  expect(task.completed_at).to eq(Time.now)
11
13
  end
12
14
 
@@ -33,6 +35,8 @@ RSpec.describe ActiveRecord::Events do
33
35
 
34
36
  it 'handles an object' do
35
37
  user.confirm_email
38
+
36
39
  expect(user.email_confirmed?).to be(true)
40
+ expect(user.email_not_confirmed?).to be(false)
37
41
  end
38
42
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-events
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartosz Pieńkowski