try 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/try.rb +20 -23
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59d052acdfe93469250ccd32f028f0909d22ebc3
4
- data.tar.gz: 8af0c816b218d044e8f50fff90195b1c77e0189d
3
+ metadata.gz: bf2862d6d70b79ba5c2e897a48f8997afe3b73f7
4
+ data.tar.gz: f5539752a77ad04ae555b4f3133528705b47e292
5
5
  SHA512:
6
- metadata.gz: b87930d9e447137c7f0b324f063369ba6e2b5d06b499e31dac4a1550945e5edbc2617b8c920b1f6890adbc3530ca54e4df7c5b025efdfaba19cef6847351b605
7
- data.tar.gz: a6058c19afd7279d899d7274fff0574da95c301488fd0b629a66d246058ca84f84c718f750f399a4534b56e930e22eeb52524363c7572ce111b6b2d48b18dc03
6
+ metadata.gz: 66afc8ba7c914c47f91fab87e28fb11667d78f2ff5354254878ea95f34982c1be7c1e3160ad71df1537b3639cdfff16654c30887fd445110956c3de950529cbb
7
+ data.tar.gz: 5b7e26f86b575fe5e4d5a3038fcb969b498eb0dcd5d76a473921ad2bd637fb525604bc72acd5d35f91cddc601827412e0bdcd34d74164a0cb2e4ca23dd93d1a3
data/lib/try.rb CHANGED
@@ -9,13 +9,17 @@ by MOO Code through the following language constructs:
9
9
 
10
10
  In Ruby these become:
11
11
 
12
- Try.try { unsafe_expression }
12
+ Try.try { unsafe_expression } # OR: unsafe_expression rescue $!
13
13
  Try.trap(Exception=>fallback) { unsafe_expression } # OR: unsafe_expression rescue fallback
14
14
  Try.trap(FooError, BarError) { unsafe_expression}
15
15
  Try.trap(FooError=>fallback, BarError=>fallback) { unsafe_expression }
16
16
 
17
17
  =end
18
18
  module Try
19
+ # In #trap this can be used to map an class of exception to the
20
+ # raised exception itself.
21
+ ORIG = Object.new
22
+
19
23
  #
20
24
  # Evaluates the given block and returns its value.
21
25
  # If an exception is raised, that exception is returned instead.
@@ -35,7 +39,8 @@ module Try
35
39
  # Additionally, specific exception types can default to a fallback
36
40
  # value if passed as (({Type => value})) pairs. If the +value+ is
37
41
  # a Proc, it is called and the exception object is passed as a
38
- # parameter.
42
+ # parameter. If the +value+ is Try::ERROR, the exception object
43
+ # itself is returned.
39
44
  #
40
45
  # Any un-trapped exception is raised normally.
41
46
  #
@@ -51,7 +56,7 @@ module Try
51
56
  return ex if klass.instance_of?(Module) ? ex.kind_of?(klass) : ex.is_a?(klass)
52
57
  end
53
58
  hash.each_pair do |klass,value|
54
- return value.is_a?(Proc) ? value.call(ex) : value if klass.instance_of?(Module) ? ex.kind_of?(klass) : ex.is_a?(klass)
59
+ return value.is_a?(Proc) ? value.call(ex) : (value.equal?(ORIG) ? ex : value) if klass.instance_of?(Module) ? ex.kind_of?(klass) : ex.is_a?(klass)
55
60
  end
56
61
  raise
57
62
  end
@@ -79,26 +84,18 @@ module Try
79
84
  end
80
85
 
81
86
  =begin
82
- Copyright (c) 2013, Matthew Kerwin
83
- All rights reserved.
84
-
85
- Redistribution and use in source and binary forms, with or without
86
- modification, are permitted provided that the following conditions are met:
87
+ Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
87
88
 
88
- 1. Redistributions of source code must retain the above copyright notice, this
89
- list of conditions and the following disclaimer.
90
- 2. Redistributions in binary form must reproduce the above copyright notice,
91
- this list of conditions and the following disclaimer in the documentation
92
- and/or other materials provided with the distribution.
89
+ Permission to use, copy, modify, and/or distribute this software for any
90
+ purpose with or without fee is hereby granted, provided that the above
91
+ copyright notice and this permission notice appear in all copies.
93
92
 
94
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
95
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
96
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
97
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
98
- ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
99
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
100
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
101
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
102
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
103
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
93
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
94
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
95
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
96
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
97
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
98
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
99
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
104
100
  =end
101
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: try
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Kerwin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-21 00:00:00.000000000 Z
11
+ date: 2013-06-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Lazy mechanisms to capture exceptions on-the-fly.
14
14
  email: matthew@kerwin.net.au
@@ -19,7 +19,7 @@ files:
19
19
  - lib/try.rb
20
20
  homepage: http://rubygems.org/gems/try
21
21
  licenses:
22
- - Simplified BSD License
22
+ - ISC License
23
23
  metadata: {}
24
24
  post_install_message:
25
25
  rdoc_options:
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
44
  version: '0'
45
45
  requirements: []
46
46
  rubyforge_project:
47
- rubygems_version: 2.0.0
47
+ rubygems_version: 2.0.2
48
48
  signing_key:
49
49
  specification_version: 4
50
50
  summary: 'Try: do, or do not'