notty 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in notty.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Ernie Miller
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,67 @@
1
+ = Notty
2
+
3
+ It became clear to me, after reviewing {a recent Rails pull request}[https://github.com/rails/rails/pull/258],
4
+ that when dealing with "interrogation" methods (that is, methods intended
5
+ to return a true/false value, answering some question about an object), Ruby
6
+ is simply not expressive enough on its own.
7
+
8
+ Sure, Array#empty? is handy. But what if we want to know if our array is
9
+ *not* empty? Should we really be expected to write:
10
+
11
+ ![1, 2, 3].empty?
12
+ # or...
13
+ not [1, 2, 3].empty?
14
+
15
+ Perish the thought! We Rubyists, always moving forward toward greater levels
16
+ of expression in our code, can do better than this.
17
+
18
+ How about <tt>[1,2,3].full?</tt> Well, that would be expressive, but it's not
19
+ expressing the right thing. You see, the array isn't full, it's just not empty!
20
+
21
+ Enter Notty. Simply add Notty to your project's Gemfile, and you'll never face
22
+ the issue of non-expressiveness again.
23
+
24
+ Let's tackle that non-empty array problem once again, this time with the power of
25
+ Notty behind us.
26
+
27
+ [1, 2, 3].not_empty? # => true
28
+
29
+ Awesome! Overflowing with expressiveness.
30
+
31
+ == But wait, there's more!
32
+
33
+ What if we want to see if the opposite is true? No problem!
34
+
35
+ [1, 2, 3].not_not_empty? # => false
36
+
37
+ Easy!
38
+
39
+ In fact, as you can see from these examples from Notty's extensive test
40
+ suite, the possibilities are limitless (preceding "limitless" claim is
41
+ subject to platform callstack depth):
42
+
43
+ it 'negates frozen?' do
44
+ @o.not_frozen?.should be_true
45
+ end
46
+
47
+ it 'negates negated frozen?' do
48
+ @o.not_not_frozen?.should be_false
49
+ end
50
+
51
+ it 'negates negated negated frozen?' do
52
+ @o.not_not_not_frozen?.should be_true
53
+ end
54
+
55
+ it 'negates negated negated negated frozen?' do
56
+ @o.not_not_not_not_frozen?.should be_false
57
+ end
58
+
59
+ it 'negates negated negated negated negated frozen?' do
60
+ @o.not_not_not_not_not_frozen?.should be_true
61
+ end
62
+
63
+ it 'negates negated negated negated negated negated frozen?' do
64
+ @o.not_not_not_not_not_not_frozen?.should be_false
65
+ end
66
+
67
+ Install Notty today. Go forth, and express yourself!
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
@@ -0,0 +1,22 @@
1
+ module Notty
2
+
3
+ def respond_to? method_id, include_private = false
4
+ super || if match = method_id.to_s.match(/^not_(.*\?)$/)
5
+ send(:respond_to?, match.captures.first, include_private)
6
+ else
7
+ false
8
+ end
9
+ end
10
+
11
+ def method_missing method_id, *args, &block
12
+ if match = method_id.to_s.match(/^not_(.*\?)$/)
13
+ !send(match.captures.first, *args, &block)
14
+ else
15
+ super
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+ Object.send :include, Notty
22
+ #Class.send :include, Notty
@@ -0,0 +1,3 @@
1
+ module Notty
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "notty/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "notty"
7
+ s.version = Notty::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ernie Miller"]
10
+ s.email = ["ernie@metautonomo.us"]
11
+ s.homepage = "http://github.com/ernie/notty"
12
+ s.summary = %q{Because every yin has a yang.}
13
+ s.description = %q{
14
+ This ridiculous gem inspired by the epic pull request thread
15
+ at https://github.com/rails/rails/pull/258.
16
+ }
17
+
18
+ s.rubyforge_project = "notty"
19
+
20
+ s.add_development_dependency 'rspec', '~> 2.4.0'
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe Notty do
4
+
5
+ context 'enhances an object instance so that it' do
6
+ before do
7
+ @o = Object.new
8
+ end
9
+
10
+ it 'negates respond_to?' do
11
+ @o.not_respond_to?(:gipe).should be_true
12
+ end
13
+
14
+ it 'negates negated respond_to?' do
15
+ @o.not_not_respond_to?(:gipe).should be_false
16
+ end
17
+
18
+ it 'negates negated negated respond_to?' do
19
+ @o.not_not_not_respond_to?(:gipe).should be_true
20
+ end
21
+
22
+ it 'negates frozen?' do
23
+ @o.not_frozen?.should be_true
24
+ end
25
+
26
+ it 'negates negated frozen?' do
27
+ @o.not_not_frozen?.should be_false
28
+ end
29
+
30
+ it 'negates negated negated frozen?' do
31
+ @o.not_not_not_frozen?.should be_true
32
+ end
33
+
34
+ it 'negates negated negated negated frozen?' do
35
+ @o.not_not_not_not_frozen?.should be_false
36
+ end
37
+
38
+ it 'negates negated negated negated negated frozen?' do
39
+ @o.not_not_not_not_not_frozen?.should be_true
40
+ end
41
+
42
+ it 'negates negated negated negated negated negated frozen?' do
43
+ @o.not_not_not_not_not_not_frozen?.should be_false
44
+ end
45
+
46
+ it 'responds to negated methods' do
47
+ @o.should respond_to :not_frozen?
48
+ end
49
+
50
+ it 'responds to negated negated methods' do
51
+ @o.should respond_to :not_not_frozen?
52
+ end
53
+
54
+ it 'does not negate a method that does not end in ?' do
55
+ expect { @o.not_hash }.to raise_error NoMethodError
56
+ end
57
+ end
58
+
59
+ context 'enhances your custom object instance so that it' do
60
+ before do
61
+ @o = MyObject.new
62
+ end
63
+
64
+ it 'negates a custom method' do
65
+ @o.not_awesome?.should be_false
66
+ end
67
+
68
+ it 'negates a negated custom method' do
69
+ @o.not_not_awesome?.should be_true
70
+ end
71
+
72
+ it 'negates a negated negated custom method' do
73
+ @o.not_not_not_awesome?.should be_false
74
+ end
75
+ end
76
+
77
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'notty'
4
+
5
+ Dir[File.expand_path('../support/*.rb', __FILE__)].each do |f|
6
+ require f
7
+ end
@@ -0,0 +1,5 @@
1
+ class MyObject
2
+ def awesome?
3
+ true
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: notty
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Ernie Miller
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-12 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 2.4.0
24
+ type: :development
25
+ version_requirements: *id001
26
+ description: "\n This ridiculous gem inspired by the epic pull request thread\n at https://github.com/rails/rails/pull/258.\n "
27
+ email:
28
+ - ernie@metautonomo.us
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - LICENSE
39
+ - README.rdoc
40
+ - Rakefile
41
+ - lib/notty.rb
42
+ - lib/notty/version.rb
43
+ - notty.gemspec
44
+ - spec/notty_spec.rb
45
+ - spec/spec_helper.rb
46
+ - spec/support/my_object.rb
47
+ homepage: http://github.com/ernie/notty
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project: notty
70
+ rubygems_version: 1.7.2
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Because every yin has a yang.
74
+ test_files:
75
+ - spec/notty_spec.rb
76
+ - spec/spec_helper.rb
77
+ - spec/support/my_object.rb