non_nullable 0.1.0

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: 777dda5e1a78c5623245d391b95a1873c1559fa7
4
+ data.tar.gz: 54e001297f045db39b18c1e9690962c47b532214
5
+ SHA512:
6
+ metadata.gz: a12d05c562ccc1cedbe0b3bd5f25fe9d58656741a9fcbfdd88b3dc84aa91c5b03a760be4309b4b503439d79092f41e8506566473f858cb546f8cba06112511b7
7
+ data.tar.gz: 5ee8be50b1d72267ad53c288ad2d20ea11d6c8b0ddec1dc33282d81bda8cb7b206efeee857300555b90d1f29d1737bdc2c9519645e5392f716df3fe4531f3c9d
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in non_nullable.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2014 Lukas Alexandre
2
+
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # NonNullable
2
+
3
+ Avoids nil returns on specified Ruby methods.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ class Post
9
+ extend ::NotNil
10
+
11
+ def content
12
+ nil
13
+ end
14
+
15
+ avoid_nil_on :content
16
+ end
17
+
18
+ post.content # ""
19
+
20
+ # or on all instance methods
21
+
22
+ class Blog
23
+ extend ::NotNil
24
+
25
+ # ...tons of methods...
26
+
27
+ avoid_nil_on *instance_methods
28
+ end
29
+ ```
30
+
31
+ ## Installation
32
+
33
+ Add this line to your application's Gemfile:
34
+
35
+ ```ruby
36
+ gem "non_nullable"
37
+ ```
38
+
39
+ And then execute:
40
+
41
+ ```bash
42
+ $ bundle
43
+ ```
44
+
45
+ Or install it yourself as:
46
+
47
+ ```bash
48
+ $ gem install non_nullable
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it ( https://github.com/[my-github-username]/non_nullable/fork )
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ module NonNullable
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,17 @@
1
+ require "non_nullable/version"
2
+
3
+ module NonNullable
4
+ private
5
+ def avoid_nil_on(*names)
6
+ after(*names) { |result| result.nil? ? "" : result }
7
+ end
8
+
9
+ def after(*names)
10
+ names.each do |name|
11
+ m = instance_method(name)
12
+ define_method(name) do |*args, &block|
13
+ yield m.bind(self).(*args, &block)
14
+ end
15
+ end
16
+ end
17
+ 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 'non_nullable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "non_nullable"
8
+ spec.version = NonNullable::VERSION
9
+ spec.authors = ["Lukas Alexandre\n"]
10
+ spec.email = ["lukas@codelogic.me"]
11
+ spec.summary = %q{Avoids nil returns on specified Ruby methods}
12
+ spec.homepage = "https://github.com/lukelex/non_nullable"
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.6"
21
+ spec.add_development_dependency "rake", "~> 10.3"
22
+ spec.add_development_dependency "rspec", "~> 3.1"
23
+ end
@@ -0,0 +1,29 @@
1
+ require "non_nullable"
2
+
3
+ describe NonNullable do
4
+ context "with a nil value" do
5
+ let(:klass) do
6
+ Class.new do
7
+ extend NonNullable
8
+ def nil_value ; end
9
+ avoid_nil_on :nil_value
10
+ end
11
+ end
12
+
13
+ it { expect(klass.new.nil_value).to eq "" }
14
+ end
15
+
16
+ context "with a not nil value" do
17
+ let(:klass) do
18
+ Class.new do
19
+ extend NonNullable
20
+ def not_nil_value
21
+ "not nil"
22
+ end
23
+ avoid_nil_on :not_nil_value
24
+ end
25
+ end
26
+
27
+ it { expect(klass.new.not_nil_value).to eq "not nil" }
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: non_nullable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - |
8
+ Lukas Alexandre
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.6'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.6'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.3'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.3'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.1'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.1'
56
+ description:
57
+ email:
58
+ - lukas@codelogic.me
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/non_nullable.rb
69
+ - lib/non_nullable/version.rb
70
+ - non_nullable.gemspec
71
+ - spec/non_nullable_spec.rb
72
+ homepage: https://github.com/lukelex/non_nullable
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Avoids nil returns on specified Ruby methods
96
+ test_files:
97
+ - spec/non_nullable_spec.rb