egonil 1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c662ea596b9af71e1a7e853628bc784e429c8024
4
+ data.tar.gz: 02701b0364a606deccc92fc0f642a5f98a881d7a
5
+ SHA512:
6
+ metadata.gz: d42bfe4f62cddb79b581f0ca2381df02ad3e79b6f908d489bcb0f39d263e0491b5bf4114338449be8e6707c9e5fa38b7210865e9e8b26fcee275a7453a0ae1d5
7
+ data.tar.gz: 8ed0f83699246913130fba6c0a775d11f79c1173d97c65fc5b08d159daf5ae8192618576737ace33e7db39653f472841e28d5d51459c7df5a9f816d4c82ebfa4
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ /pkg
@@ -0,0 +1,20 @@
1
+ sudo: false
2
+ language: ruby
3
+
4
+ script: bundle exec ruby spec/egonil_spec.rb
5
+
6
+ rvm:
7
+ - 2.3.0
8
+ - 2.2
9
+ - 2.1
10
+ - 2.0
11
+ - ruby-head
12
+ - rbx-2
13
+ - jruby-head
14
+ - jruby-9000
15
+
16
+ cache:
17
+ - bundler
18
+
19
+ # matrix:
20
+ # fast_finish: true
@@ -0,0 +1,6 @@
1
+ ## CHANGELOG
2
+
3
+ ### 1.0.0
4
+
5
+ * Moved from zucker gem into its own gem
6
+ * Make egonil a Kernel method
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'minitest'
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010-2016 Jan Lelis, mail@janlelis.de
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Egocentric Nil [![[version]](https://badge.fury.io/rb/egonil.svg)](http://badge.fury.io/rb/egonil) [![[travis]](https://travis-ci.org/janlelis/egonil.png)](https://travis-ci.org/janlelis/egonil)
2
+
3
+ Creates a block, where `nil` does not raise `NoMethodError`s
4
+
5
+ ```ruby
6
+ egonil do
7
+ nil.some_methods.that[:do].not.exist
8
+ end
9
+ ```
10
+
11
+
12
+ ## Further Information
13
+
14
+ - [The Hopelessly Egocentric Blog Post](https://github.com/raganwald-deprecated/homoiconic/blob/master/2009-02-02/hopeless_egocentricity.md)
15
+ - [The 25 Bytes of Ruby Joy!](http://ruby.janlelis.de/26-the-28-bytes-of-ruby-joy)
16
+ - [Safe navigation operator](https://bugs.ruby-lang.org/issues/11537)
17
+ - Null objects with [null_question](https://github.com/janlelis/null_question) and [exists](https://github.com/janlelis/exists) or [null_plus](https://github.com/janlelis/null_plus)
18
+
19
+
20
+ ## Setup
21
+
22
+ Add to your `Gemfile`:
23
+
24
+ ```ruby
25
+ gem 'egonil'
26
+ ```
27
+
28
+
29
+ ## MIT License
30
+
31
+ Copyright (C) 2010-2016 Jan Lelis <http://janlelis.com>. Released under the MIT license.
@@ -0,0 +1,30 @@
1
+ # # #
2
+ # Get gemspec info
3
+
4
+ gemspec_file = Dir['*.gemspec'].first
5
+ gemspec = eval File.read(gemspec_file), binding, gemspec_file
6
+ info = "#{gemspec.name} | #{gemspec.version} | " \
7
+ "#{gemspec.runtime_dependencies.size} dependencies | " \
8
+ "#{gemspec.files.size} files"
9
+
10
+
11
+ # # #
12
+ # Gem build and install task
13
+
14
+ desc info
15
+ task :gem do
16
+ puts info + "\n\n"
17
+ print " "; sh "gem build #{gemspec_file}"
18
+ FileUtils.mkdir_p 'pkg'
19
+ FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
20
+ puts; sh %{gem install --no-document pkg/#{gemspec.name}-#{gemspec.version}.gem}
21
+ end
22
+
23
+
24
+ # # #
25
+ # Start an IRB session with the gem loaded
26
+
27
+ desc "#{gemspec.name} | IRB"
28
+ task :irb do
29
+ sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}"
30
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + "/lib/egonil/version"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "egonil"
7
+ gem.version = Egonil::VERSION
8
+ gem.summary = "Egocentric nil"
9
+ gem.description = "Creates a block, where nil does not raise NoMethodErrors."
10
+ gem.authors = ["Jan Lelis"]
11
+ gem.email = ["mail@janlelis.de"]
12
+ gem.homepage = "https://github.com/janlelis/egonil"
13
+ gem.license = "MIT"
14
+
15
+ gem.files = Dir["{**/}{.*,*}"].select{ |path| File.file?(path) && path !~ /^pkg/ }
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.required_ruby_version = "~> 2.0"
21
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "egonil/version"
2
+
3
+ module Kernel
4
+ private
5
+
6
+ def egonil
7
+ mm = NilClass.instance_method(:method_missing)
8
+ NilClass.send :define_method, :method_missing, ->(*){}
9
+ yield
10
+ ensure
11
+ NilClass.send :define_method, :method_missing, mm
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module Egonil
2
+ VERSION = "1.0.0".freeze
3
+ end
4
+
@@ -0,0 +1,32 @@
1
+ require_relative "../lib/egonil"
2
+ require "minitest/autorun"
3
+
4
+ describe 'Kernel#egonil' do
5
+ it 'should not raise nil exceptions in the block' do
6
+ egonil do
7
+ nil.some_methods.that[:do].not.exist
8
+ end
9
+ end
10
+
11
+ it 'should restore default behaviour after the block' do
12
+ egonil do
13
+ nil.some_methods.that[:do].not.exist
14
+ end
15
+
16
+ assert_raises NoMethodError do
17
+ nil.a_method
18
+ end
19
+ end
20
+
21
+ it 'raise NoMethodError for non-nil objects' do
22
+ assert_raises NoMethodError do
23
+ egonil{ 5.a_method }
24
+ end
25
+ end
26
+
27
+ it 'should raise other Exceptions' do
28
+ assert_raises ZeroDivisionError do
29
+ egonil{ 5 / 0 }
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: egonil
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jan Lelis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Creates a block, where nil does not raise NoMethodErrors.
14
+ email:
15
+ - mail@janlelis.de
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".travis.yml"
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - MIT-LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - egonil.gemspec
28
+ - lib/egonil.rb
29
+ - lib/egonil/version.rb
30
+ - spec/egonil_spec.rb
31
+ homepage: https://github.com/janlelis/egonil
32
+ licenses:
33
+ - MIT
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '2.0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 2.5.1
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Egocentric nil
55
+ test_files:
56
+ - spec/egonil_spec.rb