tapp 1.3.1 → 1.4.0
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/.rspec +1 -1
- data/CHANGELOG.md +19 -7
- data/LICENSE +1 -1
- data/README.md +61 -0
- data/lib/tapp.rb +12 -43
- data/lib/tapp/configuration.rb +14 -0
- data/lib/tapp/deprecated.rb +15 -0
- data/lib/tapp/object_extension.rb +24 -0
- data/lib/tapp/printer.rb +30 -0
- data/lib/tapp/printer/awesome_print.rb +10 -0
- data/lib/tapp/printer/pretty_print.rb +10 -0
- data/lib/tapp/printer/puts.rb +9 -0
- data/lib/tapp/util.rb +17 -0
- data/lib/tapp/version.rb +1 -1
- data/spec/acceptance/default_printer.feature +14 -0
- data/spec/acceptance/report_caller.feature +21 -0
- data/spec/acceptance/tapp.feature +0 -4
- data/spec/acceptance/taputs.feature +16 -0
- data/spec/spec_helper.rb +7 -2
- data/spec/steps/global_steps.rb +28 -0
- data/tapp.gemspec +2 -0
- metadata +50 -10
- data/README.rdoc +0 -49
- data/spec/steps/tapp_steps.rb +0 -18
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
-r turnip
|
1
|
+
-r turnip/rspec
|
data/CHANGELOG.md
CHANGED
@@ -1,17 +1,29 @@
|
|
1
1
|
# ChangeLog
|
2
2
|
|
3
|
-
## 1.
|
3
|
+
## 1.4.0 (2012-07-08)
|
4
4
|
|
5
|
-
|
5
|
+
Some API changes for future enhancements.
|
6
6
|
|
7
|
-
|
7
|
+
* Added `Tapp.config` and `Tapp.configure`. See README.md for details.
|
8
|
+
* `Tapp.verbose` moved to `Tapp.config.report_caller`.
|
9
|
+
* `Object#taap` is deprecated. Set `Tapp.config.default_printer = :awesome_print` and use `#tapp` instead.
|
8
10
|
|
9
|
-
|
11
|
+
## 1.3.1 (2012-03-13)
|
10
12
|
|
11
|
-
|
13
|
+
* `tapp grep` finds "taputs" and "taap". (@kei-s)
|
12
14
|
|
13
|
-
|
15
|
+
## 1.3.0 (2011-11-01)
|
14
16
|
|
15
|
-
|
17
|
+
* Add `tapp` command-line tool. (@ursm)
|
18
|
+
|
19
|
+
## 1.2.0 (2011-10-27)
|
20
|
+
|
21
|
+
* Add `Tapp.verbose` option. (@moro)
|
22
|
+
|
23
|
+
## 1.1.0 (2011-07-06)
|
24
|
+
|
25
|
+
* `Object#taap` support `awesome_print`. (Thanks @ryopeko!)
|
26
|
+
|
27
|
+
## 1.0.0 (2010-07-07)
|
16
28
|
|
17
29
|
initial release
|
data/LICENSE
CHANGED
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# tapp 
|
2
|
+
|
3
|
+
## Install
|
4
|
+
|
5
|
+
```
|
6
|
+
$ gem install tapp
|
7
|
+
```
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
require 'tapp'
|
13
|
+
|
14
|
+
'foo'.tapp #=> `pp 'foo'` and return 'foo'
|
15
|
+
'foo'.taputs #=> `puts 'foo'` and return 'foo'
|
16
|
+
```
|
17
|
+
|
18
|
+
See more examples in [spec/acceptance](https://github.com/esminc/tapp/tree/master/spec/acceptance) directory.
|
19
|
+
|
20
|
+
## Configuration
|
21
|
+
|
22
|
+
``` ruby
|
23
|
+
Tapp.configure do |config|
|
24
|
+
config.default_printer = :awesome_print
|
25
|
+
config.report_caller = true
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
<table>
|
30
|
+
<tr>
|
31
|
+
<th>Key</th>
|
32
|
+
<th>Default</th>
|
33
|
+
<th>Description</th>
|
34
|
+
</tr>
|
35
|
+
<tr>
|
36
|
+
<td><code>default_printer</code></td>
|
37
|
+
<td><code>:pretty_print</code></td>
|
38
|
+
<td><a href="https://github.com/esminc/tapp/blob/master/spec/acceptance/default_printer.feature">default_printer.feature</a></td>
|
39
|
+
</tr>
|
40
|
+
<tr>
|
41
|
+
<td><code>report_caller</code></td>
|
42
|
+
<td><code>false</code></td>
|
43
|
+
<td><a href="https://github.com/esminc/tapp/blob/master/spec/acceptance/report_caller.feature">report_caller.feature</a></td>
|
44
|
+
</tr>
|
45
|
+
</table>
|
46
|
+
|
47
|
+
## Note on Patches/Pull Requests
|
48
|
+
|
49
|
+
* Fork the project.
|
50
|
+
* Make your feature addition or bug fix.
|
51
|
+
* Add tests for it. This is important so I don't break it in a
|
52
|
+
future version unintentionally.
|
53
|
+
* Commit, do not mess with rakefile, version, or history.
|
54
|
+
(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)
|
55
|
+
* Send me a pull request. Bonus points for topic branches.
|
56
|
+
|
57
|
+
## Contributors
|
58
|
+
See https://github.com/esminc/tapp/contributors
|
59
|
+
|
60
|
+
## Copyright
|
61
|
+
Copyright © 2010-2012 Keita Urashima. See LICENSE for details.
|
data/lib/tapp.rb
CHANGED
@@ -1,53 +1,22 @@
|
|
1
|
-
require 'tapp/
|
1
|
+
require 'tapp/configuration'
|
2
|
+
require 'tapp/deprecated'
|
3
|
+
require 'tapp/object_extension'
|
4
|
+
require 'tapp/printer'
|
2
5
|
|
3
6
|
module Tapp
|
4
|
-
|
5
|
-
attr_accessor :verbose
|
6
|
-
|
7
|
-
def report_called
|
8
|
-
return unless verbose
|
9
|
-
method_quoted = caller[0].split(':in').last.strip
|
10
|
-
puts "#{method_quoted} in #{caller[1]}"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class Object
|
16
|
-
def tapp
|
17
|
-
require 'pp'
|
18
|
-
|
19
|
-
Object.module_eval do
|
20
|
-
remove_method :tapp
|
7
|
+
extend Deprecated
|
21
8
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
9
|
+
class << self
|
10
|
+
def config
|
11
|
+
@config ||= Tapp::Configuration.new
|
26
12
|
end
|
27
13
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
def taputs
|
32
|
-
Tapp.report_called
|
33
|
-
tap { puts block_given? ? yield(self) : self }
|
34
|
-
end
|
14
|
+
def configure
|
15
|
+
yield config
|
35
16
|
|
36
|
-
|
37
|
-
require 'ap'
|
38
|
-
|
39
|
-
Object.module_eval do
|
40
|
-
remove_method :taap
|
41
|
-
|
42
|
-
def taap
|
43
|
-
Tapp.report_called
|
44
|
-
tap { ap block_given? ? yield(self) : self }
|
45
|
-
end
|
17
|
+
config
|
46
18
|
end
|
47
|
-
|
48
|
-
taap
|
49
|
-
rescue LoadError
|
50
|
-
warn "Sorry, you need to install awesome_print: `gem install awesome_print`"
|
51
19
|
end
|
52
20
|
end
|
53
21
|
|
22
|
+
Object.__send__ :include, Tapp::ObjectExtension
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Tapp
|
2
|
+
module Deprecated
|
3
|
+
def verbose=(bool)
|
4
|
+
warn 'DEPRECATION WARNING: Tapp.verbose= is deprecated. Use Tapp.config.report_caller= instead.'
|
5
|
+
|
6
|
+
config.report_caller = bool
|
7
|
+
end
|
8
|
+
|
9
|
+
def verbose
|
10
|
+
warn 'DEPRECATION WARNING: Tapp.verbose is deprecated. Use Tapp.config.report_caller instead.'
|
11
|
+
|
12
|
+
config.report_caller
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'tapp/printer'
|
2
|
+
require 'tapp/util'
|
3
|
+
|
4
|
+
module Tapp
|
5
|
+
module ObjectExtension
|
6
|
+
def tapp(printer = Tapp.config.default_printer)
|
7
|
+
Tapp::Util.report_called if Tapp.config.report_caller
|
8
|
+
|
9
|
+
tap {
|
10
|
+
Tapp::Printer.instance(printer).print block_given? ? yield(self) : self
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def taputs
|
15
|
+
tapp :puts
|
16
|
+
end
|
17
|
+
|
18
|
+
def taap
|
19
|
+
warn 'DEPRECATION WARNING: `taap` is deprecated. Set `Tapp.config.default_printer = :awesome_print` and use `tapp` instead.'
|
20
|
+
|
21
|
+
tapp :awesome_print
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/tapp/printer.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Tapp
|
4
|
+
module Printer
|
5
|
+
autoload :AwesomePrint, 'tapp/printer/awesome_print'
|
6
|
+
autoload :PrettyPrint, 'tapp/printer/pretty_print'
|
7
|
+
autoload :Puts, 'tapp/printer/puts'
|
8
|
+
|
9
|
+
def self.instance(name)
|
10
|
+
case name
|
11
|
+
when :pretty_print
|
12
|
+
PrettyPrint.instance
|
13
|
+
when :puts
|
14
|
+
Puts.instance
|
15
|
+
when :awesome_print
|
16
|
+
AwesomePrint.instance
|
17
|
+
else
|
18
|
+
raise ArgumentError, "Unknown printer: #{name.inspect}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Base
|
23
|
+
include Singleton
|
24
|
+
|
25
|
+
def print(*args)
|
26
|
+
raise NotImplementedError
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/tapp/util.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'tapp'
|
2
|
+
|
3
|
+
module Tapp
|
4
|
+
module Util
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def report_called
|
8
|
+
inner, outer = caller.partition {|line|
|
9
|
+
line.include?('/lib/tapp')
|
10
|
+
}
|
11
|
+
|
12
|
+
method_quoted = inner.last.split(':in').last.strip
|
13
|
+
|
14
|
+
puts "#{method_quoted} in #{outer.first}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/tapp/version.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
Feature: config.default_printer
|
2
|
+
Scenario: set config.default_printer to :awesome_print and call tapp
|
3
|
+
Given I have the following code:
|
4
|
+
"""
|
5
|
+
Tapp.config.default_printer = :awesome_print
|
6
|
+
|
7
|
+
'hoge'.tapp
|
8
|
+
"""
|
9
|
+
|
10
|
+
When Ruby it
|
11
|
+
Then I should see:
|
12
|
+
"""
|
13
|
+
"hoge"
|
14
|
+
"""
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Feature: config.report_caller
|
2
|
+
Scenario: set config.report_caller to true and call tapp
|
3
|
+
Given a file named "hello.rb" with:
|
4
|
+
"""
|
5
|
+
Tapp.config.report_caller = true
|
6
|
+
|
7
|
+
class Hello
|
8
|
+
def say
|
9
|
+
'hello'.tapp
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Hello.new.say
|
14
|
+
"""
|
15
|
+
|
16
|
+
When Ruby it
|
17
|
+
Then I should see:
|
18
|
+
"""
|
19
|
+
`tapp' in hello.rb:5:in `say'
|
20
|
+
"hello"
|
21
|
+
"""
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
step 'I have the following code:' do |code|
|
2
|
+
@code = code
|
3
|
+
end
|
4
|
+
|
5
|
+
step 'a file named :filename with:' do |filename, code|
|
6
|
+
@filename, @code = filename, code
|
7
|
+
end
|
8
|
+
|
9
|
+
step 'Ruby it' do
|
10
|
+
stdout = StringIO.new
|
11
|
+
$stdout = stdout
|
12
|
+
|
13
|
+
begin
|
14
|
+
if @filename
|
15
|
+
eval @code, binding, @filename, 1
|
16
|
+
else
|
17
|
+
eval @code
|
18
|
+
end
|
19
|
+
ensure
|
20
|
+
$stdout = STDOUT
|
21
|
+
end
|
22
|
+
|
23
|
+
@output = stdout.string.gsub(/\e\[0.*?m/, '').chop
|
24
|
+
end
|
25
|
+
|
26
|
+
step 'I should see:' do |output|
|
27
|
+
@output.should == output
|
28
|
+
end
|
data/tapp.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: turnip
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,7 +37,28 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: awesome_print
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
36
62
|
description: tap { pp self }
|
37
63
|
email:
|
38
64
|
- ursm@ursm.jp
|
@@ -47,15 +73,26 @@ files:
|
|
47
73
|
- CHANGELOG.md
|
48
74
|
- Gemfile
|
49
75
|
- LICENSE
|
50
|
-
- README.
|
76
|
+
- README.md
|
51
77
|
- Rakefile
|
52
78
|
- bin/tapp
|
53
79
|
- lib/tapp.rb
|
54
80
|
- lib/tapp/command.rb
|
81
|
+
- lib/tapp/configuration.rb
|
82
|
+
- lib/tapp/deprecated.rb
|
83
|
+
- lib/tapp/object_extension.rb
|
84
|
+
- lib/tapp/printer.rb
|
85
|
+
- lib/tapp/printer/awesome_print.rb
|
86
|
+
- lib/tapp/printer/pretty_print.rb
|
87
|
+
- lib/tapp/printer/puts.rb
|
88
|
+
- lib/tapp/util.rb
|
55
89
|
- lib/tapp/version.rb
|
90
|
+
- spec/acceptance/default_printer.feature
|
91
|
+
- spec/acceptance/report_caller.feature
|
56
92
|
- spec/acceptance/tapp.feature
|
93
|
+
- spec/acceptance/taputs.feature
|
57
94
|
- spec/spec_helper.rb
|
58
|
-
- spec/steps/
|
95
|
+
- spec/steps/global_steps.rb
|
59
96
|
- tapp.gemspec
|
60
97
|
homepage: http://github.com/esminc/tapp
|
61
98
|
licenses: []
|
@@ -77,11 +114,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
114
|
version: '0'
|
78
115
|
requirements: []
|
79
116
|
rubyforge_project:
|
80
|
-
rubygems_version: 1.8.
|
117
|
+
rubygems_version: 1.8.23
|
81
118
|
signing_key:
|
82
119
|
specification_version: 3
|
83
120
|
summary: tap { pp self }
|
84
121
|
test_files:
|
122
|
+
- spec/acceptance/default_printer.feature
|
123
|
+
- spec/acceptance/report_caller.feature
|
85
124
|
- spec/acceptance/tapp.feature
|
125
|
+
- spec/acceptance/taputs.feature
|
86
126
|
- spec/spec_helper.rb
|
87
|
-
- spec/steps/
|
127
|
+
- spec/steps/global_steps.rb
|
data/README.rdoc
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
= tapp {<img src="https://secure.travis-ci.org/esminc/tapp.png?branch=master" alt="Build Status" />}[http://travis-ci.org/esminc/tapp]
|
2
|
-
|
3
|
-
== Usage
|
4
|
-
|
5
|
-
$ gem install tapp
|
6
|
-
|
7
|
-
require 'tapp'
|
8
|
-
...
|
9
|
-
foo bar.tapp #=> pp bar
|
10
|
-
foo bar.taputs #=> puts bar
|
11
|
-
foo bar.taap #=> ap bar
|
12
|
-
|
13
|
-
examples of use:
|
14
|
-
|
15
|
-
>> require 'tapp'
|
16
|
-
=> true
|
17
|
-
>> (1..5).tapp.select(&:odd?).tapp.inject(&:+)
|
18
|
-
1..5
|
19
|
-
[1, 3, 5]
|
20
|
-
=> 9
|
21
|
-
>> {:a => 1, :b => 2}.tapp(&:keys).tapp(&:values)
|
22
|
-
[:a, :b]
|
23
|
-
[1, 2]
|
24
|
-
=> {:a=>1, :b=>2}
|
25
|
-
|
26
|
-
=== Verbose Mode
|
27
|
-
|
28
|
-
>> Tapp::verbose = true
|
29
|
-
>> (1..5).tapp
|
30
|
-
`tapp' in (irb):2:in `irb_binding'
|
31
|
-
1..5
|
32
|
-
=> 1..5
|
33
|
-
|
34
|
-
== Note on Patches/Pull Requests
|
35
|
-
|
36
|
-
* Fork the project.
|
37
|
-
* Make your feature addition or bug fix.
|
38
|
-
* Add tests for it. This is important so I don't break it in a
|
39
|
-
future version unintentionally.
|
40
|
-
* Commit, do not mess with rakefile, version, or history.
|
41
|
-
(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)
|
42
|
-
* Send me a pull request. Bonus points for topic branches.
|
43
|
-
|
44
|
-
== Contributors
|
45
|
-
see https://github.com/esminc/tapp/contributors
|
46
|
-
|
47
|
-
== Copyright
|
48
|
-
|
49
|
-
Copyright (c) 2010 Keita Urashima. See LICENSE for details.
|
data/spec/steps/tapp_steps.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
step "I have the following code:" do |code|
|
2
|
-
@code = code
|
3
|
-
end
|
4
|
-
|
5
|
-
step "Ruby it" do
|
6
|
-
stdout = StringIO.new
|
7
|
-
$stdout = stdout
|
8
|
-
begin
|
9
|
-
eval @code
|
10
|
-
ensure
|
11
|
-
$stdout = STDOUT
|
12
|
-
end
|
13
|
-
@output = stdout.string.chop
|
14
|
-
end
|
15
|
-
|
16
|
-
step "I should see:" do |output|
|
17
|
-
@output.should == output
|
18
|
-
end
|