nil_or 1.0.0 → 2.0.0

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.
Files changed (7) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +45 -21
  4. data/UNLICENSE +24 -0
  5. data/lib/nil_or.rb +9 -13
  6. data/nil_or.gemspec +3 -2
  7. metadata +10 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1a0af38e63fb8dc2790570ee5297eb7ad07a161
4
- data.tar.gz: 2b6f8cfe4040142bf4273c254915781b1747266e
3
+ metadata.gz: eaa7d0cb1fee3219f241ee02cd8b0638e8eab3f7
4
+ data.tar.gz: 051b4177d3d83c908e1b25fb83c28720eacd8665
5
5
  SHA512:
6
- metadata.gz: ad1a4dcfec50cfe3d85ea58f53b14f3bc6f32165d1805df0a8ddee2a704b623d7b820908a1a6c9f079aec80e54d4ab64acf9f3358af42b411849ef1093159676
7
- data.tar.gz: 48a0bba734760dd9df498da05b14c296835867d4e26d0defeacad8d3836e48d87ce9e0f477942e279f0c5ce4e943c6781f9724ddbea9ee049d2be8c06faf7fda
6
+ metadata.gz: bc9d01bd57a503ad0b2b11d8bc45645534b0c7dcbb06cc9e5336565b1a06b9ab45bdc28351e4a458f69c8de4ed6e091c5c6b9628cd2b486f03b6a24c7ddd1755
7
+ data.tar.gz: c2b2321e0c8d291edca1882838337ae049cb28cbd9a9544002969020c457c054f20863fe3bffa4dafede80f5b013ffa69615a340375d40fa352d107457c008e4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nil_or (0.0.1)
4
+ nil_or (2.0.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -1,41 +1,65 @@
1
- # nil_or
1
+ # nil_or [![Gem Version](https://badge.fury.io/rb/nil_or.svg)](http://badge.fury.io/rb/nil_or)
2
2
 
3
3
  Delegates methods to the target unless nil.
4
4
 
5
- ## Getting started
5
+ ## Installation
6
6
 
7
- $ gem install nil_or
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'nil_or'
11
+ ```
8
12
 
9
- Or in your Gemfile:
13
+ And then execute:
10
14
 
11
- gem "nil_or"
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install nil_or
12
20
 
13
21
  ## Usage
14
22
 
15
23
  When am I going to need it? Instead of writing:
16
24
 
17
- date_of_birth = params[:date_of_birth] ? params[:date_of_birth].to_date : nil
25
+ ```ruby
26
+ date_of_birth = params[:date_of_birth] ? params[:date_of_birth].to_date : nil
27
+ ```
18
28
 
19
29
  Write:
20
30
 
21
- date_of_birth = params[:date_of_birth].nil_or.to_date
31
+ ```ruby
32
+ date_of_birth = params[:date_of_birth].nil_or.to_date
33
+ ```
22
34
 
23
35
  When x is not nil:
24
36
 
25
- x = 5
26
- x.nil_or.to_s
27
- => "5"
28
- x.nil_or + 2
29
- => 7
30
- x.nil_or.times { |i| puts i }
31
- ...
37
+ ```ruby
38
+ x = 5
39
+ x.nil_or.to_s
40
+ => "5"
41
+ x.nil_or + 2
42
+ => 7
43
+ x.nil_or.times { |i| puts i }
44
+ ...
45
+ ```
32
46
 
33
47
  But when it is nil:
34
48
 
35
- x = nil
36
- x.nil_or.to_s
37
- => nil
38
- x.nil_or + 2
39
- => nil
40
- x.nil_or.shakalaka(1, 2) { does_nothing }
41
- => nil
49
+ ```ruby
50
+ x = nil
51
+ x.nil_or.to_s
52
+ => nil
53
+ x.nil_or + 2
54
+ => nil
55
+ x.nil_or.shakalaka(1, 2) { does_nothing }
56
+ => nil
57
+ ```
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it ( https://github.com/odedniv/nil_or/fork )
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create a new Pull Request
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
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 NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
@@ -1,23 +1,19 @@
1
1
  module NilOr
2
- class NilOrDelegate < BasicObject
3
- attr_accessor :delegation_target
4
-
5
- def initialize(delegation_target)
6
- @delegation_target = delegation_target
7
- end
8
-
9
- def method_missing(method, *attributes, &block)
10
- @delegation_target.nil? ? nil :
11
- @delegation_target.__send__(method, *attributes, &block)
2
+ class DSL < BasicObject
3
+ def method_missing(*)
4
+ nil
12
5
  end
13
6
  end
7
+ DSLObject = DSL.new
14
8
 
15
- def nil_or
16
- NilOrDelegate.new(self)
9
+ module Methods
10
+ def nil_or
11
+ nil? ? DSLObject : self
12
+ end
17
13
  end
18
14
  end
19
15
 
20
16
  class Object
21
- include NilOr
17
+ include NilOr::Methods
22
18
  end
23
19
 
@@ -3,12 +3,13 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "nil_or"
6
- s.version = "1.0.0"
6
+ s.version = "2.0.0"
7
7
  s.authors = ["Oded Niv"]
8
8
  s.email = ["oded.niv@gmail.com"]
9
- s.homepage = "https://github.com/toplex/nil_or"
9
+ s.homepage = "https://github.com/odedniv/nil_or"
10
10
  s.summary = %q{Execute Unless Nil}
11
11
  s.description = %q{Delegates methods to the object or returns nil.}
12
+ s.license = 'UNLICENSE'
12
13
 
13
14
  s.rubyforge_project = "nil_or"
14
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nil_or
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oded Niv
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-29 00:00:00.000000000 Z
11
+ date: 2014-10-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Delegates methods to the object or returns nil.
14
14
  email:
@@ -17,17 +17,19 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - .gitignore
20
+ - ".gitignore"
21
21
  - Gemfile
22
22
  - Gemfile.lock
23
23
  - README.md
24
24
  - Rakefile
25
+ - UNLICENSE
25
26
  - lib/nil_or.rb
26
27
  - nil_or.gemspec
27
28
  - spec/lib/nil_or_spec.rb
28
29
  - spec/spec_helper.rb
29
- homepage: https://github.com/toplex/nil_or
30
- licenses: []
30
+ homepage: https://github.com/odedniv/nil_or
31
+ licenses:
32
+ - UNLICENSE
31
33
  metadata: {}
32
34
  post_install_message:
33
35
  rdoc_options: []
@@ -35,17 +37,17 @@ require_paths:
35
37
  - lib
36
38
  required_ruby_version: !ruby/object:Gem::Requirement
37
39
  requirements:
38
- - - '>='
40
+ - - ">="
39
41
  - !ruby/object:Gem::Version
40
42
  version: '0'
41
43
  required_rubygems_version: !ruby/object:Gem::Requirement
42
44
  requirements:
43
- - - '>='
45
+ - - ">="
44
46
  - !ruby/object:Gem::Version
45
47
  version: '0'
46
48
  requirements: []
47
49
  rubyforge_project: nil_or
48
- rubygems_version: 2.0.3
50
+ rubygems_version: 2.2.0
49
51
  signing_key:
50
52
  specification_version: 4
51
53
  summary: Execute Unless Nil