why_not 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ pkg
3
+ nbproject
4
+ TODO.txt
5
+ *.gemspec
6
+ *.gem
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006-2009 Jeff Patmon
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.
data/README.rdoc ADDED
@@ -0,0 +1,32 @@
1
+ = WhyNot?
2
+
3
+ not_empty?, not_blank?, ... why_not? Tired of writing !array.empty? Ruby is ledgible and should be more ledgible. Ruby is terse and should be terser. A predicate method is one that returns a boolean and ends in a question mark. This simple library adds corresponding negation methods for all Ruby predicate methods.
4
+
5
+ == Resources
6
+
7
+ Install
8
+
9
+ * sudo gem install why_not
10
+
11
+ Use
12
+
13
+ * require 'why_not'
14
+
15
+
16
+ == Usage
17
+
18
+ In general
19
+
20
+ array = %w(one two three)
21
+ array.empty? # => false
22
+ array.not_empty? # => true
23
+
24
+ value = nil
25
+ value.nil? # => true
26
+ value.not_nil? # => false
27
+
28
+
29
+ == Dependencies
30
+
31
+ * rubygems
32
+ * meta_programming
data/Rakefile ADDED
@@ -0,0 +1,72 @@
1
+ #require 'rake/testtask'
2
+ require 'rake/rdoctask'
3
+ require 'rake/gempackagetask'
4
+ gem 'gem_version', '>= 0.0.1'
5
+ require 'gem_version'
6
+ #require 'rake/contrib/sshpublisher'
7
+
8
+ spec = Gem::Specification.new do |s|
9
+ s.name = 'why_not'
10
+ s.version = GemVersion.next_version
11
+ s.platform = Gem::Platform::RUBY
12
+ s.required_ruby_version = '>= 1.8.7'
13
+ s.description = 'not_empty?, not_blank?, not_defined? ... why not? This is Ruby, come on.'
14
+ s.summary = 'Comprehensive negation for all Ruby predicate methods.'
15
+
16
+ s.add_dependency('meta_programming', '>= 0.0.3')
17
+
18
+ exclude_folders = '' # 'spec/rails/{doc,lib,log,nbproject,tmp,vendor,test}'
19
+ exclude_files = [] # FileList['**/*.log'] + FileList[exclude_folders+'/**/*'] + FileList[exclude_folders]
20
+ s.files = FileList['{lib,spec}/**/*'] + %w(init.rb LICENSE Rakefile README.rdoc .gitignore) - exclude_files
21
+ s.require_path = 'lib'
22
+ s.has_rdoc = true
23
+ s.test_files = Dir['spec/*_spec.rb']
24
+
25
+ s.author = 'Jeff Patmon'
26
+ s.email = 'jpatmon@gmail.com'
27
+ s.homepage = 'http://github.com/jeffp/why_not/tree/master'
28
+ end
29
+
30
+ require 'spec/version'
31
+ require 'spec/rake/spectask'
32
+
33
+ desc "Run specs"
34
+ Spec::Rake::SpecTask.new(:spec) do |t|
35
+ t.spec_files = FileList['spec/*_spec.rb']
36
+ t.libs << 'lib' << 'spec'
37
+ t.rcov = false
38
+ t.spec_opts = ['--options', 'spec/spec.opts']
39
+ #t.rcov_dir = 'coverage'
40
+ #t.rcov_opts = ['--exclude', "kernel,load-diff-lcs\.rb,instance_exec\.rb,lib/spec.rb,lib/spec/runner.rb,^spec/*,bin/spec,examples,/gems,/Library/Ruby,\.autotest,#{ENV['GEM_HOME']}"]
41
+ end
42
+
43
+ desc "Generate documentation for the #{spec.name} gem."
44
+ Rake::RDocTask.new(:rdoc) do |rdoc|
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = spec.name
47
+ #rdoc.template = '../rdoc_template.rb'
48
+ rdoc.options << '--line-numbers' << '--inline-source'
49
+ rdoc.rdoc_files.include('README.rdoc', 'LICENSE', 'lib/**/*.rb')
50
+ end
51
+
52
+ desc 'Clean up gem build.'
53
+ task :clean do
54
+ FileUtils.rm_f Dir.glob('*.gem')
55
+ end
56
+
57
+ desc 'Generate a gemspec file.'
58
+ task :gemspec do
59
+ File.open("#{spec.name}.gemspec", 'w') do |f|
60
+ f.write spec.to_ruby
61
+ end
62
+ GemVersion.increment_version
63
+ GemVersion.commit_and_push
64
+ end
65
+
66
+ Rake::GemPackageTask.new(spec) do |p|
67
+ p.gem_spec = spec
68
+ p.need_tar = RUBY_PLATFORM =~ /mswin/ ? false : true
69
+ p.need_zip = true
70
+ end
71
+
72
+ Dir['tasks/**/*.rake'].each {|rake| load rake}
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'arspy'
data/lib/why_not.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'meta_programming'
2
+
3
+ class Object
4
+ define_ghost_method(/^not_.+\?$/) do |object, symbol, *args|
5
+ symbol.to_s =~ /^not_(.+\?)$/
6
+ regular_method = $1.to_sym
7
+ !object.__send__(regular_method, *args)
8
+ end
9
+ end
10
+
11
+
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1 @@
1
+ require 'rubygems'
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'lib/why_not'
3
+
4
+ describe "WhyNot" do
5
+ describe "/^not_.*\?$/ method" do
6
+ it "should work for empty? method on arrays" do
7
+ array = []
8
+ array.empty?.should be_true
9
+ lambda { array.not_empty?.should be_false }.should_not raise_exception
10
+ array = %w(one two three four five)
11
+ array.empty?.should be_false
12
+ array.not_empty?.should be_true
13
+ end
14
+ it "should work for NilClass" do
15
+ obj = nil
16
+ obj.nil?.should be_true
17
+ lambda { obj.not_nil?.should be_false }.should_not raise_exception
18
+ end
19
+ it "should raise NoMethodError if associated method does not exist" do
20
+ array = %w(one two three)
21
+ lambda { array.not_even? }.should raise_exception(NoMethodError, /even/)
22
+ end
23
+ it "should work for methods defined through opening a class" do
24
+ class TestArray < Array; def even?; self.size%2 == 0; end; end
25
+ array = TestArray.new(%w(one two three))
26
+ lambda { array.even?.should == false }.should_not raise_exception
27
+ lambda { array.not_even?.should == true}.should_not raise_exception
28
+ end
29
+ it "should raise NoMethodError when not negating a test (?) method" do
30
+ array = %w(one two three)
31
+ lambda { array.not_length }.should raise_exception(NoMethodError, /not_length/)
32
+ end
33
+ it "should not access protected methods but should from inside method call" do
34
+ class TestArray < Array; def protected_odd?; self.size % 2 != 0; end; protected :protected_odd?; end
35
+ array = TestArray.new(%w(one two three))
36
+ lambda { array.protected_odd? }.should raise_exception
37
+ class TestArray < Array; def inner_odd?; protected_odd?; end; end
38
+ lambda { array.inner_odd?.should == true }.should_not raise_exception
39
+ lambda { array.not_inner_odd?.should == false}.should_not raise_exception
40
+ end
41
+ it "should not access private methods but should from inside method call" do
42
+ class TestArray < Array; def private_odd?; self.size % 2 != 0; end; private :private_odd?; end
43
+ array = TestArray.new(%w(one two three))
44
+ lambda { array.privat_odd? }.should raise_exception
45
+ class TestArray < Array; def inner_odd?; private_odd?; end; end
46
+ lambda { array.inner_odd?.should == true }.should_not raise_exception
47
+ lambda { array.not_inner_odd?.should == false}.should_not raise_exception
48
+ end
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: why_not
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Jeff Patmon
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-29 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: meta_programming
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 0
30
+ - 3
31
+ version: 0.0.3
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: not_empty?, not_blank?, not_defined? ... why not? This is Ruby, come on.
35
+ email: jpatmon@gmail.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - lib/why_not.rb
44
+ - spec/spec_helper.rb
45
+ - spec/why_not_spec.rb
46
+ - spec/spec.opts
47
+ - init.rb
48
+ - LICENSE
49
+ - Rakefile
50
+ - README.rdoc
51
+ - .gitignore
52
+ has_rdoc: true
53
+ homepage: http://github.com/jeffp/why_not/tree/master
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 1
67
+ - 8
68
+ - 7
69
+ version: 1.8.7
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.6
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Comprehensive negation for all Ruby predicate methods.
84
+ test_files:
85
+ - spec/why_not_spec.rb