reactive_support 0.3.0.beta4 → 0.4.0.beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81f05e52790af3ef46c2291c2aedbfb10cd6dc51
4
- data.tar.gz: 41cfee452fb77ea758ac726eefaa060c64386c7a
3
+ metadata.gz: 59bff29f1a8eaf3b256c0bbeb988bcc3be5af4d3
4
+ data.tar.gz: 1bb1f2bffe4a3283a156b85fb3b35b15ecfa212d
5
5
  SHA512:
6
- metadata.gz: 4f19048864c1426fecf482564bea6942e2be0c7a4d4cba59e7b151678ef965c745ce954e6d87251d78006d64a6e346ff3e017b181c0f3ed93efe06809e6cb26a
7
- data.tar.gz: 413727a29f202747077068afb3c557ff59ebbdf22031ba25d6c45c4d87b8b9e1a604ce5922578a1d6aac1a35199531bc363429f62296c7a39c6b4a03391ffcfe
6
+ metadata.gz: 59870827ff9e3318bd6e007e942cd56b66554e46f87bb8312b8808bcfe3cca0a3da4826efac419aef61252605689410a2bc5cdc456c037f10422943c48f2feea
7
+ data.tar.gz: bc177dbad0251df83cdb602e90425189c799b612a9a1f612027f01ca0a73e00fdf146d08258314c0eab23848fe7e4b2bbb6d36ca4fd1f33a3ba2a19afb23b3f7
data/README.md CHANGED
@@ -5,23 +5,31 @@ The ReactiveSupport gem provides a re-implementation of certain [ActiveSupport](
5
5
  methods, allowing them to be used outside of the Rails ecosystem. This gem can
6
6
  be used in any kind of project and is not dependent on any frameworks, gemsets, etc.
7
7
  To add ReactiveSupport to your project, add this to your Gemfile and run `bundle install`:
8
- <pre><code>gem 'reactive_support', '~> 0.1.3'</code></pre>
8
+ <pre><code>gem 'reactive_support', '~> 0.4.0'</code></pre>
9
9
  To install locally:
10
10
  <pre><code>sudo gem install reactive_support</code></pre>
11
11
  Or if you're using RVM:
12
12
  <pre><code>gem install reactive_support</code></pre>
13
- Then, in your main project file, include:
14
- <pre><code>require 'reactive_support'</code></pre>
15
13
 
16
14
  You can also point your Gemfile to this repo:
17
- <pre><code>gem 'reactive_support', '~> 0.1.3', git: 'https://github.com/danascheider/reactive_support.git</code></pre>
15
+ <pre><code>gem 'reactive_support', '~> 0.4.0.beta', git: 'https://github.com/danascheider/reactive_support.git</code></pre>
18
16
 
19
- Please note that version 0.1.2 is the earliest available version of ReactiveSupport, and is currently the only release labeled production ready.
17
+ Like ActiveSupport, ReactiveSupport is designed to load only the code you are actually
18
+ using in your app. For that reason, you will need to specify in your project files
19
+ exactly what you're using. For example, in Canto, I have the following requires:
20
+ <pre><code>require 'reactive_support'
21
+ require 'reactive_support/core_ext/object/blank'
22
+ require 'reactive_support/core_ext/object/inclusion'
23
+ require 'reactive_support/core_ext/object/try'
24
+ require 'reactive_support/extensions/reactive_extensions'</code></pre>
25
+ The ReactiveExtensions module should be required as a whole. I do have plans to add the ability to require the entire gem, or broader parts of it, in the future. This would also be a welcome contribution to the project if you're interested.
26
+
27
+ Please note that version 0.1.2 is the earliest available version of ReactiveSupport.
20
28
 
21
29
  ### Usage
22
- In its current version, ReactiveSupport adds methods to Ruby's `Object` class, so
23
- once required, its methods can be used on any object within your project, including
24
- core Ruby classes.
30
+ In its current version, ReactiveSupport adds methods to several core Ruby classes
31
+ (including `Object`), so once required, its methods can be used on any object within
32
+ your project.
25
33
 
26
34
  Currently, ReactiveSupport's methods are a strict subset of ActiveSupport's. (This may
27
35
  change in future versions, or most saliently, if ActiveSupport's API changes.)
@@ -29,7 +37,7 @@ That means that, while not all ActiveSupport methods are available, those that a
29
37
  as of September 2014, be found in ActiveSupport's API documentation with no functional
30
38
  differences. (This is true of ReactiveSupport 0.1.x and ActiveSupport 4.1.6.)
31
39
 
32
- ReactiveSupport includes an extension module, ReactiveExtensions, that additional
40
+ ReactiveSupport includes an extension module, ReactiveExtensions, that houses additional
33
41
  methods in the spirit of, but not included in, ActiveSupport. This module needs to
34
42
  be included separately; the default configuration is that only ActiveSupport methods
35
43
  are added to your project. You can include ReactiveExtensions with a simple `require`:
@@ -0,0 +1,48 @@
1
+ class Object
2
+
3
+ # The +#try_rescue+ method extends ReactiveSupport's +#try+ method so it
4
+ # rescues NoMethodErrors and TypeErrors as well as returning +nil+ when
5
+ # called on a +nil+ value.
6
+ #
7
+ # Like the +#try+ method, +#try_rescue+ takes 1 or more arguments. The first
8
+ # argument is the method to be called on the calling object, passed as a
9
+ # symbol. The others are zero or more arguments that will be passed through to
10
+ # that method, and +&block+ is an optional block that will be similarly passed through.
11
+ #
12
+ # Example of usage identical to +#try+:
13
+ # nil.try(:map) {|a| a.to_s } # => nil
14
+ # nil.try_rescue(:map) {|a| a.to_s } # => nil
15
+ #
16
+ # Example of usage calling a method that is not defined on the calling object:
17
+ # 10.try(:to_h) # => TypeError
18
+ # 10.try_rescue(:to_h) # => nil
19
+ #
20
+ # Example of usage with invalid arguments:
21
+ # %w(foo, bar, baz).try(:join, [:hello, :world]) # => TypeError
22
+ # %w(foo, bar, baz).try_rescue(:join, [:hello, :world]) # => nil
23
+
24
+ def try_rescue(*args, &block)
25
+ self.try(*args, &block) rescue nil
26
+ end
27
+ end
28
+
29
+ # The +#try_rescue+ method extends ReactiveSupport's +#try+ method so it rescues
30
+ # NoMethodErrors and TypeErrors as well as returning +nil+ when called on a +nil+
31
+ # value.
32
+ #
33
+ # Like the +#try+ method, +#try_rescue+ takes 1 or more arguments. The first argument
34
+ # is the method to be called on the calling object, passed as a symbol. The others
35
+ # are zero or more arguments that will be passed through to that method, and an
36
+ # optional block to be likewise passed through.
37
+ #
38
+ # When called on NilClass, +#try_rescue+ always returns nil.
39
+ #
40
+ # Example:
41
+ # foo = nil
42
+ # foo.try_rescue(:has_key?, :bar) # => nil
43
+
44
+ class NilClass
45
+ def try_rescue(*args, &block)
46
+ nil
47
+ end
48
+ end
@@ -1,3 +1,5 @@
1
+ Dir['./lib/reactive_support/extensions/*.rb'].each {|f| require f }
2
+
1
3
  # The ReactiveExtensions module consists of methods I wish ActiveSupport provided.
2
4
  # These methods do not adhere to the ActiveSupport API. If you wish to include
3
5
  # them in your project, you will need to put this in your main project file:
@@ -7,34 +9,4 @@
7
9
  # requires for ReactiveSupport as it will raise a SystemStackError.
8
10
 
9
11
  module ReactiveExtensions
10
- Dir['./lib/reactive_support/extensions/*'].each {|f| require f }
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
- class Object
39
- include ReactiveExtensions
40
12
  end
data/version.rb CHANGED
@@ -5,9 +5,9 @@ module ReactiveSupport
5
5
 
6
6
  module Version
7
7
  MAJOR = '0'
8
- MINOR = '3'
8
+ MINOR = '4'
9
9
  PATCH = '0'
10
- PRE = 'beta4'
10
+ PRE = 'beta2'
11
11
 
12
12
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.').chomp('.')
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactive_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.beta4
4
+ version: 0.4.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dana Scheider
@@ -86,6 +86,7 @@ files:
86
86
  - "./lib/reactive_support/core_ext/object/try.rb"
87
87
  - "./lib/reactive_support/extensions/array_extensions.rb"
88
88
  - "./lib/reactive_support/extensions/hash_extensions.rb"
89
+ - "./lib/reactive_support/extensions/object_extensions.rb"
89
90
  - "./lib/reactive_support/extensions/proc_extensions.rb"
90
91
  - "./lib/reactive_support/extensions/reactive_extensions.rb"
91
92
  - "./spec/array_spec.rb"