tappie 0.9

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source :gemcutter
2
+
3
+ group :test do
4
+ gem "thoughtbot-shoulda"
5
+ gem "rcov"
6
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,12 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ rcov (0.9.9)
5
+ thoughtbot-shoulda (2.11.1)
6
+
7
+ PLATFORMS
8
+ ruby
9
+
10
+ DEPENDENCIES
11
+ rcov
12
+ thoughtbot-shoulda
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 guilherme silveira
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.markdown ADDED
@@ -0,0 +1,44 @@
1
+ = tappie
2
+
3
+ Tappie goes a "long" way in improving Ruby's tap method, which is similar to Rail's returning method.
4
+
5
+ It allows you to remove the syntax noise from that extra variable:
6
+
7
+ puts "Guilherme Silveira".tap { puts size }
8
+ # 18
9
+ # Guilherme Silveira
10
+
11
+ ## Benefits ##
12
+
13
+ Less noise if you are not using @variables of the current scope.
14
+ Less code.
15
+
16
+ ## Compatibility issues ##
17
+
18
+ Because tappie checks the Proc arity, it is fully compatible.
19
+
20
+ ## How to use configure it? ##
21
+
22
+ Either copy tappie.rb code to your project or gem install it:
23
+
24
+ gem install relata
25
+
26
+ Have fun!
27
+
28
+ == Team
29
+
30
+ Guilherme Silveira - Caelum
31
+
32
+ == Note on Patches/Pull Requests
33
+
34
+ * Fork the project.
35
+ * Make your feature addition or bug fix.
36
+ * Add tests for it. This is important so I don't break it in a
37
+ future version unintentionally.
38
+ * Commit, do not mess with rakefile, version, or history.
39
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
40
+ * Send me a pull request. Bonus points for topic branches.
41
+
42
+ == Copyright
43
+
44
+ Copyright (c) 2010 guilherme silveira. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "tappie"
8
+ gem.version = "0.9"
9
+ gem.summary = %Q{Enhanced tap or tap on steroids as some would prefer.}
10
+ gem.description = %Q{Allows tapping without the extra syntax noise of the parameter. Fully compatible with ruby 1.8 and 1.9.}
11
+ gem.email = "guilherme.silveira@caelum.com.br"
12
+ gem.homepage = "http://github.com/caelum/tappie"
13
+ gem.authors = ["Guilherme Silveira"]
14
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "tappie #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/lib/tappie.rb ADDED
@@ -0,0 +1,22 @@
1
+ module Tappie
2
+
3
+ # taps and returns the object itself.
4
+ #
5
+ # if the block has arity one, the object will be passed as an argument.
6
+ # if the block has no arity, the object is the scope (old style).
7
+ # if there is no block, just taps (why, why?).
8
+ def tap(&block)
9
+ if block_given?
10
+ if block.arity==1
11
+ yield self
12
+ else
13
+ self.instance_eval(&block)
14
+ end
15
+ end
16
+ self
17
+ end
18
+ end
19
+
20
+ class Object
21
+ include Tappie
22
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'tappie'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,46 @@
1
+ require 'helper'
2
+
3
+ class TestTappie < Test::Unit::TestCase
4
+
5
+ should "run a block if it exists" do
6
+ tapped = false
7
+ "Guilherme Silveira".tap { tapped = true }
8
+ assert tapped
9
+ end
10
+
11
+ should "return itself" do
12
+ a_friendly_guy = "Guilherme Silveira"
13
+ assert_equal a_friendly_guy.tap { }, a_friendly_guy
14
+ end
15
+
16
+ should "allow access to the object itself as self" do
17
+ char_len = -1
18
+ a_friendly_guy = "Guilherme Silveira"
19
+ a_friendly_guy.tap { char_len = size }
20
+ assert_equal 18, char_len
21
+ end
22
+
23
+ should "old style run a block if it exists" do
24
+ tapped = false
25
+ "Guilherme Silveira".tap { |who| tapped = true }
26
+ assert tapped
27
+ end
28
+
29
+ should "old style return itself" do
30
+ a_friendly_guy = "Guilherme Silveira"
31
+ assert_equal a_friendly_guy.tap { |who| }, a_friendly_guy
32
+ end
33
+
34
+ should "old style allow access to the object itself as self" do
35
+ char_len = -1
36
+ a_friendly_guy = "Guilherme Silveira"
37
+ a_friendly_guy.tap { |who| char_len = who.size }
38
+ assert_equal 18, char_len
39
+ end
40
+
41
+ should "taps if it has no block" do
42
+ a_friendly_guy = "Guilherme Silveira"
43
+ assert_equal a_friendly_guy, a_friendly_guy.tap
44
+ end
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tappie
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 9
9
+ version: "0.9"
10
+ platform: ruby
11
+ authors:
12
+ - Guilherme Silveira
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-20 00:00:00 -02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: Allows tapping without the extra syntax noise of the parameter. Fully compatible with ruby 1.8 and 1.9.
35
+ email: guilherme.silveira@caelum.com.br
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ - README.markdown
43
+ files:
44
+ - .document
45
+ - .gitignore
46
+ - Gemfile
47
+ - Gemfile.lock
48
+ - LICENSE
49
+ - README.markdown
50
+ - Rakefile
51
+ - lib/tappie.rb
52
+ - test/helper.rb
53
+ - test/test_tappie.rb
54
+ has_rdoc: true
55
+ homepage: http://github.com/caelum/tappie
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --charset=UTF-8
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.3.7
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Enhanced tap or tap on steroids as some would prefer.
88
+ test_files:
89
+ - test/helper.rb
90
+ - test/test_tappie.rb