paper_boy 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07e7a9c1d5184e6ac88469259ccc656fd8703b57d767e1f6f67d257f8b0ce6bb
4
- data.tar.gz: da636ce15158cd085ee5ce04971c15cd7dcdb1a51cdc278fbbbc0ffc6515e51b
3
+ metadata.gz: 322f3a888b5ba1d4ed7720523a4e76fc9594a029c0a8b4f3b2c621764398b911
4
+ data.tar.gz: 1ccec0f8a25f2ff682fc00576a5983ff2ea6ac87b3972e3dd57313c159420332
5
5
  SHA512:
6
- metadata.gz: 14b26e13ceb4ff52152837905ed23596d7927d9a9bc415bb994e4c26cf547f6643d8023c4a23a0d7f7fd37248a4200523c4493d4a25c3a629315e47ff40a65b5
7
- data.tar.gz: bf8f0cdd38b4e0dff0f8f94964a0d5ac0865df9c841153f8d65a08aa2ea3e4a2d833849de350393d70962751d32ba9122ac9a5150601efa19fe8455c7c28752c
6
+ metadata.gz: cc94274907490e08b575cbd24cc330126011605d6636584c87fb185961cec5e14712d60cf30ff28e8ab5d634b02060f432c413bb16a39dcc4d081aed85e293d3
7
+ data.tar.gz: 78798241e5dc8fd247ec1229b9f74b3f3470eed16bbf7910cde2e263f3233b48ea6424100e3b5694226a7803dde43df509f76ed4889f54f5090adfca626315c2
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ Gemfile.lock
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # PaperBoy
2
2
 
3
- Automatically deliver notifications to subscribers from controllers.
3
+ Automatically deliver notifications to subscribers from controllers (lightweight mixin using `ActiveSupport::Notifications`)
4
4
 
5
5
  ## Installation
6
6
 
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  At first, execute install command:
24
24
 
25
- $ bin/rails generate paper_boy:install
25
+ $ bin/rails g paper_boy:install
26
26
 
27
27
  Include `PaperBoy` in `ApplicationController`:
28
28
 
@@ -36,7 +36,7 @@ And you generate subscriber class with generator command:
36
36
 
37
37
  $ bin/rails g paper_boy:subscriber
38
38
 
39
- Then you implement subscriber class:
39
+ Then you implement `app/subscribers/users_subscriber.rb`:
40
40
 
