paper_boy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 07e7a9c1d5184e6ac88469259ccc656fd8703b57d767e1f6f67d257f8b0ce6bb
4
+ data.tar.gz: da636ce15158cd085ee5ce04971c15cd7dcdb1a51cdc278fbbbc0ffc6515e51b
5
+ SHA512:
6
+ metadata.gz: 14b26e13ceb4ff52152837905ed23596d7927d9a9bc415bb994e4c26cf547f6643d8023c4a23a0d7f7fd37248a4200523c4493d4a25c3a629315e47ff40a65b5
7
+ data.tar.gz: bf8f0cdd38b4e0dff0f8f94964a0d5ac0865df9c841153f8d65a08aa2ea3e4a2d833849de350393d70962751d32ba9122ac9a5150601efa19fe8455c7c28752c
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
+ gemspec
6
+
7
+ gem "rake", "~> 10.0"
8
+
9
+ group :test do
10
+ gem "rspec", "~> 3.0"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
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
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Yoshiyuki Hirano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # PaperBoy
2
+
3
+ Automatically deliver notifications to subscribers from controllers.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'paper_boy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install paper_boy
20
+
21
+ ## Usage
22
+
23
+ At first, execute install command:
24
+
25
+ $ bin/rails generate paper_boy:install
26
+
27
+ Include `PaperBoy` in `ApplicationController`:
28
+
29
+ ```ruby
30
+ class ApplicationController < ActionController::Base
31
+ include PaperBoy
32
+ end
33
+ ```
34
+
35
+ And you generate subscriber class with generator command:
36
+
37
+ $ bin/rails g paper_boy:subscriber
38
+
39
+ Then you implement subscriber class:
40
+
41
+ ```ruby
42
+ class UsersSubscriber < ApplicationSubscriber
43
+ def create(event)
44
+ payload = event.payload
45
+
46
+ # All instance variables are set from controller class.
47
+ user = payload[:current_user]
48
+
49
+ # implement something (mailer, slack notifier ...etc)
50
+ end
51
+
52
+ attach_to :"users"
53
+ end
54
+ ```
55
+
56
+ ## License
57
+
58
+ [MIT License](https://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "paper_boy"
6
+
7
+ require "irb"
8
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,19 @@
1
+ require "rails/generators"
2
+ require "rails/generators/rails/controller/controller_generator"
3
+ require "rails/generators/rails/scaffold_controller/scaffold_controller_generator"
4
+
5
+ module Rails
6
+ module Generators
7
+ class ControllerGenerator
8
+ hook_for :subscriber, type: :boolean, default: true do |generator|
9
+ invoke generator, [name.pluralize]
10
+ end
11
+ end
12
+
13
+ class ScaffoldControllerGenerator
14
+ hook_for :subscriber, type: :boolean, default: true do |generator|
15
+ invoke generator, [name.pluralize]
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,2 @@
1
+ Description:
2
+ Generates an application subscriber as a starting point for your application.
@@ -0,0 +1,11 @@
1
+ module PaperBoy
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path("templates", __dir__)
5
+
6
+ def copy_application_loyalty
7
+ copy_file "application_subscriber.rb.tt", "app/subscribers/application_subscriber.rb"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationSubscriber < ActiveSupport::Subscriber
2
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates a subscriber for a controller with the given name.
3
+
4
+ Example:
5
+ rails generate subscriber users
6
+
7
+ This will create:
8
+ app/subscribers/users_subscriber.rb
@@ -0,0 +1,14 @@
1
+ module Rails
2
+ module Generators
3
+ class SubscriberGenerator < NamedBase
4
+ source_root File.expand_path("templates", __dir__)
5
+ check_class_collision suffix: "Subscriber"
6
+
7
+ def create_subscriber
8
+ template "subscriber.rb.tt", File.join("app/subscribers", class_path, "#{file_name}_subscriber.rb")
9
+ end
10
+
11
+ hook_for :test_framework
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Subscriber < ApplicationSubscriber
3
+ # def action(event)
4
+ # payload = event.payload
5
+ # end
6
+
7
+ attach_to :"<%= plural_name %>"
8
+ end
9
+ <% end -%>
@@ -0,0 +1,11 @@
1
+ module Rspec
2
+ module Generators
3
+ class SubscriberGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path("templates", __dir__)
5
+
6
+ def create_test_file
7
+ template 'subscriber_spec.rb.tt', File.join('spec/subscribers', class_path, "#{plural_name}_subscriber_spec.rb")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe <%= class_name %>Subscriber do
4
+ end
@@ -0,0 +1,12 @@
1
+ module TestUnit
2
+ module Generators
3
+ class SubscriberGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path("templates", __dir__)
5
+ check_class_collision suffix: "SubscriberTest"
6
+
7
+ def create_test_file
8
+ template 'subscriber_test.rb.tt', File.join('test/subscribers', class_path, "#{plural_name}_subscriber_test.rb")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ require 'test_helper'
2
+
3
+ class <%= class_name %>SubscriberTest < ActiveSupport::TestCase
4
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/railtie'
4
+
5
+ module ActiveModel
6
+ class Railtie < Rails::Railtie
7
+ generators do |app|
8
+ Rails::Generators.configure! app.config.generators
9
+ require_relative '../generators/controller_override'
10
+ end
11
+ end
12
+ end
13
+
14
+ module PaperBoy
15
+ class Railtie < Rails::Railtie
16
+ config.after_initialize do |app|
17
+ app.config.paths.add 'app/subscribers', eager_load: true, glob: "**/*_subscriber.rb"
18
+ end
19
+
20
+ config.to_prepare do
21
+ Dir[Rails.root.join("app", "subscribers", "**", "*_subscriber.rb")].each { |f| require(f) }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaperBoy
4
+ VERSION = "0.1.0"
5
+ end
data/lib/paper_boy.rb ADDED
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+ require "paper_boy/railtie" if defined?(Rails)
5
+ require "paper_boy/version"
6
+
7
+ module PaperBoy
8
+ extend ActiveSupport::Concern
9
+
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
+ included do
29
+ after_action :paper_boy_deliver!
30
+ end
31
+
32
+ private
33
+
34
+ def paper_boy_deliver!
35
+ ActiveSupport::Notifications.instrument(paper_boy_event_name, paper_boy_context)
36
+ end
37
+
38
+ def paper_boy_event_name
39
+ "#{params[:action]}.#{params[:controller]}"
40
+ end
41
+
42
+ def paper_boy_context
43
+ instance_variable_names.each_with_object({}) do |name, payload|
44
+ next if IGNORE_IVARS.include?(name)
45
+ payload[name.sub(/\A@_?/, "")] = instance_variable_get(name)
46
+ end.compact
47
+ end
48
+ end
data/paper_boy.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "paper_boy/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "paper_boy"
9
+ spec.version = PaperBoy::VERSION
10
+ spec.authors = ["Yoshiyuki Hirano"]
11
+ spec.email = ["yhirano@me.com"]
12
+ spec.summary = %q{Automatically deliver notifications to subscribers from controllers.}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/yhirano55/paper_boy"
15
+ spec.license = "MIT"
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paper_boy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yoshiyuki Hirano
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Automatically deliver notifications to subscribers from controllers.
14
+ email:
15
+ - yhirano@me.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".travis.yml"
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - lib/generators/controller_override.rb
31
+ - lib/generators/paper_boy/install/USAGE
32
+ - lib/generators/paper_boy/install/install_generator.rb
33
+ - lib/generators/paper_boy/install/templates/application_subscriber.rb.tt
34
+ - lib/generators/rails/subscriber/USAGE
35
+ - lib/generators/rails/subscriber/subscriber_generator.rb
36
+ - lib/generators/rails/subscriber/templates/subscriber.rb.tt
37
+ - lib/generators/rspec/subscriber_generator.rb
38
+ - lib/generators/rspec/templates/subscriber_spec.rb.tt
39
+ - lib/generators/test_unit/subscriber_generator.rb
40
+ - lib/generators/test_unit/templates/subscriber_test.rb.tt
41
+ - lib/paper_boy.rb
42
+ - lib/paper_boy/railtie.rb
43
+ - lib/paper_boy/version.rb
44
+ - paper_boy.gemspec
45
+ homepage: https://github.com/yhirano55/paper_boy
46
+ licenses:
47
+ - MIT
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 2.7.6
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Automatically deliver notifications to subscribers from controllers.
69
+ test_files: []