nobody 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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nobody.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'minitest'
8
+ gem 'turn'
9
+ end
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # nobody / personne
2
+
3
+ ## English
4
+
5
+ ### Description
6
+
7
+ Nobody is a gem to add shorthand ability of implementing the Null Object Pattern in a class.
8
+
9
+ ### Installation
10
+
11
+ ```bash
12
+ $ gem install nobody
13
+ ```
14
+
15
+ ### Usage
16
+
17
+ Using nobody is easy, just include the module in your class and then use one if its methods, `returns_nil_for`, `returns_true_for`, or `returns_false_for`. You can specify any other methods normally in the class.
18
+
19
+ ```ruby
20
+ class NullOdysseus
21
+ include Nobody
22
+
23
+ returns_nil_for :name, :email_address
24
+ returns_true_for :is_adventurer?, :alive?
25
+ returns_false_for :dead?, :cyclops?
26
+
27
+ def hometown
28
+ 'Itaca'
29
+ end
30
+ end
31
+ ```
32
+
33
+ ## Français
34
+
35
+ ### Description
36
+
37
+ Personne est un gem pour utiliser facilement la Modèle d'objet Null dans un class.
38
+
39
+ ### Installation
40
+
41
+ ```bash
42
+ $ gem install nobody
43
+ ```
44
+
45
+ ### Utilisation
46
+
47
+ Utiliser personne est facile. On doit seulement inclure le module dans son class et puis utiliser un de ses méthodes, `returns_nil_for`, `returns_true_for`, ou `returns_false_for`. On peut écrire des autre méthodes comme d'habitude.
48
+
49
+ ```ruby
50
+ class NullOdysseus
51
+ include Nobody
52
+
53
+ returns_nil_for :name, :email_address
54
+ returns_true_for :is_adventurer?, :alive?
55
+ returns_false_for :dead?, :cyclops?
56
+
57
+ def hometown
58
+ 'Itaca'
59
+ end
60
+ end
61
+ ```
62
+
63
+ ## Acknowledgements
64
+
65
+ Thanks to Ben Orenstein (@r00k) for his talk at RMR12 on refactoring, which included this pattern.
66
+
67
+ ## License
68
+
69
+ Copyright (c) 2012 GordonDiggs
70
+
71
+ MIT License
72
+
73
+ Permission is hereby granted, free of charge, to any person obtaining
74
+ a copy of this software and associated documentation files (the
75
+ "Software"), to deal in the Software without restriction, including
76
+ without limitation the rights to use, copy, modify, merge, publish,
77
+ distribute, sublicense, and/or sell copies of the Software, and to
78
+ permit persons to whom the Software is furnished to do so, subject to
79
+ the following conditions:
80
+
81
+ The above copyright notice and this permission notice shall be
82
+ included in all copies or substantial portions of the Software.
83
+
84
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
86
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
87
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
88
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
89
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
90
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'libs/nobody'
7
+ t.test_files = FileList['test/lib/nobody/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module Nobody
2
+ VERSION = "0.1"
3
+ end
data/lib/nobody.rb ADDED
@@ -0,0 +1,31 @@
1
+ require_relative "./nobody/version"
2
+
3
+ module Nobody
4
+ def self.included(klass)
5
+ class << klass
6
+ private
7
+ def returns_nil_for(*methods)
8
+ define_methods_with_return_value(nil, methods)
9
+ end
10
+
11
+ def returns_true_for(*methods)
12
+ define_methods_with_return_value(true, methods)
13
+ end
14
+
15
+ def returns_false_for(*methods)
16
+ define_methods_with_return_value(false, methods)
17
+ end
18
+
19
+ # takes a value and method array, defines instance methods returning that value
20
+ def define_methods_with_return_value(value, methods)
21
+ methods.each do |name|
22
+ define_method name do
23
+ value
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ end
data/nobody.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/nobody/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["GordonDiggs"]
6
+ gem.email = ["gordon@gordondiggs.com"]
7
+ gem.description = %q{Null Object Pattern shorthand}
8
+ gem.summary = %q{Easily use the Null Object Pattern in a class}
9
+ gem.homepage = "https://github.com/GordonDiggs/nobody"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "nobody"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Nobody::VERSION
17
+
18
+ gem.add_development_dependency 'rake'
19
+ end
@@ -0,0 +1,23 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Nobody do
4
+ describe 'including it in a class' do
5
+ it 'should make new methods' do
6
+ class TestClass
7
+ include Nobody
8
+ returns_true_for :true_method
9
+ returns_nil_for :nil_method
10
+ returns_false_for :false_method
11
+ end
12
+
13
+ TestClass.new.must_respond_to(:true_method)
14
+ assert TestClass.new.true_method
15
+
16
+ TestClass.new.must_respond_to(:false_method)
17
+ assert_equal false, TestClass.new.false_method
18
+
19
+ TestClass.new.must_respond_to(:nil_method)
20
+ assert_nil TestClass.new.nil_method
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Nobody do
4
+ it "must have a version" do
5
+ Nobody::VERSION.wont_be_nil
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ Turn.config do |c|
2
+ c.format = :pretty
3
+ c.trace = true
4
+ c.natural = true
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require 'minitest/autorun'
5
+ require 'turn'
6
+ require_relative './minitest_helper'
7
+ require File.expand_path('../../lib/nobody.rb', __FILE__)
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nobody
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - GordonDiggs
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70262270121980 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70262270121980
25
+ description: Null Object Pattern shorthand
26
+ email:
27
+ - gordon@gordondiggs.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - lib/nobody.rb
37
+ - lib/nobody/version.rb
38
+ - nobody.gemspec
39
+ - test/lib/nobody/inclusion_test.rb
40
+ - test/lib/nobody/version_test.rb
41
+ - test/minitest_helper.rb
42
+ - test/test_helper.rb
43
+ homepage: https://github.com/GordonDiggs/nobody
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.15
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Easily use the Null Object Pattern in a class
67
+ test_files:
68
+ - test/lib/nobody/inclusion_test.rb
69
+ - test/lib/nobody/version_test.rb
70
+ - test/minitest_helper.rb
71
+ - test/test_helper.rb
72
+ has_rdoc: