not 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.
- data/CHANGELOG.rdoc +7 -0
- data/Manifest +8 -0
- data/README.rdoc +26 -0
- data/Rakefile +24 -0
- data/init.rb +1 -0
- data/lib/not.rb +50 -0
- data/not.gemspec +30 -0
- data/spec/not_spec.rb +48 -0
- metadata +69 -0
data/CHANGELOG.rdoc
ADDED
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= Not
|
2
|
+
|
3
|
+
|
4
|
+
This little gem/plugin adds a little syntactic sugar to your code. You can append not
|
5
|
+
in the middle of your code to improve readability.
|
6
|
+
|
7
|
+
= Examples
|
8
|
+
|
9
|
+
@foo.not.nil?
|
10
|
+
@user.not.active?
|
11
|
+
"something".not.tainted?
|
12
|
+
User.not.new(:name => 'iain') # not sure why you'd want to do this though
|
13
|
+
@foo.not.not.not.not.send(:not).not.nil? # sorry, couldn't resist
|
14
|
+
|
15
|
+
= Installation
|
16
|
+
|
17
|
+
To install as a gem:
|
18
|
+
|
19
|
+
gem sources add http://gems.github.com
|
20
|
+
gem install iain-not
|
21
|
+
|
22
|
+
To install as a Rails plugin:
|
23
|
+
|
24
|
+
ruby script/plugin install git://github.com/iain/not
|
25
|
+
|
26
|
+
Copyright (c) 2008 Iain Hecker, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
|
6
|
+
desc 'Default: run specs'
|
7
|
+
task :default => :spec
|
8
|
+
|
9
|
+
desc 'Run the specs'
|
10
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
11
|
+
t.spec_opts = ['--colour --format specdoc --loadby mtime --reverse']
|
12
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
13
|
+
end
|
14
|
+
|
15
|
+
Echoe.new('not', '0.0.1') do |p|
|
16
|
+
p.description = "Syntactic sugar for negating any results: @foo.not.nil?"
|
17
|
+
p.url = "http://github.com/iain/not"
|
18
|
+
p.author = "Iain Hecker"
|
19
|
+
p.email = "iain@iain.nl"
|
20
|
+
p.ignore_pattern = [ "tmp/*", "script/*" ]
|
21
|
+
p.development_dependencies = []
|
22
|
+
end
|
23
|
+
|
24
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'not'
|
data/lib/not.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Not
|
2
|
+
|
3
|
+
# Negates any command that comes after it.
|
4
|
+
#
|
5
|
+
# @foo.nil? # => true
|
6
|
+
# @foo.not.nil? # => false
|
7
|
+
def not
|
8
|
+
@_not_class ||= NotClass.new(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
# NotClass is the proxy object to perform other commands from.
|
12
|
+
class NotClass
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# The not method needs to pass self to work so the Notclass
|
17
|
+
def initialize(base)
|
18
|
+
@base = base
|
19
|
+
|
20
|
+
# Make the NotClass a proxy for whatever object it is called from
|
21
|
+
if self.class.respond_to?(:delegate_methods!)
|
22
|
+
self.class.delegate_methods!
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# The not-class is a proxy, but with negation. Send any method to it's base object
|
27
|
+
def method_missing(method, *args, &block)
|
28
|
+
not @base.send(method, *args, &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Also override any methods this method has so that you can use any method,
|
32
|
+
# including nil? and other basic methods.
|
33
|
+
def self.delegate_methods!
|
34
|
+
override = instance_methods.reject do |m|
|
35
|
+
m == 'method_missing' or m[0,1] == '_' or m == 'not'
|
36
|
+
end
|
37
|
+
override.each do |m|
|
38
|
+
class_eval(%Q{
|
39
|
+
def #{m}(*args, &block)
|
40
|
+
method_missing(:#{m}, *args, &block)
|
41
|
+
end
|
42
|
+
})
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
# Apply the magic
|
50
|
+
Object.send(:include, Not)
|
data/not.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{not}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Iain Hecker"]
|
9
|
+
s.date = %q{2009-10-10}
|
10
|
+
s.description = %q{Syntactic sugar for negating any results: @foo.not.nil?}
|
11
|
+
s.email = %q{iain@iain.nl}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc", "lib/not.rb"]
|
13
|
+
s.files = ["CHANGELOG.rdoc", "Manifest", "README.rdoc", "Rakefile", "init.rb", "lib/not.rb", "not.gemspec", "spec/not_spec.rb"]
|
14
|
+
s.homepage = %q{http://github.com/iain/not}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Not", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{not}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{Syntactic sugar for negating any results: @foo.not.nil?}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
data/spec/not_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/not'
|
2
|
+
|
3
|
+
class Duck
|
4
|
+
|
5
|
+
def quack?
|
6
|
+
true
|
7
|
+
end
|
8
|
+
|
9
|
+
def bark?
|
10
|
+
nil
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
class NotSpec < Spec::ExampleGroup
|
16
|
+
|
17
|
+
describe "Using the not method" do
|
18
|
+
|
19
|
+
it "should negate nil?" do
|
20
|
+
@foo.should be_nil
|
21
|
+
@foo.not.nil?.should be_false
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should chain" do
|
25
|
+
@foo.not.not.nil?.should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "a duck" do
|
29
|
+
|
30
|
+
before do
|
31
|
+
@duck = Duck.new
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should quack" do
|
35
|
+
@duck.quack?.should be_true
|
36
|
+
@duck.not.quack?.should be_false
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should not bark" do
|
40
|
+
@duck.bark?.should be_nil
|
41
|
+
@duck.not.bark?.should be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: not
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Iain Hecker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-10 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: "Syntactic sugar for negating any results: @foo.not.nil?"
|
17
|
+
email: iain@iain.nl
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- CHANGELOG.rdoc
|
24
|
+
- README.rdoc
|
25
|
+
- lib/not.rb
|
26
|
+
files:
|
27
|
+
- CHANGELOG.rdoc
|
28
|
+
- Manifest
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- init.rb
|
32
|
+
- lib/not.rb
|
33
|
+
- not.gemspec
|
34
|
+
- spec/not_spec.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/iain/not
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options:
|
41
|
+
- --line-numbers
|
42
|
+
- --inline-source
|
43
|
+
- --title
|
44
|
+
- Not
|
45
|
+
- --main
|
46
|
+
- README.rdoc
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "1.2"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project: not
|
64
|
+
rubygems_version: 1.3.5
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: "Syntactic sugar for negating any results: @foo.not.nil?"
|
68
|
+
test_files: []
|
69
|
+
|