try_chain 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 14d6a789436ec1604723c95725e3487392024b83
4
+ data.tar.gz: d52cd81401591846e63d971fa3502fc6dc5b5052
5
+ SHA512:
6
+ metadata.gz: 64a0bd52f604658ff9c5ceab1fe7652ec413f4fa3110ce52e3bdacbe23673899ad04a70b46cb7d62a0a6d49f167bcedf7a4a222dd184e6600eec87902519a328
7
+ data.tar.gz: 3f82ad4034acf35be5d78da858a80cc5d2bf847f448de0f02a31102a6e92eaf87270baa434745d4be83ee704df95a13bc6b20d9a83e4f9691ec91dd9fd01304d
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .ruby-*
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in try_chain.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Brandon Dewitt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # TryChain
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'try_chain'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install try_chain
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ desc "Run specs (default)"
8
+ task :default => :spec
9
+
10
+ Dir["lib/tasks/**/*.rake"].each { |ext| load ext } if defined?(Rake)
@@ -0,0 +1,31 @@
1
+ require "try_chain/version"
2
+ require "active_support/core_ext/object/try"
3
+
4
+ module TryChain
5
+
6
+ def self.proxy_try_chain(object, *chain)
7
+ object.extend(::TryChain::InstanceMethods)
8
+
9
+ return object.try_chain(chain)
10
+ end
11
+
12
+ class << self
13
+ alias_method :call, :proxy_try_chain
14
+ alias_method :proxied_try_chain, :proxy_try_chain
15
+ end
16
+
17
+ module InstanceMethods
18
+ def try_chain(*symbols)
19
+ return nil if self.nil?
20
+
21
+ symbols = symbols.flatten
22
+ symbols.compact!
23
+
24
+ symbols.reduce(self) do |result, symbol|
25
+ result = result.try(symbol)
26
+ break nil if result.nil?
27
+ result
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,11 @@
1
+ require 'try_chain'
2
+
3
+ class Object
4
+ include ::TryChain::InstanceMethods
5
+ end
6
+
7
+ class NilClass
8
+ def try_chain(*args)
9
+ return nil
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module TryChain
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ ::Bundler.require(:default, :development, :test)
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::TryChain do
4
+
5
+ context "#proxy_try_chain" do
6
+
7
+ it "returns nil when nil given" do
8
+ ::TryChain.proxy_try_chain(nil, :derp, :derp).should be_nil
9
+ end
10
+
11
+ it "returns nil when first level try returns nil" do
12
+ mock_it = double(Object)
13
+ mock_it.stub(:derp) { nil }
14
+ ::TryChain.proxy_try_chain(mock_it, :derp, :derp).should be_nil
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'try_chain/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "try_chain"
8
+ gem.version = TryChain::VERSION
9
+ gem.authors = ["Brandon Dewitt"]
10
+ gem.email = ["brandonsdewitt@gmail.com"]
11
+ gem.description = %q{ using try that takes an array of chainable try calls }
12
+ gem.summary = %q{ don't use this unless you really need to use it, it is bad form to have "try all the way down"
13
+ This was really built for JRuby applications to deal with custom typing in the Java side that
14
+ requires tons of intermediary objects to actually get to an object that is "usable"
15
+ (that MIGHT be a good use-case, but probably not) }
16
+ gem.homepage = ""
17
+
18
+ gem.files = `git ls-files`.split($/)
19
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
+ gem.require_paths = ["lib"]
22
+
23
+ gem.add_dependency "activesupport"
24
+
25
+ gem.add_development_dependency "bundler", "~> 1.3"
26
+ gem.add_development_dependency "rake"
27
+ gem.add_development_dependency "rspec"
28
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: try_chain
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Dewitt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ' using try that takes an array of chainable try calls '
70
+ email:
71
+ - brandonsdewitt@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/try_chain.rb
82
+ - lib/try_chain/core_ext/object/try_chain.rb
83
+ - lib/try_chain/version.rb
84
+ - spec/spec_helper.rb
85
+ - spec/try_chain_spec.rb
86
+ - try_chain.gemspec
87
+ homepage: ''
88
+ licenses: []
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.0.3
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: don't use this unless you really need to use it, it is bad form to have "try
110
+ all the way down" This was really built for JRuby applications to deal with custom
111
+ typing in the Java side that requires tons of intermediary objects to actually get
112
+ to an object that is "usable" (that MIGHT be a good use-case, but probably not)
113
+ test_files:
114
+ - spec/spec_helper.rb
115
+ - spec/try_chain_spec.rb