complain 1.0.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
+ SHA1:
3
+ metadata.gz: a78852e2ff4d9f535aee93606f77044efaeb0233
4
+ data.tar.gz: 3b7d011692d0926f939fee3fc54c8cb77992576d
5
+ SHA512:
6
+ metadata.gz: a4d6ae8db2e4b3a876db7cee1a8bdd352c3d1f863e39b596b58ae44392bfdc7f95c5df34c38bfadd4d9f3e140beffb677abf21bad889b09b122e645a72e80af9
7
+ data.tar.gz: a3eec24b42e59a77fce35e4c8cb42e81f6581dc75e1d31f96f1ad0096663ef717c314ae198e8166eef4810b0c6794238bd3767e104300494ef2b525836e7140b
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.idea/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.byebug_history
11
+ /Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ - ruby-head
8
+ - rbx-2
9
+
10
+ gemfile:
11
+ - Gemfile
12
+
13
+ sudo: false
14
+
15
+ script: "bundle exec rspec"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in complain.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Complain
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'complain'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install complain
18
+
19
+ ## Usage
20
+
21
+ Just replace
22
+
23
+ ```ruby
24
+ rescue => exc
25
+ $stderr.puts
26
+ $stderr.puts Time.now
27
+ $stderr.puts exc.message
28
+ $stderr.puts exc.backtrace.join("\n")
29
+ end
30
+ ```
31
+
32
+ with
33
+
34
+ ```ruby
35
+ rescue => exc
36
+ Complain.(exc)
37
+ end
38
+ ```
39
+
40
+ ## Development
41
+
42
+ 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.
43
+
44
+
45
+ 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).
46
+
47
+ ## Contributing
48
+
49
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/complain.
50
+
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "complain"
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
data/bin/setup ADDED
@@ -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
data/complain.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'complain/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "complain"
8
+ spec.version = Complain::VERSION
9
+ spec.authors = ["Roman"]
10
+ spec.email = ["urvala@gmail.com"]
11
+
12
+ spec.summary = %q{Complain - simple exception to logs writer.}
13
+ spec.description = %q{Complain can output exceptions to stderr, stdout, loggers with single-line call.}
14
+ spec.homepage = "https://github.com/appelsin/complain"
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.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ end
data/lib/complain.rb ADDED
@@ -0,0 +1,57 @@
1
+ require "complain/version"
2
+
3
+ # One-liner exception process
4
+ #
5
+ # # replace
6
+ # rescue => exc
7
+ # $stderr.puts exc.message
8
+ # $stderr.puts exc.backtrace
9
+ # end
10
+ # # with
11
+ # rescue => exc
12
+ # Complain.(exc)
13
+ # end
14
+ #
15
+ module Complain
16
+ # Calls exception writer
17
+ # @param [Exception] exc Exception to write.
18
+ # @param [Mixed] logger Logger - can be `:stderr`, `:stdout` or should respond to `error` or `puts`
19
+ # @option [Boolean] :skip_exc - By default (false) internal exceptions will be rescued and written to logger,
20
+ # and exception will be raised only if second writing is failed;
21
+ # when set to true exception will not be handled.
22
+ def self.call(exc, logger = :stderr, skip_exc: false)
23
+ message = if exc.is_a?(Exception)
24
+ [exc.message, exc.backtrace.join("\n")].join("\n")
25
+ elsif exc.is_a?(String)
26
+ exc
27
+ elsif exc.respond_to?(:to_s)
28
+ exc.to_s
29
+ elsif exc.respond_to?(:inspect)
30
+ exc.inspect
31
+ else
32
+ "Message can't be processed at #{caller.join("\n")}"
33
+ end
34
+
35
+ if logger.nil? || :stderr == logger
36
+ $stderr.puts message
37
+ elsif :stdout == logger
38
+ $stdout.puts message
39
+ elsif :exception == logger
40
+ skip_exc = true
41
+ raise exc
42
+ elsif logger.respond_to?(:error)
43
+ logger.error message
44
+ elsif logger.respond_to?(:puts)
45
+ logger.puts message
46
+ else
47
+ skip_exc = true
48
+ Complain.("Can't write to logs:\n" + message, :exception, skip_exc: true)
49
+ end
50
+ rescue => exc
51
+ if skip_exc
52
+ raise exc
53
+ else
54
+ Complain.(exc, skip_exc: true)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module Complain
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: complain
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Roman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-04 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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
+ description: Complain can output exceptions to stderr, stdout, loggers with single-line
56
+ call.
57
+ email:
58
+ - urvala@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - complain.gemspec
72
+ - lib/complain.rb
73
+ - lib/complain/version.rb
74
+ homepage: https://github.com/appelsin/complain
75
+ licenses: []
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.6.4
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Complain - simple exception to logs writer.
97
+ test_files: []
98
+ has_rdoc: