nil_object 0.0.1

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,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .vagrant
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nil_object.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Mark Kremer
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.
@@ -0,0 +1,30 @@
1
+ # NilObject
2
+ Very simple Null Object pattern implementation. Avdi Grimm has a blog post that gives an excellent introduction to the pattern in Ruby: http://devblog.avdi.org/2011/05/30/null-objects-and-falsiness/
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'nil_object'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install nil_object
17
+
18
+ ## Usage
19
+
20
+ Wherever you want a NilObject simply instantiate one with NilObject.new, conversion methods (such as to_s, to_i, etc.) work like they would on nil, method_missing will return self.
21
+
22
+ You can extend NilObject to create your own variations of NilObjects as you please.
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task :default => :test
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.pattern = 'test/**/*_test\.rb'
8
+ end
@@ -0,0 +1,10 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant::Config.run do |config|
5
+ config.vm.box = "precise32"
6
+ config.vm.box_url = "http://files.vagrantup.com/precise32.box"
7
+ config.vm.network :hostonly, "192.168.33.20"
8
+ config.vm.share_folder "v-root", "/vagrant", ".", :nfs => !(ENV["OS"] =~ /windows/i)
9
+ config.vm.provision :shell, :path => "vagrant-provision"
10
+ end
@@ -0,0 +1,41 @@
1
+ class NilObject
2
+ def method_missing(*args, &block)
3
+ self
4
+ end
5
+
6
+ def blank?
7
+ true
8
+ end
9
+
10
+ def present?
11
+ false
12
+ end
13
+
14
+ def to_s
15
+ ""
16
+ end
17
+
18
+ def to_i
19
+ 0
20
+ end
21
+
22
+ def to_f
23
+ 0.0
24
+ end
25
+
26
+ def to_r
27
+ Rational(0)
28
+ end
29
+
30
+ def rationalize
31
+ to_r
32
+ end
33
+
34
+ def to_c
35
+ Complex(0)
36
+ end
37
+
38
+ def to_a
39
+ []
40
+ end
41
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "nil_object"
7
+ gem.version = "0.0.1"
8
+ gem.authors = ["Mark Kremer"]
9
+ gem.email = ["mark@without-brains.net"]
10
+ gem.summary = %q{Simple Null Object implementation}
11
+ gem.homepage = "https://github.com/mkremer/nil_object"
12
+
13
+ gem.files = `git ls-files`.split($/)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.require_paths = ["lib"]
17
+
18
+ gem.add_development_dependency "rake", "~> 0.9.2"
19
+ gem.add_development_dependency "minitest", "~> 4.1"
20
+ end
@@ -0,0 +1,50 @@
1
+ require "minitest/unit"
2
+ require "minitest/autorun"
3
+ require "nil_object"
4
+
5
+ class NilObjectTest < MiniTest::Unit::TestCase
6
+ def setup
7
+ @nil_object = NilObject.new
8
+ end
9
+
10
+ def test_is_blank
11
+ assert @nil_object.blank?
12
+ end
13
+
14
+ def test_is_not_present
15
+ refute @nil_object.present?
16
+ end
17
+
18
+ def test_missing_methods_return_self
19
+ assert_equal @nil_object, @nil_object.this_does_not_exist
20
+ assert_equal @nil_object, @nil_object.this_does_not_exist.and_neither_does_this.or_this
21
+ end
22
+
23
+ def test_rationalize_returns_0_as_rational
24
+ assert_equal Rational(0), @nil_object.rationalize
25
+ end
26
+
27
+ def test_to_a_returns_empty_array
28
+ assert_equal [], @nil_object.to_a
29
+ end
30
+
31
+ def test_to_c_returns_zero_as_complex
32
+ assert_equal Complex(0), @nil_object.to_c
33
+ end
34
+
35
+ def test_to_f_returns_0_0
36
+ assert_equal 0.0, @nil_object.to_f
37
+ end
38
+
39
+ def test_to_i_returns_0
40
+ assert_equal 0, @nil_object.to_i
41
+ end
42
+
43
+ def test_to_r_returns_0_as_rational
44
+ assert_equal Rational(0), @nil_object.to_r
45
+ end
46
+
47
+ def test_to_s_returns_empty_string
48
+ assert_equal "", @nil_object.to_s
49
+ end
50
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+
3
+ export DEBIAN_FRONTEND=noninteractive
4
+
5
+ apt-get update > /dev/null
6
+ apt-get -y install build-essential git-core ruby1.9.1-full ruby1.9.1-dev libyaml-dev libssl-dev zlib1g-dev libreadline-dev openssl libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev autoconf libc6-dev ncurses-dev automake libtool bison libffi-dev
7
+
8
+ gem install bundler pry
9
+
10
+ su -c 'cd /vagrant && bundle' vagrant
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nil_object
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mark Kremer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &83762700 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.2
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *83762700
25
+ - !ruby/object:Gem::Dependency
26
+ name: minitest
27
+ requirement: &83762280 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '4.1'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *83762280
36
+ description:
37
+ email:
38
+ - mark@without-brains.net
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - LICENSE.txt
46
+ - README.md
47
+ - Rakefile
48
+ - Vagrantfile
49
+ - lib/nil_object.rb
50
+ - nil_object.gemspec
51
+ - test/nil_object_test.rb
52
+ - vagrant-provision
53
+ homepage: https://github.com/mkremer/nil_object
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.11
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Simple Null Object implementation
77
+ test_files:
78
+ - test/nil_object_test.rb