nil_conditional 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cf1d6643060be57fa65e068058c18be67b556f43
4
+ data.tar.gz: ea61686c2b12673eea19af37c53d893c2534fc4e
5
+ SHA512:
6
+ metadata.gz: 93a0f182e484b1ddc80ac388a64c2dbc62a01e01673655bacb7f09d1ee55d16bbc4daa864862d27c23794d34fd523a2d2c6a366b17db29a7fe3bfcf07b937e50
7
+ data.tar.gz: ebd9ee3c616386816517fccc54ab7c05d49461a40378a6ca1d33c2e6e94fd2f72de95a98d85d816078bb6a3eb5f595b4abea1252e7819ba82f813d107a97357e
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nil_conditional.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Grzegorz Bizon <grzegorz.bizon@ntsn.pl>
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.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # nil-conditional
2
+
3
+ Nil Conditional Operator in Ruby.
4
+
5
+ ## Summary
6
+
7
+ This gem introduces Nil Conditional Operator (`_?`) in Ruby, similar to Null Conditional Operator in C# 6.0.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'nil_conditional'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install nil_conditional
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ empty_object = Object.new
29
+ empty_object.non_existent_method_?
30
+ => nil
31
+
32
+ empty_object_?
33
+ => #<Object:0x00000002d89170>
34
+
35
+ non_existent_object_?
36
+ => nil
37
+
38
+ "test_string".sub_?("_string", '_case')
39
+ => "test_case"
40
+
41
+ :test_string.sub_?("string", "case")
42
+ => nil
43
+
44
+ Object.foo_?.bar_?.car_?.cow_?
45
+ => nil
46
+ ```
47
+
48
+ ## License
49
+
50
+ This is free software, licensed under MIT License. See LICENSE.txt file.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+ task :default => :spec
@@ -0,0 +1,17 @@
1
+ require "nil_conditional/version"
2
+
3
+ module NilConditional
4
+
5
+ class ::Object
6
+ def method_missing(name, *params)
7
+ if name =~ /^.+_\?$/
8
+ original_method = name.to_s.sub(/_\?$/, '').to_sym
9
+ return send(original_method, *params) if respond_to?(original_method)
10
+ nil
11
+ else
12
+ super
13
+ end
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,3 @@
1
+ module NilConditional
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nil_conditional/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nil_conditional"
8
+ spec.version = NilConditional::VERSION
9
+ spec.authors = ["Grzegorz Bizon"]
10
+ spec.email = ["grzegorz.bizon@ntsn.pl"]
11
+ spec.summary = %q{Nil Conditional Operator in Ruby}
12
+ spec.homepage = "http://github.com/grzesiek/nil-conditional"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.2.0"
23
+ end
@@ -0,0 +1,25 @@
1
+ describe Object do
2
+ context 'test method' do
3
+ it 'should not raise error when receiving test_method_?' do
4
+ expect { Object.new.test_method }.to raise_error(NoMethodError)
5
+ end
6
+
7
+ it 'should not raise error when receiving test_method_?' do
8
+ expect { Object.new.test_method_? }.to_not raise_error
9
+ end
10
+
11
+ it 'should return nil when received non existent method with nil conditional' do
12
+ expect(Object.new.test_method_?).to be nil
13
+ end
14
+
15
+ it 'should support chained methods with nil conditional' do
16
+ expect { Object.new.test_method_?.foo_?.bar_?.car_?.cow_? }.to_not raise_error
17
+ expect(Object.new.test_method_?.foo_?.bar_?.car_?.cow_?).to be nil
18
+ end
19
+
20
+ it 'should support methods with arguments' do
21
+ expect { Object.test_method_with_args_?(1, 2, 3) }.to_not raise_error
22
+ expect(Object.test_method_with_args_?(1, 2, 3)).to be nil
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ require 'nil_conditional'
2
+
3
+ RSpec.configure do |config|
4
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nil_conditional
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Grzegorz Bizon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ description:
56
+ email:
57
+ - grzegorz.bizon@ntsn.pl
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/nil_conditional.rb
69
+ - lib/nil_conditional/version.rb
70
+ - nil_conditional.gemspec
71
+ - spec/object_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: http://github.com/grzesiek/nil-conditional
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.4.3
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Nil Conditional Operator in Ruby
97
+ test_files:
98
+ - spec/object_spec.rb
99
+ - spec/spec_helper.rb
100
+ has_rdoc: