exes_poster 0.1.0

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 (61) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +100 -0
  4. data/Rakefile +58 -0
  5. data/lib/exes_poster.rb +17 -0
  6. data/lib/exes_poster/configurator.rb +28 -0
  7. data/lib/exes_poster/poster.rb +39 -0
  8. data/lib/exes_poster/version.rb +3 -0
  9. data/lib/tasks/exes_poster_tasks.rake +4 -0
  10. data/spec/dummy/Rakefile +6 -0
  11. data/spec/dummy/app/assets/config/manifest.js +2 -0
  12. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  13. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  14. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  15. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  16. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  17. data/spec/dummy/app/jobs/application_job.rb +2 -0
  18. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  19. data/spec/dummy/app/models/application_record.rb +3 -0
  20. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  21. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  22. data/spec/dummy/bin/bundle +3 -0
  23. data/spec/dummy/bin/rails +4 -0
  24. data/spec/dummy/bin/rake +4 -0
  25. data/spec/dummy/bin/setup +34 -0
  26. data/spec/dummy/bin/update +29 -0
  27. data/spec/dummy/config.ru +5 -0
  28. data/spec/dummy/config/application.rb +28 -0
  29. data/spec/dummy/config/application.yml +12 -0
  30. data/spec/dummy/config/boot.rb +5 -0
  31. data/spec/dummy/config/cable.yml +9 -0
  32. data/spec/dummy/config/database.yml +25 -0
  33. data/spec/dummy/config/environment.rb +5 -0
  34. data/spec/dummy/config/environments/development.rb +47 -0
  35. data/spec/dummy/config/environments/production.rb +78 -0
  36. data/spec/dummy/config/environments/test.rb +42 -0
  37. data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
  38. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/spec/dummy/config/initializers/cors.rb +16 -0
  40. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  41. data/spec/dummy/config/initializers/inflections.rb +16 -0
  42. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  43. data/spec/dummy/config/initializers/new_framework_defaults.rb +18 -0
  44. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  45. data/spec/dummy/config/locales/en.yml +23 -0
  46. data/spec/dummy/config/puma.rb +47 -0
  47. data/spec/dummy/config/routes.rb +3 -0
  48. data/spec/dummy/config/secrets.yml +22 -0
  49. data/spec/dummy/config/spring.rb +6 -0
  50. data/spec/dummy/db/development.sqlite3 +0 -0
  51. data/spec/dummy/db/schema.rb +15 -0
  52. data/spec/dummy/db/test.sqlite3 +0 -0
  53. data/spec/dummy/log/development.log +7 -0
  54. data/spec/dummy/log/test.log +4831 -0
  55. data/spec/lib/exes_poster/configurator_spec.rb +47 -0
  56. data/spec/lib/exes_poster/poster_spec.rb +80 -0
  57. data/spec/lib/exes_poster/version_spec.rb +11 -0
  58. data/spec/rails_helper.rb +62 -0
  59. data/spec/spec_helper.rb +99 -0
  60. data/spec/support/hooks.rb +5 -0
  61. metadata +174 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b88589a7be0db10bd1f45dc664398f03677feff1
