plock 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/lib/plock.rb +11 -24
- data/lib/plock/version.rb +1 -1
- data/plock.gemspec +2 -0
- data/spec/plock_spec.rb +27 -6
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c762559276fd2fff6c9b8493782c35bb4624ef19
|
4
|
+
data.tar.gz: 7dcdcee27ca47f8227baa023361ac7b05228392c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8455faddd53d074406bf63b072db283b9fb78797b32eb42b85735ebe2f4b23a5698bca05e1822c558b8345c35d2deebaed2c91709f67bfff02ceb7146a344c39
|
7
|
+
data.tar.gz: c8d80609cb4025f5e3864113b7d0e0de37c8a80fc185edb2ad05d576d1f4ae6ed763e73a5c3b7004e8229aaa8471b34e5946c78c685c93bdfcc44888451bf956
|
data/lib/plock.rb
CHANGED
@@ -21,34 +21,19 @@ module Plock
|
|
21
21
|
[ block.to_source( attached_to: attached, strip_enclosure: true ), result ]
|
22
22
|
end
|
23
23
|
|
24
|
-
def print_block_with
|
25
|
-
returned = []
|
26
|
-
returned.concat args
|
27
|
-
|
24
|
+
def print_block_with inspect_method, attached, &block
|
28
25
|
block_source, block_result = Plock.inspect_block( attached, &block )
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
returned << block_result
|
33
|
-
returned.length > 1 ? returned : returned.first
|
26
|
+
puts self.format_with( inspect_method, block_source, block_result )
|
27
|
+
block_result
|
34
28
|
end
|
35
29
|
|
36
|
-
def format_with block_source, block_result
|
30
|
+
def format_with inspect_method, block_source, block_result
|
37
31
|
result = self.output_format.dup
|
38
32
|
result.sub! self::Format::PERCENT_B, block_source
|
39
33
|
result.sub! self::Format::PERCENT_R, block_result.__send__( inspect_method )
|
40
34
|
return result
|
41
35
|
end
|
42
36
|
|
43
|
-
def format block_source, block_result
|
44
|
-
self.format_with block_source, block_result, :inspect
|
45
|
-
end
|
46
|
-
|
47
|
-
if Object.public_method_defined? :pretty_inspect
|
48
|
-
def pretty_format block_source, block_result
|
49
|
-
self.format_with block_source, block_result, :pretty_inspect
|
50
|
-
end
|
51
|
-
end
|
52
37
|
end
|
53
38
|
|
54
39
|
end
|
@@ -56,21 +41,23 @@ end
|
|
56
41
|
module Kernel # reopen
|
57
42
|
alias p_without_plock p
|
58
43
|
def p_with_plock *args, &block
|
44
|
+
returned_by_p = p_without_plock( *args )
|
59
45
|
if block_given?
|
60
|
-
Plock.print_block_with :
|
46
|
+
Plock.print_block_with :inspect, :p, &block
|
61
47
|
else
|
62
|
-
|
48
|
+
returned_by_p
|
63
49
|
end
|
64
50
|
end
|
65
51
|
alias p p_with_plock
|
66
52
|
|
67
53
|
if Kernel.private_method_defined? :pp
|
68
54
|
alias pp_without_plock pp
|
69
|
-
def pp_with_plock
|
55
|
+
def pp_with_plock *args, &block
|
56
|
+
returned_by_pp = pp_without_plock( *args )
|
70
57
|
if block_given?
|
71
|
-
Plock.print_block_with :
|
58
|
+
Plock.print_block_with :pretty_inspect, :pp, &block
|
72
59
|
else
|
73
|
-
|
60
|
+
returned_by_pp
|
74
61
|
end
|
75
62
|
end
|
76
63
|
alias pp pp_with_plock
|
data/lib/plock/version.rb
CHANGED
data/plock.gemspec
CHANGED
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
spec.add_development_dependency "rb-readline"
|
24
26
|
|
25
27
|
spec.add_runtime_dependency "sourcify"
|
26
28
|
end
|
data/spec/plock_spec.rb
CHANGED
@@ -9,14 +9,14 @@ describe Plock do
|
|
9
9
|
end
|
10
10
|
it { should eq ['(a + 1)', 2] }
|
11
11
|
end
|
12
|
-
describe '.
|
12
|
+
describe '.format_with' do
|
13
13
|
context 'when Plock.output_format = "%b #=> %r"' do
|
14
14
|
before { described_class.output_format = "%b #=> %r" }
|
15
|
-
subject { described_class.
|
15
|
+
subject { described_class.format_with :inspect, '(a + 1)', 2 }
|
16
16
|
it { should eq '(a + 1) #=> 2' }
|
17
17
|
it 'never changes the output_format desructively' do
|
18
18
|
described_class.output_format = '%b and %r SHOULD NOT BE CHANGED'
|
19
|
-
described_class.
|
19
|
+
described_class.format_with :inspect, 'block', 'result'
|
20
20
|
described_class.output_format.should eq '%b and %r SHOULD NOT BE CHANGED'
|
21
21
|
end
|
22
22
|
end
|
@@ -29,18 +29,39 @@ RSpec::Matchers.define :include_when_ignoring_space_difference do|expected|
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
RSpec::Matchers.define :equals_when_ignoring_space_difference do|expected|
|
33
|
+
match do|actual|
|
34
|
+
expected.gsub( /\s+/, '' ) == actual.gsub( /\s+/, '' )
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
32
38
|
describe Kernel do
|
33
39
|
describe '#p' do
|
34
|
-
before
|
40
|
+
before { $stdout = StringIO.new '', 'wb' } # replaces the stdin for testing the output of p
|
41
|
+
after { $stdout = STDOUT } # restore default stdin
|
42
|
+
|
35
43
|
context 'when Plock.output_format = "%b #=> %r"' do
|
36
44
|
before( :all ) { Plock.output_format = "%b #=> %r" }
|
37
45
|
let( :no_percent ){ Plock.output_format.gsub( /%[br]/, '' ) }
|
46
|
+
|
38
47
|
subject { p { 1 + 1 } }
|
48
|
+
before { subject }
|
49
|
+
|
39
50
|
it { should be 2 }
|
40
|
-
it
|
51
|
+
it "prints out the block and the block's result onto stdin" do
|
41
52
|
$stdout.string.should include_when_ignoring_space_difference "(1 + 1) #{no_percent} 2"
|
42
53
|
end
|
54
|
+
|
55
|
+
context 'given both argument and block' do
|
56
|
+
subject { p( 'one plus one' ) { 1 + 1 } }
|
57
|
+
|
58
|
+
it { should be 2 }
|
59
|
+
it 'prints out its arguments, its block, and the result onto stdin' do
|
60
|
+
$stdout.string.should equals_when_ignoring_space_difference %Q'"one plus one" (1 + 1) #{no_percent} 2'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
43
64
|
end
|
44
|
-
|
65
|
+
|
45
66
|
end
|
46
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yamamoto Yuji
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rb-readline
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: sourcify
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
131
|
version: '0'
|
104
132
|
requirements: []
|
105
133
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.0.
|
134
|
+
rubygems_version: 2.0.2
|
107
135
|
signing_key:
|
108
136
|
specification_version: 4
|
109
137
|
summary: '''p { 1 + 1 }` prints "1 + 1 #=> 2". That''s all.'
|