active_record-events 1.1.0 → 2.0.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 +8 -8
- data/README.md +3 -3
- data/lib/active_record/events/naming.rb +7 -8
- data/lib/active_record/events/version.rb +1 -1
- data/spec/active_record/events/naming_spec.rb +3 -3
- data/spec/active_record/events_spec.rb +1 -1
- data/spec/dummy/app/models/user.rb +1 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTljYzhjZWM1OGRmODA4YjIzYjYyYzMwMDg3YmMxOWVmMWM5ZTMwOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDljYzhkYTk1ZjI1ZjIyNWRlYmZmZTVhNDIzNDNhNjFiNmRlZjA5Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Nzg4ODRhMzRiNzFiMjUwZjkzNWNiNTFmZmE5MjAzZDZjNGE1YzkzNmI5MWQx
|
10
|
+
NDVhZjJlOGM2YzNlNGFhZjc2ZjgzNzMwN2Y1YzU5MjVmOTU3OTMyMzJjY2Zl
|
11
|
+
Y2NiZDU1ZTk4M2UxYjdlOTRjNzM1ZTUwZjMwMjQ0Njk1MWMzOTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODYzYjIyZTNjM2I2NDNhNTk0YWFmOTkxZGU4NjQwZjQ1YzdjODJjM2M4OTkz
|
14
|
+
YzUzZjZmMWM4ZWVhZTNmYWEwYzZkZjA0YzFjNDZhY2Q5MDVhOTk2ODk1ODA3
|
15
|
+
NjE2ZmI5NzdiYzcxN2IyOTFiNjU3NWJkNTA3OWFmYjIxMWMyNzY=
|
data/README.md
CHANGED
@@ -69,14 +69,14 @@ scope :not_completed, -> { where(completed_at: nil) }
|
|
69
69
|
scope :completed, -> { where.not(completed_at: nil) }
|
70
70
|
```
|
71
71
|
|
72
|
-
###
|
72
|
+
### Object
|
73
73
|
|
74
74
|
There are events which do not relate to a model itself but to one of its attributes – take the `User` model with the `email_confirmed_at` field as an example.
|
75
|
-
In order to keep method names grammatically correct, you can specify
|
75
|
+
In order to keep method names grammatically correct, you can specify an object using the `object` option.
|
76
76
|
|
77
77
|
```ruby
|
78
78
|
class User < ActiveRecord::Base
|
79
|
-
has_event :confirm,
|
79
|
+
has_event :confirm, object: :email
|
80
80
|
end
|
81
81
|
```
|
82
82
|
|
@@ -5,34 +5,33 @@ module ActiveRecord
|
|
5
5
|
class Naming
|
6
6
|
def initialize(infinitive, options = {})
|
7
7
|
@infinitive = infinitive
|
8
|
-
@
|
8
|
+
@object = options[:object].presence
|
9
9
|
end
|
10
10
|
|
11
11
|
def field
|
12
|
-
[@
|
12
|
+
[@object, past_participle, 'at'].compact.join('_')
|
13
13
|
end
|
14
14
|
|
15
15
|
def predicate
|
16
|
-
[@
|
16
|
+
[@object, past_participle].compact.join('_')
|
17
17
|
end
|
18
18
|
|
19
19
|
def action
|
20
|
-
[@infinitive, @
|
20
|
+
[@infinitive, @object].compact.join('_')
|
21
21
|
end
|
22
22
|
|
23
23
|
def scope
|
24
|
-
[@
|
24
|
+
[@object, past_participle].compact.join('_')
|
25
25
|
end
|
26
26
|
|
27
27
|
def inverse_scope
|
28
|
-
[@
|
28
|
+
[@object, 'not', past_participle].compact.join('_')
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def past_participle
|
34
|
-
|
35
|
-
@infinitive.verb.conjugate(options)
|
34
|
+
@infinitive.verb.conjugate(tense: :past, aspect: :perfective)
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe ActiveRecord::Events::Naming do
|
4
|
-
context 'without
|
4
|
+
context 'without an object' do
|
5
5
|
subject { described_class.new(:complete) }
|
6
6
|
|
7
7
|
it 'generates a field name' do
|
@@ -25,8 +25,8 @@ RSpec.describe ActiveRecord::Events::Naming do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
context 'with
|
29
|
-
subject { described_class.new(:confirm,
|
28
|
+
context 'with an object' do
|
29
|
+
subject { described_class.new(:confirm, object: :email) }
|
30
30
|
|
31
31
|
it 'generates a field name' do
|
32
32
|
expect(subject.field).to eq('email_confirmed_at')
|
Binary file
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-events
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartosz Pieńkowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|