reactive_extensions 0.4.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +37 -0
- data/files.rb +13 -0
- data/lib/reactive_extensions/errors.rb +33 -0
- data/lib/reactive_extensions/scope.rb +60 -0
- data/lib/reactive_extensions/try_rescue.rb +57 -0
- data/lib/reactive_extensions.rb +21 -0
- data/reactive_extensions.gemspec +37 -0
- data/spec/array_spec.rb +76 -0
- data/spec/object_spec.rb +35 -0
- data/spec/proc_spec.rb +28 -0
- data/spec/spec_helper.rb +18 -0
- data/version.rb +14 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 95cfb507a96c0d13c7a2803a45676a934ec17591
|
4
|
+
data.tar.gz: 3c83c7f824369ef330b5c0c2774bf9dc7ec3b7f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3953d57a95c1fa8a2d8c6644fa9e2db88109ec331815abb35bbe52cf89dc0f7b4bd0c7775f85add15eb82e8c7a6a7c8604e75c77eec76056302ac3ddeacd87c3
|
7
|
+
data.tar.gz: 7319cd7d3e82094bd89905d4f001e66913bc13bb19ea4acf4f9906651eb8797c7cbab53a0e596e2036a2ecf33f3c04d2a5eeefd7b9a2b50f872ffa985e56a0f5
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Dana Scheider
|
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.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
## ReactiveExtensions
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/reactive_extensions.svg)](http://badge.fury.io/rb/reactive_extensions) [![Build Status](https://travis-ci.org/danascheider/reactive_extensions.svg?branch=master)](https://travis-ci.org/danascheider/reactive_extensions) [![Coverage Status](https://img.shields.io/coveralls/danascheider/reactive_extensions.svg)](https://coveralls.io/r/danascheider/reactive_extensions) [![Code Climate](https://codeclimate.com/github/danascheider/reactive_extensions/badges/gpa.svg)](https://codeclimate.com/github/danascheider/reactive_extensions) [![Inline docs](http://inch-ci.org/github/danascheider/reactive_extensions.svg?branch=master)](http://inch-ci.org/github/danascheider/reactive_extensions)
|
3
|
+
|
4
|
+
The ReactiveExtensions gem adds a variety of useful methods into core Ruby classes
|
5
|
+
in the spirit of [ActiveSupport](https://github.com/rails/activesupport). This gem can
|
6
|
+
be used in any kind of project and is not dependent on any frameworks, gemsets, etc.
|
7
|
+
Its only runtime dependency is [ReactiveSupport](https://github.com/danascheider/reactive_support).
|
8
|
+
To add ReactiveExtensions to your project, add this to your Gemfile and run `bundle install`:
|
9
|
+
<pre><code>gem 'reactive_extensions', '~> 0.4.0.beta'</code></pre>
|
10
|
+
To install locally:
|
11
|
+
<pre><code>sudo gem install reactive_extensions</code></pre>
|
12
|
+
Or if you're using RVM:
|
13
|
+
<pre><code>gem install reactive_extensions</code></pre>
|
14
|
+
|
15
|
+
You can also point your Gemfile to this repo:
|
16
|
+
<pre><code>gem 'reactive_extensions', '~> 0.4.0.beta', git: 'https://github.com/danascheider/reactive_extensions.git</code></pre>
|
17
|
+
|
18
|
+
After installing, simply include this in your main project file:
|
19
|
+
<pre><code>require 'reactive_support'</code></pre>
|
20
|
+
|
21
|
+
Please note that version 0.4.0.beta is the earliest available version of ReactiveExtensions.
|
22
|
+
|
23
|
+
### Contributing
|
24
|
+
Contributions are welcome and I will respond promptly to all issue reports and pull
|
25
|
+
requests. Particularly helpful are pull requests adding support for additional Rubies.
|
26
|
+
(Currently, only Matz Rubies >= 1.9.3 are supported.) Here are some general guidelines
|
27
|
+
to get you started:
|
28
|
+
* Include passing RSpec tests with your pull request. I aim for 100% test coverage.
|
29
|
+
* Run the whole test suite before you make your PR. Make sure your changes don't
|
30
|
+
break the rest of the gem.
|
31
|
+
* Don't add any new dependencies to ReactiveExtensions, or methods that are specific
|
32
|
+
to a particular framework, gemset, or type of app.
|
33
|
+
* Include documentation. ReactiveExtensions uses [Inch CI](http://inch-ci.org) to
|
34
|
+
evaluate the quality of documentation. Please help make it easy for others to
|
35
|
+
use and contribute to this project.
|
36
|
+
* ReactiveExtension is designed with principles of stability, simplicity, and
|
37
|
+
transparency in mind. Its functionality should be easy to understand and use.
|
data/files.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module ReactiveExtensions
|
2
|
+
def self.files
|
3
|
+
Files::FILES
|
4
|
+
end
|
5
|
+
|
6
|
+
module Files
|
7
|
+
LIB_FILES = Dir.glob('./lib/**/*.rb').sort
|
8
|
+
SPEC_FILES = Dir.glob('./spec/**/*.rb').sort
|
9
|
+
BASE_FILES = %w(files.rb Gemfile LICENSE reactive_extensions.gemspec README.md version.rb)
|
10
|
+
|
11
|
+
FILES = [LIB_FILES, SPEC_FILES, BASE_FILES].flatten
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# This file adds the #raises_error? method to a Proc object. This
|
2
|
+
# method checks whether the proc raises an error when called with
|
3
|
+
# the given parameters.
|
4
|
+
#
|
5
|
+
# Ruby's core Proc class. See documentation for version
|
6
|
+
# 2.1.5[http://ruby-doc.org/core-2.1.5/Proc.html],
|
7
|
+
# 2.0.0[http://ruby-doc.org/core-2.0.0/Proc.html], or
|
8
|
+
# 1.9.3[http://ruby-doc.org/core-1.9.3/Proc.html].
|
9
|
+
|
10
|
+
class Proc
|
11
|
+
|
12
|
+
# The +#raises_error?+ method checks whether an exception is raised
|
13
|
+
# when the calling Proc is called with the given +*args+.
|
14
|
+
#
|
15
|
+
# The +#raises_error?+ method does not actually create lasting changes
|
16
|
+
# to objects or variables; it only checks whether an exception would be
|
17
|
+
# raised if the Proc were called with the given +*args+.
|
18
|
+
#
|
19
|
+
# Basic examples:
|
20
|
+
# proc = Proc.new {|q| 1.quo(q) }
|
21
|
+
# proc.raises_error?(2) # => false
|
22
|
+
# proc.raises_error?(0) # => true
|
23
|
+
#
|
24
|
+
# Examples with destructive proc:
|
25
|
+
# hash = {:foo => :bar}
|
26
|
+
# proc = Proc.new {|hash| hash.reject! {|k,v| k === :foo } }
|
27
|
+
# proc.raises_error?(hash) # => false
|
28
|
+
# hash # => {:foo => :bar}
|
29
|
+
|
30
|
+
def raises_error?(*args)
|
31
|
+
(!self.call(*args.deep_dup)) rescue true
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# This file adds the +#scope+, #where, and +#where_not+ methods to the +Array+ class.
|
2
|
+
# These methods work on an array of hashes, returning hashes for which the given
|
3
|
+
# condition is true.
|
4
|
+
|
5
|
+
# Ruby's core Array class. See documentation for version
|
6
|
+
# 2.1.5[http://ruby-doc.org/core-2.1.5/Array.html],
|
7
|
+
# 2.0.0[http://ruby-doc.org/core-2.0.0/Array.html], or
|
8
|
+
# 1.9.3[http://ruby-doc.org/core-1.9.3/Array.html].
|
9
|
+
|
10
|
+
class Array
|
11
|
+
|
12
|
+
# The +#scope+ method is called on an array of hashes. It returns a sub-array
|
13
|
+
# including only hashes for which the value at a given +key+ is among the given +values+.
|
14
|
+
# The +#scope+ method is non-destructive; the original array will remain intact
|
15
|
+
# after it is called. The +#scope+ method is known to work for string or symbol
|
16
|
+
# keys. It should work for other data type keys as well.
|
17
|
+
#
|
18
|
+
# Example:
|
19
|
+
# array = [
|
20
|
+
# { name: 'Jean-Paul Sartre', nationality: 'French' },
|
21
|
+
# { name: 'Bertrand Russell', nationality: 'English' },
|
22
|
+
# { name: 'Ludwig Wittgenstein', nationality: 'Austrian' },
|
23
|
+
# { name: 'Albert Camus', nationality: 'French' }
|
24
|
+
# ]
|
25
|
+
#
|
26
|
+
# array.scope(:nationality, 'French')
|
27
|
+
# # => [
|
28
|
+
# { name: 'Jean-Paul Sartre', nationality: 'French' },
|
29
|
+
# { name: 'Albert Camus', nationality: 'French' }
|
30
|
+
# ]
|
31
|
+
|
32
|
+
def scope(key, *values)
|
33
|
+
self.select {|hash| hash[key].in?(values) }
|
34
|
+
end
|
35
|
+
|
36
|
+
# The +#where_not+ method is called on an array of hashes. It returns a sub-array
|
37
|
+
# including only hashes for which the value at a given +key+ is not among the
|
38
|
+
# given +values+. It is the inverse of the +#scope+ method. The +#where_not+ method
|
39
|
+
# is non-destructive; the original array will remain intact after it is called. The
|
40
|
+
# +#where_not+ method is known to work for string or symbol keys. It should work for
|
41
|
+
# other data types as well.
|
42
|
+
#
|
43
|
+
# Example:
|
44
|
+
# array = [
|
45
|
+
# { name: 'Jean-Paul Sartre', nationality: 'French' },
|
46
|
+
# { name: 'Bertrand Russell', nationality: 'English' },
|
47
|
+
# { name: 'Ludwig Wittgenstein', nationality: 'Austrian' },
|
48
|
+
# { name: 'Albert Camus', nationality: 'French' }
|
49
|
+
# ]
|
50
|
+
#
|
51
|
+
# array.where_not(:nationality, 'French')
|
52
|
+
# # => [
|
53
|
+
# { name: 'Bertrand Russell', nationality: 'English' },
|
54
|
+
# { name: 'Ludwig Wittgenstein', nationality: 'English' }
|
55
|
+
# ]
|
56
|
+
|
57
|
+
def where_not(key, *values)
|
58
|
+
self.reject {|hash| hash[key].in?(values) }
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# This file adds the +#scope+, #where, and +#where_not+ methods to the +Array+ class.
|
2
|
+
# These methods work on an array of hashes, returning hashes for which the given
|
3
|
+
# condition is true.
|
4
|
+
|
5
|
+
# Ruby's core Array class. See documentation for version
|
6
|
+
# 2.1.5[http://ruby-doc.org/core-2.1.5/Array.html],
|
7
|
+
# 2.0.0[http://ruby-doc.org/core-2.0.0/Array.html], or
|
8
|
+
# 1.9.3[http://ruby-doc.org/core-1.9.3/Array.html].
|
9
|
+
|
10
|
+
class Object
|
11
|
+
|
12
|
+
# The +#try_rescue+ method extends ReactiveSupport's +#try+ method so it
|
13
|
+
# rescues NoMethodErrors and TypeErrors as well as returning +nil+ when
|
14
|
+
# called on a +nil+ value.
|
15
|
+
#
|
16
|
+
# Like the +#try+ method, +#try_rescue+ takes 1 or more arguments. The first
|
17
|
+
# argument is the method to be called on the calling object, passed as a
|
18
|
+
# symbol. The others are zero or more arguments that will be passed through to
|
19
|
+
# that method, and +&block+ is an optional block that will be similarly passed through.
|
20
|
+
#
|
21
|
+
# Example of usage identical to +#try+:
|
22
|
+
# nil.try(:map) {|a| a.to_s } # => nil
|
23
|
+
# nil.try_rescue(:map) {|a| a.to_s } # => nil
|
24
|
+
#
|
25
|
+
# Example of usage calling a method that is not defined on the calling object:
|
26
|
+
# 10.try(:to_h) # => TypeError
|
27
|
+
# 10.try_rescue(:to_h) # => nil
|
28
|
+
#
|
29
|
+
# Example of usage with invalid arguments:
|
30
|
+
# %w(foo, bar, baz).try(:join, [:hello, :world]) # => TypeError
|
31
|
+
# %w(foo, bar, baz).try_rescue(:join, [:hello, :world]) # => nil
|
32
|
+
|
33
|
+
def try_rescue(*args, &block)
|
34
|
+
self.try(*args, &block) rescue nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# The +#try_rescue+ method extends ReactiveSupport's +#try+ method so it rescues
|
39
|
+
# NoMethodErrors and TypeErrors as well as returning +nil+ when called on a +nil+
|
40
|
+
# value.
|
41
|
+
#
|
42
|
+
# Like the +#try+ method, +#try_rescue+ takes 1 or more arguments. The first argument
|
43
|
+
# is the method to be called on the calling object, passed as a symbol. The others
|
44
|
+
# are zero or more arguments that will be passed through to that method, and an
|
45
|
+
# optional block to be likewise passed through.
|
46
|
+
#
|
47
|
+
# When called on NilClass, +#try_rescue+ always returns nil.
|
48
|
+
#
|
49
|
+
# Example:
|
50
|
+
# foo = nil
|
51
|
+
# foo.try_rescue(:has_key?, :bar) # => nil
|
52
|
+
|
53
|
+
class NilClass
|
54
|
+
def try_rescue(*args, &block)
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'reactive_support/core_ext/object/duplicable'
|
2
|
+
require 'reactive_support/core_ext/object/deep_dup'
|
3
|
+
require 'reactive_support/core_ext/object/inclusion'
|
4
|
+
require 'reactive_support/core_ext/object/try'
|
5
|
+
|
6
|
+
Dir['./lib/reactive_extensions/**/*.rb'].each {|f| require f }
|
7
|
+
|
8
|
+
# The ReactiveExtensions module adds useful methods to core Ruby classes. You
|
9
|
+
# can use these methods by adding +require 'reactive_extensions'+ to your project.
|
10
|
+
# Then, ReactiveExtensions methods can be called on any Ruby object just like the
|
11
|
+
# object's own methods. Easy peasy!
|
12
|
+
#
|
13
|
+
# In this example, ReactiveExtension's #try_rescue method is called on an array:
|
14
|
+
# require 'reactive_extensions'
|
15
|
+
# arr = %w(foo, bar, baz)
|
16
|
+
# bad = Math.pi
|
17
|
+
# arr.try_rescue(:join, '.') # => 'foo.bar.baz'
|
18
|
+
# nil.try_rescue(:join, '.') # => nil
|
19
|
+
|
20
|
+
module ReactiveExtensions
|
21
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path('../version.rb', __FILE__)
|
2
|
+
require File.expand_path('../files.rb', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.specification_version = 1 if s.respond_to? :specification_version=
|
6
|
+
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version
|
7
|
+
s.required_ruby_version = '1.9.3'
|
8
|
+
|
9
|
+
s.name = 'reactive_extensions'
|
10
|
+
s.version = ReactiveExtensions.gem_version
|
11
|
+
s.date = '2014-11-29'
|
12
|
+
|
13
|
+
s.description = 'Handy extensions to core Ruby classes'
|
14
|
+
s.summary = 'ReactiveExtensions, a spinoff of ReactiveSupport, adds a variety of useful methods to core Ruby classes.'
|
15
|
+
|
16
|
+
s.authors = ['Dana Scheider']
|
17
|
+
s.email = 'dana.scheider@gmail.com'
|
18
|
+
|
19
|
+
s.files = ReactiveExtensions.files
|
20
|
+
s.require_paths = ['lib']
|
21
|
+
s.test_files = s.files.select {|path| path =~ /^spec\/.*\.rb/ }
|
22
|
+
s.licenses = 'MIT'
|
23
|
+
s.extra_rdoc_files = %w(README.md LICENSE)
|
24
|
+
|
25
|
+
s.add_runtime_dependency 'reactive_support', '>= 0.5.0.beta'
|
26
|
+
|
27
|
+
s.add_development_dependency 'rspec', '~> 3.1'
|
28
|
+
s.add_development_dependency 'bundler', '~> 1.7'
|
29
|
+
s.add_development_dependency 'coveralls', '~> 0.7', '>= 0.7.2'
|
30
|
+
s.add_development_dependency 'simplecov', '~> 0.9', '>= 0.9.1'
|
31
|
+
s.add_development_dependency 'rake', '~> 10.4'
|
32
|
+
|
33
|
+
s.has_rdoc = true
|
34
|
+
s.homepage = 'http://github.com/danascheider/reactive_extensions'
|
35
|
+
s.rdoc_options = %w(--line-numbers --inline-source --title ReactiveExtensions)
|
36
|
+
s.rubygems_version = '1.1.1'
|
37
|
+
end
|
data/spec/array_spec.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'reactive_support/core_ext/hash/keys'
|
3
|
+
|
4
|
+
describe Array do
|
5
|
+
describe 'array scoping' do
|
6
|
+
let(:sartre) { { 'name' => 'Jean-Paul Sartre', 'nationality' => 'French' } }
|
7
|
+
let(:russell) { { 'name' => 'Bertrand Russell', 'nationality' => 'English' } }
|
8
|
+
let(:wittgenstein) { { 'name' => 'Ludwig Wittgenstein', 'nationality' => 'Austrian' } }
|
9
|
+
let(:camus) { { 'name' => 'Albert Camus', 'nationality' => 'French' } }
|
10
|
+
let(:array) { [sartre, russell, wittgenstein, camus] }
|
11
|
+
|
12
|
+
describe 'array #scope method' do
|
13
|
+
context 'symbol keys' do
|
14
|
+
context 'single value' do
|
15
|
+
it 'returns scoped hashes' do
|
16
|
+
array.each {|hash| hash.symbolize_keys! }
|
17
|
+
expect(array.scope(:nationality, 'French')).to eql([sartre, camus])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'multiple values' do
|
22
|
+
it 'returns scoped hashes' do
|
23
|
+
array.each {|hash| hash.symbolize_keys! }
|
24
|
+
expect(array.scope(:nationality, 'French', 'English')).to eql([sartre, russell, camus])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'string keys' do
|
30
|
+
context 'single value' do
|
31
|
+
it 'returns scoped hashes' do
|
32
|
+
expect(array.scope('nationality', 'French')).to eql([sartre, camus])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'multiple values' do
|
37
|
+
it 'returns scoped hashes' do
|
38
|
+
expect(array.scope('nationality', 'French', 'English')).to eql([sartre, russell, camus])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'array #where_not method' do
|
45
|
+
context 'symbol keys' do
|
46
|
+
context 'single value' do
|
47
|
+
it 'returns scoped hashes' do
|
48
|
+
array.each {|hash| hash.symbolize_keys! }
|
49
|
+
expect(array.where_not(:nationality, 'French')).to eql([russell, wittgenstein])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'multiple values' do
|
54
|
+
it 'returns scoped hashes' do
|
55
|
+
array.each {|hash| hash.symbolize_keys! }
|
56
|
+
expect(array.where_not(:nationality, 'French', 'English')).to eql([wittgenstein])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'string keys' do
|
62
|
+
context 'single value' do
|
63
|
+
it 'returns scoped hashes' do
|
64
|
+
expect(array.where_not('nationality', 'French')).to eql([russell, wittgenstein])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'multiple values' do
|
69
|
+
it 'returns scoped hashes' do
|
70
|
+
expect(array.where_not('nationality', 'French', 'English')).to eql([wittgenstein])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/spec/object_spec.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Object do
|
4
|
+
describe '#try_rescue method' do
|
5
|
+
context 'called on nil' do
|
6
|
+
it 'returns nil' do
|
7
|
+
expect(nil.try_rescue(:collect) {|i| i + 2 }).to eql nil
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when the method can be executed successfully' do
|
12
|
+
it 'calls the method' do
|
13
|
+
expect('foo'.try_rescue(:upcase)).to eql 'FOO'
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'called on the Object base class' do
|
17
|
+
it 'calls the method' do
|
18
|
+
expect((Object.new).try_rescue(:class)).to eql Object
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when a NoMethodError is raised' do
|
24
|
+
it 'returns nil' do
|
25
|
+
expect(('foo').try_rescue(:bar)).to eql nil
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when called on the Object base class' do
|
29
|
+
it 'returns nil' do
|
30
|
+
expect((Object.new).try_rescue(:foo)).to eql nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/proc_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Proc do
|
4
|
+
describe '#raises_error?' do
|
5
|
+
let(:proc) { Proc.new {|quotient| 1.quo(quotient) } }
|
6
|
+
|
7
|
+
context 'when an error is raised' do
|
8
|
+
it 'returns true' do
|
9
|
+
expect(proc.raises_error?(0)).to be true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'handles the exception' do
|
13
|
+
expect{ proc.raises_error?(0) }.not_to raise_error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when no error is raised' do
|
18
|
+
it 'returns false' do
|
19
|
+
expect(proc.raises_error?(2)).to be false
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'doesn\'t change objects' do
|
23
|
+
h, p = {:foo => :bar}, Proc.new {|hash| hash.reject! {|k,v| k === :foo } }
|
24
|
+
expect{ p.raises_error?(h) }.not_to change(h, :length)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
Coveralls::SimpleCov::Formatter
|
9
|
+
]
|
10
|
+
|
11
|
+
SimpleCov.start if ENV["COVERAGE"]
|
12
|
+
Coveralls.wear!
|
13
|
+
|
14
|
+
require File.expand_path('../../lib/reactive_extensions.rb', __FILE__)
|
15
|
+
|
16
|
+
RSpec.configure do |c|
|
17
|
+
c.order = 'random'
|
18
|
+
end
|
data/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reactive_extensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0.beta
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dana Scheider
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: reactive_support
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.0.beta
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.0.beta
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.7'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 0.7.2
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0.7'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.7.2
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: simplecov
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0.9'
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 0.9.1
|
85
|
+
type: :development
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0.9'
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 0.9.1
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rake
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '10.4'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '10.4'
|
109
|
+
description: Handy extensions to core Ruby classes
|
110
|
+
email: dana.scheider@gmail.com
|
111
|
+
executables: []
|
112
|
+
extensions: []
|
113
|
+
extra_rdoc_files:
|
114
|
+
- README.md
|
115
|
+
- LICENSE
|
116
|
+
files:
|
117
|
+
- "./lib/reactive_extensions.rb"
|
118
|
+
- "./lib/reactive_extensions/errors.rb"
|
119
|
+
- "./lib/reactive_extensions/scope.rb"
|
120
|
+
- "./lib/reactive_extensions/try_rescue.rb"
|
121
|
+
- "./spec/array_spec.rb"
|
122
|
+
- "./spec/object_spec.rb"
|
123
|
+
- "./spec/proc_spec.rb"
|
124
|
+
- "./spec/spec_helper.rb"
|
125
|
+
- Gemfile
|
126
|
+
- LICENSE
|
127
|
+
- README.md
|
128
|
+
- files.rb
|
129
|
+
- reactive_extensions.gemspec
|
130
|
+
- version.rb
|
131
|
+
homepage: http://github.com/danascheider/reactive_extensions
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options:
|
137
|
+
- "--line-numbers"
|
138
|
+
- "--inline-source"
|
139
|
+
- "--title"
|
140
|
+
- ReactiveExtensions
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - '='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: 1.9.3
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.3.1
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 2.2.2
|
156
|
+
signing_key:
|
157
|
+
specification_version: 1
|
158
|
+
summary: ReactiveExtensions, a spinoff of ReactiveSupport, adds a variety of useful
|
159
|
+
methods to core Ruby classes.
|
160
|
+
test_files: []
|