everett 0.2.0 → 0.2.1

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +50 -10
  4. data/lib/everett/version.rb +1 -1
  5. metadata +19 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9a4844f265ec031ab1001d8f5600f4f5d14c005
4
- data.tar.gz: 78ec39f0f8bbfc0e651c416ea7ee14a086dee58b
3
+ metadata.gz: 920a79c76d642ee25609e003dcac93b30a254983
4
+ data.tar.gz: 07f1bc61977121160a4ea199da1354b6ff8ac7e7
5
5
  SHA512:
6
- metadata.gz: 40912e945e0961017752771bd31667046812b76a1de29da451c795b4dff5645beecc6a08c19e42ee0246eb7a46a15d4b25e000cec9659b99b9a7c3937b168859
7
- data.tar.gz: a414083ee2f1b2604811c036a6f8a3b0c9de71e23c0d1b18de895f9bb047a9c8efe0c60b29311427a0ef5d0cbf9e878e0a6a6ce524fbb7efcf0965569a7a2120
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 simple observer for Rails 5 ActiveRecord.
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/comment_observer.rb`:
27
+ You can put them anywhere, for example `app/observers/contact_observer.rb`:
27
28
 
28
29
  ```ruby
29
- class CommentObserver < Everett::Observer
30
- def after_create(comment)
31
- Rails.logger.info("New comment was posted.")
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(comment)
35
- Rails.logger.info("Comment with an id of #{comment.id} was destroyed.")
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
- Like [rails-observers](https://github.com/rails/rails-observers), the convention is to name observers after the class they observe.
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 after_create_commit(record)
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 = :comment_observer, :notifications_observer
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
 
@@ -1,3 +1,3 @@
1
1
  module Everett
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.2.1".freeze
3
3
  end
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.0
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-17 00:00:00.000000000 Z
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 simple observer for Rails 5 ActiveRecord.
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: Simple observer for Rails 5 ActiveRecord
212
+ summary: Substitute for ActiveRecord::Observer on Rails 5
198
213
  test_files: []