4
+ data.tar.gz: c9ae68113d889217b670db6b59f737ed046a4318
5
+ SHA512:
6
+ metadata.gz: a3dda28c49b55920fb1a6dfb728a8bc0e85e4cc766b7d2300b9c744d0d9d05df4d2b2ea1af1076119a7482c9b9373149dddbb66a7d26c891adf44c49e9aefa10
7
+ data.tar.gz: 277ae0ed64f62c580ded7dc101de9ca9d4a688b2629ac9d67a0403d910f375208a97e42fac9f65d064b2da85ae66da40a25019e474239fe107091158a4bb5a03
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Takahiro HAMAGUCHI
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,100 @@
1
+ ExesPoster
2
+ ========
3
+
4
+ ExesPoster is an exception post tool to Elasticsearch.
5
+
6
+ Installation
7
+ -----
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'exes_poster'
13
+ ```
14
+
15
+ And then execute:
16
+ ```bash
17
+ $ bundle
18
+ ```
19
+
20
+ Or install it yourself as:
21
+ ```bash
22
+ $ gem install exes_poster
23
+ ```
24
+
25
+
26
+ Getting Started
27
+ -----
28
+
29
+ 1. To set an environment variable "ELASTICSEARCH_URL"
30
+ ```bash
31
+ $ export ELASTICSEARCH_URL=localhost:9200
32
+ ```
33
+
34
+ 2. Call `ExesPoster.post_exception` with caught exception in the rescue section.
35
+ ```ruby
36
+ require 'exes_poster'
37
+
38
+ begin
39
+ raise RuntimeError, 'hoge'
40
+ rescue => e
41
+ ExesPoster.post_exception(e)
42
+ end
43
+ ```
44
+
45
+ 3. You can find exception information at your elasticsearch.
46
+ ```javascript
47
+ {
48
+ "_index" : "exes_index",
49
+ "_type" : "exception",
50
+ "_id" : "eIb4VGPbRB6tw0eGnUXUXA",
51
+ "_version" : 1,
52
+ "found" : true,
53
+ "_source" : {
54
+ "message" : "hoge",
55
+ "@timestamp" : "2016-09-21T16:28:09.753+09:00",
56
+ "detail" : {
57
+ "class" : "RuntimeError",
58
+ "backtrace" : [
59
+ "/PATH/TO/ERROR/FILE1.rb:123:in `block (3 levels) in <top (required)>'",
60
+ "/PATH/TO/ERROR/FILE2.rb:456:in `block (2 levels) in function'",
61
+ "/PATH/TO/ERROR/FILE3.rb:15:in `<main>'"
62
+ ]
63
+ }
64
+ }
65
+ }
66
+ ```
67
+
68
+ in Japanese
69
+ -----
70
+ * [使い方](features/post_exception_to_elasticsearch.feature)
71
+
72
+
73
+ Configuration
74
+ -----
75
+
76
+ You can set Elasticsearch url and index name.
77
+
78
+ ```ruby
79
+ ExesPoster.setup do |config|
80
+ config.es_url = 'example.com:9200'
81
+ config.es_index = 'hoge_test'
82
+ end
83
+ ```
84
+
85
+ Test
86
+ -----
87
+
88
+ 1. You set an environment variable DOCKER_HOST or ELASTICSEARCH_URL
89
+ ```bash
90
+ $ export ELASTICSEARCH_URL=localhost:9200
91
+ ```
92
+ or
93
+ ```bash
94
+ $ eval $(docker-machine env default)
95
+ ```
96
+
97
+ 2. Then exec rake
98
+ ```bash
99
+ $ bundle exec rake
100
+ ```
@@ -0,0 +1,58 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ default_tasks = []
8
+
9
+ begin
10
+ require 'rspec/core/rake_task'
11
+ RSpec::Core::RakeTask.new(:spec) do |t|
12
+ t.rspec_opts = "-fd"
13
+ end
14
+ default_tasks << :spec
15
+ rescue LoadError
16
+ end
17
+
18
+ begin
19
+ require 'cucumber/rake/task'
20
+ Cucumber::Rake::Task.new(:features) do |t|
21
+ t.cucumber_opts = "features --format pretty"
22
+ end
23
+ default_tasks << :features
24
+ rescue LoadError
25
+ end
26
+
27
+ begin
28
+ require 'yard'
29
+ require 'yard/rake/yardoc_task'
30
+ YARD::Rake::YardocTask.new do |t|
31
+ t.files = ['app/controllers/**/*.rb','app/helpers/**/*.rb', 'app/mailers/**/*.rb', 'app/models/**/*.rb', 'lib/**/*.rb']
32
+ t.options = []
33
+ t.options << '--debug' << '--verbose' if $trace
34
+ end
35
+ default_tasks << :yard
36
+ rescue LoadError
37
+ end
38
+
39
+ begin
40
+ require 'rubocop/rake_task'
41
+ RuboCop::RakeTask.new
42
+ default_tasks << :rubocop
43
+ rescue LoadError
44
+ end
45
+
46
+ desc 'Generate docs'
47
+ task :docs do
48
+ system 'rm -rf docs'
49
+ system 'rspec spec -fh -o docs/rspec/index.html'
50
+ system 'mv coverage docs'
51
+ system 'mkdir -p docs/cucumber/'
52
+ system 'cucumber features -f html -o docs/cucumber/index.html'
53
+ system 'yardoc -o docs/yard'
54
+ system 'rubocop -fh -o docs/rubocop/index.html'
55
+ end
56
+
57
+ task default: default_tasks
58
+
@@ -0,0 +1,17 @@
1
+ require 'elasticsearch'
2
+
3
+ # ExesPoster
4
+ #
5
+ # @since 0.1.0
6
+ # @author tk.hamaguchi@gmail.com
7
+ #
8
+ module ExesPoster
9
+ @@es_url = ENV['ELASTICSEARCH_URL']
10
+ @@es_index = 'exes_index'
11
+
12
+ autoload :Configurator, 'exes_poster/configurator'
13
+ autoload :Poster, 'exes_poster/poster'
14
+
15
+ include Configurator
16
+ include Poster
17
+ end
@@ -0,0 +1,28 @@
1
+ module ExesPoster
2
+ # ExesPoster::Configurator
3
+ #
4
+ # @since 0.1.0
5
+ # @author tk.hamaguchi@gmail.com
6
+ #
7
+ module Configurator
8
+ def self.included(klass)
9
+ klass.class_variables.each do |var|
10
+ sym = var.to_s.gsub(/^@@/, '').to_sym
11
+ klass.class_eval <<-EOS
12
+ def self.#{sym}()
13
+ return @@#{sym}
14
+ end
15
+
16
+ def self.#{sym}=(obj)
17
+ @@#{sym} = obj
18
+ end
19
+ EOS
20
+ end
21
+ klass.class_eval <<-EOS
22
+ def self.setup
23
+ yield self
24
+ end
25
+ EOS
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,39 @@
1
+ module ExesPoster
2
+ # ExesPoster::Poster
3
+ #
4
+ # @since 0.1.0
5
+ # @author tk.hamaguchi@gmail.com
6
+ #
7
+ module Poster
8
+ def self.included(klass)
9
+ klass.module_eval do
10
+ def self.post(type, message, detail = nil)
11
+ body = {
12
+ message: message,
13
+ '@timestamp' => Time.now.iso8601(3)
14
+ }
15
+ body[:detail] = detail unless detail.nil?
16
+
17
+ c = Elasticsearch::Client.new(url: es_url)
18
+ d = c.index(
19
+ index: es_index,
20
+ type: type,
21
+ body: body,
22
+ refresh: true
23
+ )
24
+
25
+ d['_id']
26
+ end
27
+
28
+ def self.post_exception(e)
29
+ post(
30
+ :exception,
31
+ e.message,
32
+ class: e.class.name,
33
+ backtrace: e.backtrace
34
+ )
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module ExesPoster
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :exes_poster do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,2 @@
1
+
2
+ //= link_directory ../stylesheets .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::API
2
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a starting point to setup your application.
15
+ # Add necessary setup steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ # puts "\n== Copying sample files =="
22
+ # unless File.exist?('config/database.yml')
23
+ # cp 'config/database.yml.sample', 'config/database.yml'
24
+ # end
25
+
26
+ puts "\n== Preparing database =="
27
+ system! 'bin/rails db:setup'
28
+
29
+ puts "\n== Removing old logs and tempfiles =="
30
+ system! 'bin/rails log:clear tmp:clear'
31
+
32
+ puts "\n== Restarting application server =="
33
+ system! 'bin/rails restart'
34
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a way to update your development environment automatically.
15
+ # Add necessary update steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ puts "\n== Updating database =="
22
+ system! 'bin/rails db:migrate'
23
+
24
+ puts "\n== Removing old logs and tempfiles =="
25
+ system! 'bin/rails log:clear tmp:clear'
26
+
27
+ puts "\n== Restarting application server =="
28
+ system! 'bin/rails restart'
29
+ end