dm-noisy-failures 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/data_mapper/noisy_failures/version.rb +5 -0
- data/lib/data_mapper/resource.rb +50 -0
- metadata +84 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Resource
|
3
|
+
alias_method :save?, :save
|
4
|
+
alias_method :destroy?, :destroy
|
5
|
+
|
6
|
+
def save
|
7
|
+
unless self.save?
|
8
|
+
error_message = self.errors.map { |e| "#{self.class}: #{e.join(', ')}" }.join("\n")
|
9
|
+
raise SaveFailureError.new(error_message, self)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def destroy
|
14
|
+
unless self.destroy?
|
15
|
+
error_message = "#{self.class}: Unable to destroy, probably due to associated records."
|
16
|
+
raise SaveFailureError.new(error_message, self)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def update?(*args)
|
21
|
+
self.update(*args)
|
22
|
+
true
|
23
|
+
rescue => e
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.included(base)
|
28
|
+
def base.create?(*args)
|
29
|
+
self.create(*args)
|
30
|
+
rescue => e
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# If any library authors have overridden this, we're screwed.
|
36
|
+
# TODO: Figure out if it's possible to detect that case.
|
37
|
+
original_include_method = Class.instance_method(:include?)
|
38
|
+
|
39
|
+
# TODO: Maybe look into not just duplicating the above code here?
|
40
|
+
ObjectSpace.each_object(Class).each do |existing_class|
|
41
|
+
if original_include_method.bind(existing_class).call(Resource)
|
42
|
+
def existing_class.create?(*args)
|
43
|
+
self.create(*args)
|
44
|
+
rescue => e
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dm-noisy-failures
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Daniel Tao
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-09-15 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: data_mapper
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: |
|
35
|
+
This library replaces the default behavior of DataMapper by raising exceptions *with
|
36
|
+
descriptive error messages* whenever DB operations are not successfully completed.
|
37
|
+
|
38
|
+
email:
|
39
|
+
- daniel.tao@gmail.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- lib/data_mapper/noisy_failures/version.rb
|
48
|
+
- lib/data_mapper/resource.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/dtao/dm-noisy-failures
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
hash: 3
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
version: "0"
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.4.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Noisy (and descriptive) failures for DataMapper
|
83
|
+
test_files: []
|
84
|
+
|