active_record-events 0.1.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/README.md +2 -2
- data/lib/active_record/events.rb +21 -19
- data/lib/active_record/events/version.rb +1 -1
- data/spec/dummy/app/models/task.rb +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- metadata +22 -22
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2VhZTQxOTNiMmU4MzdmNjgyYjIzNzMwNjMzZjY1MjM3ODJiOGJhZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzRmYWY5M2JmYmNmMGY0ODdiMTIwY2QyZDdkYjhkZDMxODMzYzM3MQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Y2NjZTY3YmIyMDBjZjNlMmZiNWU1NjdlZGExMTE0ZGViYTg3NWY4YWY3ZmM3
|
10
|
+
YzBmZjJlNWI4MWFlYWQ0ZWQ5ZmRmZDgxMmI3NTYzM2VlNGZmNGYyYzEyNmE2
|
11
|
+
ZjQ0YzAzNzhmMjk5ZTE0OGZkNjM2YzAzM2IwNzI5MTkxMTU1MmU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDA2M2M3MjY2NzUyYTVhYjJkMmU4ZDhjYmJjNDcxOGU3NDFlNWE5MmFkMDMy
|
14
|
+
ODdhZTFkOWJlYWEyOTcxNjM5MTMxOGEzMmFmZDBlMDc3NDllYjMzZjRlZThl
|
15
|
+
ZTM5ZThmZWM3NzE1NjIyOTY1ZTUyZWY1NTE5MmY5MjY2YmQzZTk=
|
data/README.md
CHANGED
@@ -49,7 +49,7 @@ Instead of defining these three methods explicitly, you can use a macro provided
|
|
49
49
|
|
50
50
|
```ruby
|
51
51
|
class Task < ActiveRecord::Base
|
52
|
-
|
52
|
+
has_event :complete
|
53
53
|
end
|
54
54
|
```
|
55
55
|
|
@@ -57,7 +57,7 @@ This approach is very efficient when more than one field has to be handled that
|
|
57
57
|
In such a case, many lines of code can be replaced with an expressive one-liner.
|
58
58
|
|
59
59
|
```ruby
|
60
|
-
|
60
|
+
has_events :complete, :archive
|
61
61
|
```
|
62
62
|
|
63
63
|
### Scopes
|
data/lib/active_record/events.rb
CHANGED
@@ -8,32 +8,34 @@ module ActiveRecord
|
|
8
8
|
infinitive.verb.conjugate(options)
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def has_events(*names)
|
12
|
+
names.each { |n| has_event(n) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def has_event(name)
|
12
16
|
_module = ActiveRecord::Events
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
field_name = "#{past_participle}_at"
|
18
|
+
past_participle = _module.past_participle(name)
|
19
|
+
field_name = "#{past_participle}_at"
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
define_method("#{past_participle}?") do
|
22
|
+
self[field_name].present?
|
23
|
+
end
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
+
define_method(name) do
|
26
|
+
touch(field_name) if self[field_name].blank?
|
27
|
+
end
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
define_method("#{name}!") do
|
30
|
+
touch(field_name)
|
31
|
+
end
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
define_singleton_method(past_participle) do
|
34
|
+
where(arel_table[field_name].not_eq(nil))
|
35
|
+
end
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
+
define_singleton_method("not_#{past_participle}") do
|
38
|
+
where(arel_table[field_name].eq(nil))
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,125 +1,125 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-events
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.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: 2016-
|
11
|
+
date: 2016-12-28 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.0'
|
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.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: verbs
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: appraisal
|
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
56
|
name: standalone_migrations
|
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
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: factory_girl
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ! '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ! '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: timecop
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ! '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ! '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
description: An ActiveRecord extension providing convenience methods for timestamp
|
@@ -155,12 +155,12 @@ require_paths:
|
|
155
155
|
- lib
|
156
156
|
required_ruby_version: !ruby/object:Gem::Requirement
|
157
157
|
requirements:
|
158
|
-
- -
|
158
|
+
- - ! '>='
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: 1.9.3
|
161
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
162
|
requirements:
|
163
|
-
- -
|
163
|
+
- - ! '>='
|
164
164
|
- !ruby/object:Gem::Version
|
165
165
|
version: '0'
|
166
166
|
requirements: []
|