41
41
  ```ruby
42
42
  class UsersSubscriber < ApplicationSubscriber
@@ -46,7 +46,8 @@ class UsersSubscriber < ApplicationSubscriber
46
46
  # All instance variables are set from controller class.
47
47
  user = payload[:current_user]
48
48
 
49
- # implement something (mailer, slack notifier ...etc)
49
+ # implement something (mailer, notifier, logger ...etc)
50
+ logger.info user
50
51
  end
51
52
 
52
53
  attach_to :"users"
@@ -1,2 +1,2 @@
1
- class ApplicationSubscriber < ActiveSupport::Subscriber
1
+ class ApplicationSubscriber < PaperBoy::Subscriber::Base
2
2
  end
@@ -4,6 +4,6 @@ class <%= class_name %>Subscriber < ApplicationSubscriber
4
4
  # payload = event.payload
5
5
  # end
6
6
 
7
- attach_to :"<%= plural_name %>"
7
+ attach_to :"<%= class_name.underscore %>"
8
8
  end
9
9
  <% end -%>
@@ -2,29 +2,12 @@
2
2
 
3
3
  require "active_support/concern"
4
4
  require "paper_boy/railtie" if defined?(Rails)
5
+ require "paper_boy/subscriber"
5
6
  require "paper_boy/version"
6
7
 
7
8
  module PaperBoy
8
9
  extend ActiveSupport::Concern
9
10
 
10
- IGNORE_IVARS = %w[
11
- @_action_has_layout
12
- @_routes
13
- @_request
14
- @_response
15
- @_lookup_context
16
- @_action_name
17
- @_response_body
18
- @marked_for_same_origin_verification
19
- @_config
20
- @_db_runtime
21
- @_view_context_class
22
- @_view_renderer
23
- @_url_options
24
- @_view_runtime
25
- @_params
26
- ]
27
-
28
11
  included do
29
12
  after_action :paper_boy_deliver!
30
13
  end
@@ -41,8 +24,16 @@ module PaperBoy
41
24
 
42
25
  def paper_boy_context
43
26
  instance_variable_names.each_with_object({}) do |name, payload|
44
- next if IGNORE_IVARS.include?(name)
27
+ next if ignore_ivars.include?(name)
45
28
  payload[name.sub(/\A@_?/, "")] = instance_variable_get(name)
46
29
  end.compact
47
30
  end
31
+
32
+ def ignore_ivars
33
+ Rails.application.config.paper_boy.ignore_ivars - skip_ignore_ivars
34
+ end
35
+
36
+ def skip_ignore_ivars
37
+ Rails.application.config.paper_boy.skip_ignore_ivars
38
+ end
48
39
  end
@@ -13,6 +13,26 @@ end
13
13
 
14
14
  module PaperBoy
15
15
  class Railtie < Rails::Railtie
16
+ config.paper_boy = ActiveSupport::OrderedOptions.new
17
+ config.paper_boy.ignore_ivars = %w[
18
+ @_action_has_layout
19
+ @_routes
20
+ @_request
21
+ @_response
22
+ @_lookup_context
23
+ @_action_name
24
+ @_response_body
25
+ @marked_for_same_origin_verification
26
+ @_config
27
+ @_db_runtime
28
+ @_view_context_class
29
+ @_view_renderer
30
+ @_url_options
31
+ @_view_runtime
32
+ @_params
33
+ ]
34
+ config.paper_boy.skip_ignore_ivars = []
35
+
16
36
  config.after_initialize do |app|
17
37
  app.config.paths.add 'app/subscribers', eager_load: true, glob: "**/*_subscriber.rb"
18
38
  end
@@ -0,0 +1,13 @@
1
+ require "active_support/subscriber"
2
+
3
+ module PaperBoy
4
+ module Subscriber
5
+ class Base < ActiveSupport::Subscriber
6
+ include ActiveSupport::Rescuable
7
+
8
+ def logger
9
+ Rails.logger
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaperBoy
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_boy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshiyuki Hirano
@@ -21,7 +21,6 @@ files:
21
21
  - ".rspec"
22
22
  - ".travis.yml"
23
23
  - Gemfile
24
- - Gemfile.lock
25
24
  - LICENSE.txt
26
25
  - README.md
27
26
  - Rakefile
@@ -40,6 +39,7 @@ files:
40
39
  - lib/generators/test_unit/templates/subscriber_test.rb.tt
41
40
  - lib/paper_boy.rb
42
41
  - lib/paper_boy/railtie.rb
42
+ - lib/paper_boy/subscriber.rb
43
43
  - lib/paper_boy/version.rb
44
44
  - paper_boy.gemspec
45
45
  homepage: https://github.com/yhirano55/paper_boy
@@ -1,34 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- paper_boy (0.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- diff-lcs (1.3)
10
- rake (10.5.0)
11
- rspec (3.7.0)
12
- rspec-core (~> 3.7.0)
13
- rspec-expectations (~> 3.7.0)
14
- rspec-mocks (~> 3.7.0)
15
- rspec-core (3.7.1)
16
- rspec-support (~> 3.7.0)
17
- rspec-expectations (3.7.0)
18
- diff-lcs (>= 1.2.0, < 2.0)
19
- rspec-support (~> 3.7.0)
20
- rspec-mocks (3.7.0)
21
- diff-lcs (>= 1.2.0, < 2.0)
22
- rspec-support (~> 3.7.0)
23
- rspec-support (3.7.1)
24
-
25
- PLATFORMS
26
- ruby
27
-
28
- DEPENDENCIES
29
- paper_boy!
30
- rake (~> 10.0)
31
- rspec (~> 3.0)
32
-
33
- BUNDLED WITH
34
- 1.16.1