everett 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +50 -10
- data/lib/everett/version.rb +1 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 920a79c76d642ee25609e003dcac93b30a254983
|
4
|
+
data.tar.gz: 07f1bc61977121160a4ea199da1354b6ff8ac7e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14804ff35c6d5049dd8700314e2c62481d347cfacb30296f4462e263620956f9dfe38c6721beb66672b3642eb350c2c6cfa4a6d31ee048ed3551fd3969bb1876
|
7
|
+
data.tar.gz: 1efe1f6e2fed80ab406cad0afd187394418366daaf6edb20d365bd5e0e2cb9f99d4ee55b5fc3b882d83f54aa2f6b46ae13266027a3ae431ce10244f675e62dc1
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
## [0.2.1](https://github.com/yasaichi/everett/releases/tag/v0.2.1) (December 26, 2016)
|
3
|
+
* Improve the gem summary, description and README
|
4
|
+
* Add CHANGELOG
|
5
|
+
|
6
|
+
## [0.2.0](https://github.com/yasaichi/everett/releases/tag/v0.2.0) (December 17, 2016)
|
7
|
+
* [Implement core classes and modules](https://github.com/yasaichi/everett/pull/1)
|
8
|
+
* [Implement a rails generator to create the initializer](https://github.com/yasaichi/everett/pull/2)
|
9
|
+
|
10
|
+
## [0.1.0](https://github.com/yasaichi/everett/releases/tag/v0.1.0) (December 10, 2016)
|
11
|
+
* The initial release to reserve the gem name
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[![Code Climate](https://codeclimate.com/github/yasaichi/everett/badges/gpa.svg)](https://codeclimate.com/github/yasaichi/everett)
|
5
5
|
[![Test Coverage](https://codeclimate.com/github/yasaichi/everett/badges/coverage.svg)](https://codeclimate.com/github/yasaichi/everett/coverage)
|
6
6
|
|
7
|
-
Everett is a
|
7
|
+
Everett is a substitute for `ActiveRecord::Observer` on Rails 5.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
Put this in your Gemfile:
|
@@ -22,31 +22,32 @@ $ rails g everett:install
|
|
22
22
|
They will install the initializer into `config/initializers/everett.rb`.
|
23
23
|
|
24
24
|
## Usage
|
25
|
+
### Overview
|
25
26
|
Observers allow you to implement trigger-like behavior outside the original classes.
|
26
|
-
You can put them anywhere, for example `app/observers/
|
27
|
+
You can put them anywhere, for example `app/observers/contact_observer.rb`:
|
27
28
|
|
28
29
|
```ruby
|
29
|
-
class
|
30
|
-
def after_create(
|
31
|
-
Rails.logger.info(
|
30
|
+
class ContactObserver < Everett::Observer
|
31
|
+
def after_create(contact)
|
32
|
+
Rails.logger.info('New contact added!')
|
32
33
|
end
|
33
34
|
|
34
|
-
def after_destroy(
|
35
|
-
Rails.logger.info("
|
35
|
+
def after_destroy(contact)
|
36
|
+
Rails.logger.info("Contact with an id of #{contact.id} was destroyed!")
|
36
37
|
end
|
37
38
|
end
|
38
39
|
```
|
39
40
|
|
40
41
|
This observer prints a log message when specific callbacks are triggered.
|
41
42
|
|
42
|
-
|
43
|
+
Just like `ActiveRecord::Observer`, the convention is to name observers after the class they observe.
|
43
44
|
If you need to change this, or want to use one observer for several classes, use `observe`:
|
44
45
|
|
45
46
|
```ruby
|
46
47
|
class NotificationsObserver < Everett::Observer
|
47
48
|
observe :comment, :like
|
48
49
|
|
49
|
-
def
|
50
|
+
def after_create(record)
|
50
51
|
# notifiy users of new comment or like
|
51
52
|
end
|
52
53
|
end
|
@@ -56,9 +57,48 @@ Note that you must register observers first to activate them.
|
|
56
57
|
This can be done by adding the following line into `config/initializers/everett.rb`:
|
57
58
|
|
58
59
|
```ruby
|
59
|
-
config.observers = :
|
60
|
+
config.observers = :contact_observer, :notifications_observer
|
61
|
+
```
|
62
|
+
|
63
|
+
### after\_{create,update,destroy}\_commit
|
64
|
+
Since `after_create_commit`, `after_update_commit` and `after_destroy_commit` were introduced in Rails 5,
|
65
|
+
you can also use them in observers:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
class CommentObserver < Everett::Observer
|
69
|
+
def after_create_commit(comment)
|
70
|
+
CommentMailer.notification(comment).deliver_now
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
This observer sends an email after a record has been created.
|
76
|
+
|
77
|
+
## Migration from rails-observers
|
78
|
+
Since Everett is highly compatible with `ActiveRecord::Observer`,
|
79
|
+
you can easily migrate from [rails-observers](https://github.com/rails/rails-observers).
|
80
|
+
All you need to do is as follows:
|
81
|
+
|
82
|
+
### 1. Replace `ActiveRecord::Observer` with `Everett::Observer`
|
83
|
+
|
84
|
+
```diff
|
85
|
+
-class ContactObserver < ActiveRecord::Observer
|
86
|
+
+class ContactObserver < Everett::Observer
|
60
87
|
```
|
61
88
|
|
89
|
+
### 2. Register observers in `config/initializers/everett.rb`
|
90
|
+
|
91
|
+
```diff
|
92
|
+
# config/application.rb
|
93
|
+
-config.active_record.observers = :contact_observer, :notifications_observer
|
94
|
+
|
95
|
+
# config/initializers/everett.rb
|
96
|
+
+config.observers = :contact_observer, :notifications_observer
|
97
|
+
```
|
98
|
+
|
99
|
+
### 3. Check the test suite passes
|
100
|
+
If you find any bugs, please document them on [the issues page](https://github.com/yasaichi/everett/issues).
|
101
|
+
|
62
102
|
## Contributing
|
63
103
|
You should follow the steps below.
|
64
104
|
|
data/lib/everett/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: everett
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yasaichi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: reek
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rspec-rails
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,13 +164,14 @@ dependencies:
|
|
150
164
|
- - ">="
|
151
165
|
- !ruby/object:Gem::Version
|
152
166
|
version: '0'
|
153
|
-
description: Everett is a
|
167
|
+
description: Everett is a substitute for ActiveRecord::Observer on Rails 5.
|
154
168
|
email:
|
155
169
|
- yasaichi@users.noreply.github.com
|
156
170
|
executables: []
|
157
171
|
extensions: []
|
158
172
|
extra_rdoc_files: []
|
159
173
|
files:
|
174
|
+
- CHANGELOG.md
|
160
175
|
- MIT-LICENSE
|
161
176
|
- README.md
|
162
177
|
- Rakefile
|
@@ -194,5 +209,5 @@ rubyforge_project:
|
|
194
209
|
rubygems_version: 2.5.1
|
195
210
|
signing_key:
|
196
211
|
specification_version: 4
|
197
|
-
summary:
|
212
|
+
summary: Substitute for ActiveRecord::Observer on Rails 5
|
198
213
|
test_files: []
|