bullet_uniform_notifier_mysql 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d6155e95238d120d87d8341ac4dc91df7294e5e6
4
+ data.tar.gz: dbe2503a5000a7a7ecec353ed6d4448ba7a07d73
5
+ SHA512:
6
+ metadata.gz: f80d9c3a94fe29f8fab36d115c679f42608017315a4fb01543219aed6784340f3ec568a5d3a19c66555440f6c4e59fc6f2e84d3b032abb1cf0058b74d911aeae
7
+ data.tar.gz: f28c2afa07665a376ab477848d771091f6e0df994c62c457ffd92239b313135e10378978c03d602822f8466ca986107112f30ac58cbd3898811febac4ce3585d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bullet_uniform_notifier_mysql.gemspec
4
+ gemspec
@@ -0,0 +1,52 @@
1
+ # BulletUniformNotifierMysql
2
+
3
+ The [Bullet](https://github.com/flyerhzm/bullet) gem is great to help you detect N+1 queries. The notifier of Bullet use [uniform_notifier](https://github.com/flyerhzm/uniform_notifier) gem.
4
+
5
+ BulletUniformNotifierMysql save notifications to MySQL.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'bullet_uniform_notifier_mysql'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install bullet_uniform_notifier_mysql
22
+
23
+ ## Usage
24
+
25
+ Gemfile:
26
+
27
+ ```
28
+ gem 'bullet'
29
+ gem 'bullet_uniform_notifier_mysql'
30
+ ```
31
+
32
+ config/environments/test.rb:
33
+
34
+ ```ruby
35
+ config.after_initialize do
36
+ Bullet.enable = true
37
+ Bullet.mysql = { host: 'localhost', username: 'root', database: 'test' }
38
+ end
39
+ ```
40
+
41
+ Run your test code and bullet notifications will be saved to the MySQL `bullet_notifications` table.
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/takatoshiono/bullet_uniform_notifier_mysql.
52
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bullet_uniform_notifier_mysql"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bullet_uniform_notifier_mysql/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bullet_uniform_notifier_mysql"
8
+ spec.version = BulletUniformNotifierMysql::VERSION
9
+ spec.authors = ["Takatoshi Ono"]
10
+ spec.email = ["takatoshi.ono@gmail.com"]
11
+
12
+ spec.summary = %q{Bullet uniform_notifier for mysql}
13
+ spec.description = %q{Bullet uniform_notifier for mysql}
14
+ spec.homepage = "https://github.com/takatoshiono/bullet_uniform_notifier_mysql"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+
25
+ spec.add_development_dependency "bullet"
26
+ spec.add_development_dependency "uniform_notifier"
27
+ spec.add_development_dependency "mysql2"
28
+ end
@@ -0,0 +1,28 @@
1
+ require "bullet_uniform_notifier_mysql/version"
2
+ require "uniform_notifier"
3
+ require 'uniform_notifier/mysql'
4
+ require 'bullet'
5
+
6
+ module BulletUniformNotifierMysql
7
+ # Your code goes here...
8
+ end
9
+
10
+ class UniformNotifier
11
+ class << self
12
+ attr_accessor :mysql
13
+
14
+ def active_notifiers
15
+ [Mysql, *NOTIFIERS].select { |notifier| notifier.active? }
16
+ end
17
+
18
+ def mysql=(mysql)
19
+ UniformNotifier::Mysql.setup_connection(mysql)
20
+ end
21
+ end
22
+ end
23
+
24
+ module Bullet
25
+ class << self
26
+ delegate :mysql=, to: UniformNotifier
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module BulletUniformNotifierMysql
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,54 @@
1
+ require 'uniform_notifier/base'
2
+ require 'mysql2'
3
+
4
+ class UniformNotifier
5
+ class Mysql < Base
6
+ @config = nil
7
+
8
+ class << self
9
+ def active?
10
+ @config && mysql_client
11
+ end
12
+
13
+ def setup_connection(config = {})
14
+ @config = config
15
+ create_table
16
+ end
17
+
18
+ protected
19
+
20
+ # Bullet calls `out_of_channel_notify` with following parameter.
21
+ # {
22
+ # :user => whoami,
23
+ # :url => url,
24
+ # :title => title,
25
+ # :body => body_with_caller,
26
+ # }
27
+ def _out_of_channel_notify(data)
28
+ statement = mysql_client.prepare('INSERT INTO bullet_notifications(url, title, body, created_at) VALUES(?, ?, ?, ?)')
29
+ statement.execute(data[:url], data[:title], data[:body], Time.now)
30
+ end
31
+
32
+ private
33
+
34
+ def mysql_client
35
+ @mysql2 ||= Mysql2::Client.new(@config)
36
+ end
37
+
38
+ def create_table
39
+ mysql_client.query('DROP TABLE IF EXISTS bullet_notifications')
40
+ mysql_client.query(<<-"SQL")
41
+ CREATE TABLE bullet_notifications (
42
+ id int not null auto_increment,
43
+ url varchar(255),
44
+ title varchar(255),
45
+ body text,
46
+ created_at datetime,
47
+ updated_at timestamp,
48
+ primary key (id)
49
+ )
50
+ SQL
51
+ end
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bullet_uniform_notifier_mysql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Takatoshi Ono
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bullet
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: uniform_notifier
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mysql2
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Bullet uniform_notifier for mysql
98
+ email:
99
+ - takatoshi.ono@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - README.md
109
+ - Rakefile
110
+ - bin/console
111
+ - bin/setup
112
+ - bullet_uniform_notifier_mysql.gemspec
113
+ - lib/bullet_uniform_notifier_mysql.rb
114
+ - lib/bullet_uniform_notifier_mysql/version.rb
115
+ - lib/uniform_notifier/mysql.rb
116
+ homepage: https://github.com/takatoshiono/bullet_uniform_notifier_mysql
117
+ licenses: []
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.5.1
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Bullet uniform_notifier for mysql
139
+ test_files: []