try_to 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/try_to.rb +9 -11
  3. data/try_to.gemspec +1 -1
  4. metadata +11 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97985eb519dbff474a97eec6322beed1007b6de0
4
- data.tar.gz: a86fadb1eab2dae7e6db0192faf3a7a21e27f82f
3
+ metadata.gz: b265e05b456bcddae7647ac5108450bd176c8973
4
+ data.tar.gz: 1ffc1e94a179cb3aa60f91bdc91beaa5a5e43cc3
5
5
  SHA512:
6
- metadata.gz: c7cba069537e556aca316a11969cd7d566ec037e7025a65ab2a513ee487c10620ba7376ad1f52d6dac69fa2637b31145fe79b052377ceceed62acace871f4c6d
7
- data.tar.gz: 3cd82c83dc4ece5b8efbc92f33908ef978f5f8e80802d7363f9b589a3135d887bee37f7ee7da3c3b1570e6e3fa0bc1690868aeca9bd58eb4e7f2fa7ba4d623c6
6
+ metadata.gz: 02b58ac470c79cc489476f677362f2809679e723f434485a27bdc5936109502a0be7173789916241e6b3b5ddb8b0c25b51b3e0e47488430017c99c3f444a79bc
7
+ data.tar.gz: 8d796018c77b4c7147ecae7d08be9dc4473b77cb7ef7849c004dbdbca5cc4a5f16067d970048b63178b09b4d6dbd302b822eb6f3370eecbeb8ad0d8c48563b66
data/lib/try_to.rb CHANGED
@@ -1,26 +1,24 @@
1
1
  module TryTo
2
2
  class << self
3
- attr_accessor :exceptions, :default_handler, :handlers
4
- private :handlers=
3
+ attr_accessor :default_handler
4
+ attr_reader :exceptions, :handlers
5
5
  end
6
6
 
7
7
  def self.add_handler(exception, handler)
8
- self.handlers.merge!(exception => handler)
8
+ @handlers.merge!(exception => handler)
9
9
  end
10
10
 
11
- self.handlers = {}
12
- self.exceptions = [NoMethodError]
11
+ @handlers = {}
12
+ @exceptions = [NoMethodError]
13
13
  end
14
14
 
15
15
  module Kernel
16
- def try_to(handler = nil, &block)
17
- block.call if block
16
+ def try_to(handler = nil)
17
+ yield if block_given?
18
18
  rescue *(TryTo.exceptions | TryTo.handlers.keys) => e
19
- handler = [
20
- handler,
19
+ handler = [handler,
21
20
  TryTo.handlers[e.class],
22
- TryTo.default_handler
23
- ].compact.first
21
+ TryTo.default_handler].compact.first
24
22
  handler.respond_to?(:call) ? handler.call(e) : handler
25
23
  end
26
24
 
data/try_to.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
12
  gem.name = 'try_to'
13
13
  gem.require_paths = ['lib']
14
- gem.version = '1.0'
14
+ gem.version = '1.1'
15
15
 
16
16
  gem.add_development_dependency 'rake'
17
17
  gem.add_development_dependency 'rspec', '~>2.9.0'
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: try_to
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Kohl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-24 00:00:00.000000000 Z
11
+ date: 2015-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 2.9.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.9.0
41
41
  description: Try methods without exceptions
@@ -45,8 +45,8 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
49
- - .rspec
48
+ - ".gitignore"
49
+ - ".rspec"
50
50
  - Gemfile
51
51
  - LICENSE
52
52
  - README.md
@@ -64,17 +64,17 @@ require_paths:
64
64
  - lib
65
65
  required_ruby_version: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 2.0.3
77
+ rubygems_version: 2.4.5
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: An alternative approach to Rails' Object#try