yaml_notifier 0.0.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 +7 -0
- data/.gitignore +34 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +34 -0
- data/LICENSE +21 -0
- data/README.md +4 -0
- data/lib/exception_notifier/yaml_notifier.rb +31 -0
- data/lib/yaml_notifier.rb +7 -0
- data/lib/yaml_notifier/exception_log.rb +7 -0
- data/lib/yaml_notifier/railtie.rb +7 -0
- data/lib/yaml_notifier/version.rb +3 -0
- data/test/base_test.rb +193 -0
- data/test/test_helper.rb +17 -0
- data/yaml_notifier.gemspec +22 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: be95fcd186e78298b3ad782b0886dbfe460e19d7
|
4
|
+
data.tar.gz: 8b242988424a6f4761be2f2336964dea91559aab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f368bdb067d0d77efd70934dae8e8209131de76a773a788e4cba0a62447201669035c614a292e7a481c93bbe4663af40416c4450ea38dc6ac2a7fef53fc1ed8b
|
7
|
+
data.tar.gz: c3c6f540ff789646c7c7d53ff23359e30a04887fa187d69eb4f9b9306abc5ab8e50ea5eedfe7ed68753207e12c4029857a4622cb69830caed15877d8c3e43ab3
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
yaml_notifier (0.0.1)
|
5
|
+
yaml_record4 (= 0.0.6)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (4.1.5)
|
11
|
+
activesupport (= 4.1.5)
|
12
|
+
builder (~> 3.1)
|
13
|
+
activesupport (4.1.5)
|
14
|
+
i18n (~> 0.6, >= 0.6.9)
|
15
|
+
json (~> 1.7, >= 1.7.7)
|
16
|
+
minitest (~> 5.1)
|
17
|
+
thread_safe (~> 0.1)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
builder (3.2.2)
|
20
|
+
i18n (0.6.11)
|
21
|
+
json (1.8.1)
|
22
|
+
minitest (5.4.1)
|
23
|
+
thread_safe (0.3.4)
|
24
|
+
tzinfo (1.2.2)
|
25
|
+
thread_safe (~> 0.1)
|
26
|
+
yaml_record4 (0.0.6)
|
27
|
+
activemodel (>= 4.0)
|
28
|
+
activesupport (>= 4.0)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
yaml_notifier!
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Thierry Zires
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'yaml_notifier/exception_log'
|
2
|
+
|
3
|
+
module ExceptionNotifier
|
4
|
+
class YamlNotifier
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
# initialize options here
|
8
|
+
@extra_params = options[:extra_params] || []
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(exception, options={})
|
12
|
+
log = ::YamlNotifier::ExceptionLog.new({
|
13
|
+
title: exception.inspect,
|
14
|
+
message: exception.message,
|
15
|
+
backtrace: exception.backtrace.join("\n")
|
16
|
+
})
|
17
|
+
|
18
|
+
env = options[:env]
|
19
|
+
unless env.nil?
|
20
|
+
log.user_agent = env['HTTP_USER_AGENT']
|
21
|
+
log.request_uri = env['REQUEST_URI']
|
22
|
+
log.request_method = env['REQUEST_METHOD']
|
23
|
+
log.controller = env['action_dispatch.request.path_parameters'][:controller]
|
24
|
+
log.action = env['action_dispatch.request.path_parameters'][:action]
|
25
|
+
log.extra_params = @extra_params.map{|p| env[p]} unless @extra_params.empty?
|
26
|
+
end
|
27
|
+
|
28
|
+
log.save
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/test/base_test.rb
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class YamlObject < YamlRecord::Base
|
4
|
+
properties :title, :body, :child_ids
|
5
|
+
source File.dirname(__FILE__) + "/../tmp/yaml_object"
|
6
|
+
end
|
7
|
+
|
8
|
+
class BaseTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@obj_title = "Simple Title"
|
12
|
+
@obj_id = "1234"
|
13
|
+
@obj2_id = "5678"
|
14
|
+
@obj2_title = "Simple Title 2"
|
15
|
+
|
16
|
+
@attr = {
|
17
|
+
:child_ids => [@obj_id],
|
18
|
+
:title => @obj_title,
|
19
|
+
:body => "Body!!"
|
20
|
+
}
|
21
|
+
|
22
|
+
@attr2 = {
|
23
|
+
:child_ids => [@obj2_id],
|
24
|
+
:title => @obj2_title,
|
25
|
+
:body => "Body!!"
|
26
|
+
}
|
27
|
+
|
28
|
+
clean_yaml_record(YamlObject)
|
29
|
+
@fs = YamlObject.create(@attr)
|
30
|
+
end
|
31
|
+
|
32
|
+
context "for instance methods" do
|
33
|
+
|
34
|
+
context "for [] method" do
|
35
|
+
should("get attribute with [attribute]"){ assert_equal @fs.title, @fs[:title] }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "for []= method" do
|
39
|
+
setup do
|
40
|
+
@fs[:title] = "Toto"
|
41
|
+
end
|
42
|
+
should("set attribute with [attribute]="){ assert_equal @fs[:title], "Toto" }
|
43
|
+
end
|
44
|
+
|
45
|
+
context "for save method" do
|
46
|
+
setup do
|
47
|
+
@fs2 = YamlObject.new(@attr)
|
48
|
+
@fs2.save
|
49
|
+
end
|
50
|
+
|
51
|
+
should("save on yaml file"){ assert_equal YamlObject.last.attributes.diff(@attr), {:id => @fs2.reload.id } }
|
52
|
+
end
|
53
|
+
|
54
|
+
context "for update_attributes method" do
|
55
|
+
setup do
|
56
|
+
@fs.update_attributes(:title => "Toto", :body => "http://somewhereelse.com")
|
57
|
+
@fs.reload
|
58
|
+
end
|
59
|
+
should("update title") { assert_equal @fs.title, "Toto" }
|
60
|
+
should("update body") { assert_equal @fs.body, "http://somewhereelse.com" }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "for column_names method" do
|
64
|
+
should("return an array with attributes names") { assert_equal @fs.column_names.sort!, YamlObject.properties.map { |p| p.to_s }.sort! }
|
65
|
+
end
|
66
|
+
|
67
|
+
context "for persisted_attributes method" do
|
68
|
+
should("return persisted attributes") { assert_equal [:title, :body, :child_ids, :id ].sort_by {|sym| sym.to_s}, @fs.persisted_attributes.keys.sort_by {|sym| sym.to_s} }
|
69
|
+
end
|
70
|
+
|
71
|
+
context "for new_record? method" do
|
72
|
+
setup do
|
73
|
+
@fs3 = YamlObject.new
|
74
|
+
end
|
75
|
+
should("be a new record") { assert @fs3.new_record? }
|
76
|
+
should("not be a new record") { assert_false @fs.new_record? }
|
77
|
+
end
|
78
|
+
|
79
|
+
context "for destroyed? method" do
|
80
|
+
setup do
|
81
|
+
@fs4 = YamlObject.create(@attr)
|
82
|
+
@fs4.destroy
|
83
|
+
end
|
84
|
+
should("be a destoyed") { assert @fs4.destroyed? }
|
85
|
+
should("not be destroyed") { assert_false @fs.destroyed? }
|
86
|
+
end
|
87
|
+
|
88
|
+
context "for destroy method" do
|
89
|
+
setup do
|
90
|
+
@fs5 = YamlObject.create(@attr)
|
91
|
+
@fs5.destroy
|
92
|
+
end
|
93
|
+
should("not find @fs5"){ assert_nil YamlObject.find(@fs5.id) }
|
94
|
+
end
|
95
|
+
|
96
|
+
context "for reload method" do
|
97
|
+
setup do
|
98
|
+
@fs.title = "Foo"
|
99
|
+
end
|
100
|
+
should("equal to Foo"){ assert_equal @fs.title, "Foo" }
|
101
|
+
should("equal to correct title"){ assert_equal @fs.reload.title, @obj_title }
|
102
|
+
end
|
103
|
+
|
104
|
+
context "for to_param method" do
|
105
|
+
setup { @fs.id = "a1b2c3" }
|
106
|
+
|
107
|
+
should("return id of record") { assert_equal(@fs.to_param, @fs.id) }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "for class methods" do
|
112
|
+
context "for self.find_by_attribute method" do
|
113
|
+
setup do
|
114
|
+
@fs_found = YamlObject.find_by_attribute(:title, @obj_title)
|
115
|
+
end
|
116
|
+
should("be same object as @fs"){ assert_equal @fs_found, YamlObject.find(@fs.id) }
|
117
|
+
end
|
118
|
+
|
119
|
+
context "for self.find_by_id method" do
|
120
|
+
setup do
|
121
|
+
@fs_found = YamlObject.find_by_id(@fs.id)
|
122
|
+
@fs_found2 = YamlObject.find(@fs.id)
|
123
|
+
end
|
124
|
+
should("be same object as @fs"){ assert_equal @fs.attributes, @fs_found.attributes }
|
125
|
+
should("be same object as @fs bis"){ assert_equal @fs.attributes, @fs_found2.attributes }
|
126
|
+
end
|
127
|
+
|
128
|
+
context "for self.all method" do
|
129
|
+
setup do
|
130
|
+
clean_yaml_record(YamlObject)
|
131
|
+
@fs, @fs2 = YamlObject.create(@attr), YamlObject.create(@attr2)
|
132
|
+
end
|
133
|
+
should("retrieve 2 YamlObject obj"){ assert_equal YamlObject.all.size, 2 }
|
134
|
+
should("return as first item @fs"){ assert_equal YamlObject.all.first.attributes, @fs.attributes }
|
135
|
+
should("return as last item @fs2"){ assert_equal YamlObject.all.last.attributes, @fs2.attributes }
|
136
|
+
end
|
137
|
+
|
138
|
+
context "for self.first method" do
|
139
|
+
setup do
|
140
|
+
clean_yaml_record(YamlObject)
|
141
|
+
@fs, @fs2 = YamlObject.create(@attr), YamlObject.create(@attr2)
|
142
|
+
end
|
143
|
+
|
144
|
+
should("return @fs as the first item"){ assert_equal YamlObject.first.attributes, @fs.attributes }
|
145
|
+
should("return @fs"){ assert_equal YamlObject.first(2).first.attributes, @fs.attributes }
|
146
|
+
should("return @fs2"){ assert_equal YamlObject.first(2).last.attributes, @fs2.attributes }
|
147
|
+
end
|
148
|
+
|
149
|
+
context "for self.last method" do
|
150
|
+
setup do
|
151
|
+
clean_yaml_record(YamlObject)
|
152
|
+
@fs, @fs2 = YamlObject.create(@attr), YamlObject.create(@attr2)
|
153
|
+
end
|
154
|
+
|
155
|
+
should("return @fs as the first item"){ assert_equal YamlObject.last.attributes, @fs2.attributes }
|
156
|
+
should("return @fs"){ assert_equal YamlObject.last(2).first.attributes, @fs.attributes }
|
157
|
+
should("return @fs2"){ assert_equal YamlObject.last(2).last.attributes, @fs2.attributes }
|
158
|
+
end
|
159
|
+
|
160
|
+
context "for self.write_contents method" do
|
161
|
+
setup do
|
162
|
+
clean_yaml_record(YamlObject)
|
163
|
+
@attributes = [ @attr, @attr2 ]
|
164
|
+
YamlObject.write_contents(@attributes)
|
165
|
+
end
|
166
|
+
should("write in yaml file"){ assert_equal YAML.load_file(YamlObject.source), [ @attr, @attr2 ] }
|
167
|
+
end
|
168
|
+
|
169
|
+
context "for self.create method" do
|
170
|
+
setup do
|
171
|
+
clean_yaml_record(YamlObject)
|
172
|
+
@fs = YamlObject.create(@attr)
|
173
|
+
@fs_not_created = YamlObject.new(@attr)
|
174
|
+
end
|
175
|
+
should("create @fs"){ assert_equal YamlObject.last.attributes, @fs.attributes }
|
176
|
+
should("set its is_created to true"){ assert @fs.is_created }
|
177
|
+
should("set @fs_not_created is_created field to false"){ assert_false @fs_not_created.is_created }
|
178
|
+
end
|
179
|
+
|
180
|
+
context "for set_id!" do
|
181
|
+
setup do
|
182
|
+
@fs_no_id = YamlObject.new(@attr)
|
183
|
+
@fs_with_id = YamlObject.create(@attr)
|
184
|
+
@id = @fs_with_id.id
|
185
|
+
@fs_with_id.update_attributes(:title => "Gomiso")
|
186
|
+
end
|
187
|
+
should("not have any id"){ assert_nil @fs_no_id.id }
|
188
|
+
should("have a id"){ assert @fs_with_id.id }
|
189
|
+
should("keep the same id"){ assert_equal @fs_with_id.id, @id }
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
#require 'test/unit'
|
4
|
+
require 'shoulda'
|
5
|
+
require File.dirname(__FILE__) + "/../lib/yaml_record"
|
6
|
+
|
7
|
+
class Test::Unit::TestCase
|
8
|
+
def clean_yaml_record(class_record)
|
9
|
+
File.open(class_record.source, 'w') {|f| f.write(nil) }
|
10
|
+
end
|
11
|
+
|
12
|
+
# Asserts that the condition is not true
|
13
|
+
# assert_false @title == "hey"
|
14
|
+
def assert_false(condition, message='')
|
15
|
+
assert !condition, message
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "yaml_notifier/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "yaml_notifier"
|
7
|
+
s.version = YamlNotifier::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Thierry Zires"]
|
10
|
+
s.email = ["zshuaibin@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/zires/yaml_notifier"
|
12
|
+
s.summary = %q{save exceptions in yaml when exception_notification occur}
|
13
|
+
s.description = %q{save exceptions in yaml when exception_notification occur}
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.add_dependency 'yaml_record4', '= 0.0.6'
|
21
|
+
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yaml_notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thierry Zires
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: yaml_record4
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.6
|
27
|
+
description: save exceptions in yaml when exception_notification occur
|
28
|
+
email:
|
29
|
+
- zshuaibin@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
|
+
- LICENSE
|
38
|
+
- README.md
|
39
|
+
- lib/exception_notifier/yaml_notifier.rb
|
40
|
+
- lib/yaml_notifier.rb
|
41
|
+
- lib/yaml_notifier/exception_log.rb
|
42
|
+
- lib/yaml_notifier/railtie.rb
|
43
|
+
- lib/yaml_notifier/version.rb
|
44
|
+
- test/base_test.rb
|
45
|
+
- test/test_helper.rb
|
46
|
+
- yaml_notifier.gemspec
|
47
|
+
homepage: https://github.com/zires/yaml_notifier
|
48
|
+
licenses: []
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.1.11
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: save exceptions in yaml when exception_notification occur
|
70
|
+
test_files:
|
71
|
+
- test/base_test.rb
|
72
|
+
- test/test_helper.rb
|
73
|
+
has_rdoc:
|