nkpart-accidentally 0.0.1 → 0.0.2
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/Manifest.txt +4 -0
- data/Rakefile +2 -2
- data/accidentally.gemspec +4 -4
- data/lib/accidentally/invocation_result.rb +14 -0
- data/lib/accidentally/mad_hax.rb +5 -1
- data/lib/accidentally/method_invoker.rb +14 -10
- data/lib/accidentally.rb +1 -1
- data/spec/accidentally_spec.rb +8 -20
- data/spec/invocation_result_spec.rb +11 -0
- data/spec/method_invoker_spec.rb +14 -0
- metadata +7 -3
data/Manifest.txt
CHANGED
@@ -6,6 +6,7 @@ Rakefile
|
|
6
6
|
TODO
|
7
7
|
accidentally.gemspec
|
8
8
|
coverage/index.html
|
9
|
+
coverage/lib-accidentally-invocation_result_rb.html
|
9
10
|
coverage/lib-accidentally-mad_hax_rb.html
|
10
11
|
coverage/lib-accidentally-method_invoker_rb.html
|
11
12
|
coverage/lib-accidentally-patches-kernel_rb.html
|
@@ -14,6 +15,7 @@ coverage/lib-accidentally_rb.html
|
|
14
15
|
etc/examples.rb
|
15
16
|
etc/textmate_command.rb
|
16
17
|
lib/accidentally.rb
|
18
|
+
lib/accidentally/invocation_result.rb
|
17
19
|
lib/accidentally/mad_hax.rb
|
18
20
|
lib/accidentally/method_invoker.rb
|
19
21
|
lib/accidentally/patches/kernel.rb
|
@@ -22,6 +24,8 @@ script/console
|
|
22
24
|
script/destroy
|
23
25
|
script/generate
|
24
26
|
spec/accidentally_spec.rb
|
27
|
+
spec/invocation_result_spec.rb
|
28
|
+
spec/method_invoker_spec.rb
|
25
29
|
spec/spec.opts
|
26
30
|
spec/spec_helper.rb
|
27
31
|
tasks/rspec.rake
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require File.dirname(__FILE__) + '/lib/accidentally'
|
|
6
6
|
$hoe = Hoe.new('accidentally', Accidentally::VERSION) do |p|
|
7
7
|
p.developer('nkpart', 'nkpart@gmail.com')
|
8
8
|
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
-
p.post_install_message = '
|
9
|
+
p.post_install_message = 'the whole thing?!'
|
10
10
|
p.rubyforge_name = p.name # TODO this is default value
|
11
11
|
p.extra_deps = [
|
12
12
|
['nkpart-prohax','>= 1.0.1']
|
@@ -14,7 +14,7 @@ $hoe = Hoe.new('accidentally', Accidentally::VERSION) do |p|
|
|
14
14
|
p.extra_dev_deps = [
|
15
15
|
['newgem', ">= #{::Newgem::VERSION}"]
|
16
16
|
]
|
17
|
-
|
17
|
+
|
18
18
|
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
19
19
|
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
20
20
|
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
data/accidentally.gemspec
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{accidentally}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["nkpart"]
|
9
|
-
s.date = %q{2008-11-
|
9
|
+
s.date = %q{2008-11-20}
|
10
10
|
s.description = %q{}
|
11
11
|
s.email = ["nkpart@gmail.com"]
|
12
12
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
|
13
|
-
s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "TODO", "accidentally.gemspec", "coverage/index.html", "coverage/lib-accidentally-mad_hax_rb.html", "coverage/lib-accidentally-method_invoker_rb.html", "coverage/lib-accidentally-patches-kernel_rb.html", "coverage/lib-accidentally-patches-thread_rb.html", "coverage/lib-accidentally_rb.html", "etc/examples.rb", "etc/textmate_command.rb", "lib/accidentally.rb", "lib/accidentally/mad_hax.rb", "lib/accidentally/method_invoker.rb", "lib/accidentally/patches/kernel.rb", "lib/accidentally/patches/thread.rb", "script/console", "script/destroy", "script/generate", "spec/accidentally_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake"]
|
13
|
+
s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "TODO", "accidentally.gemspec", "coverage/index.html", "coverage/lib-accidentally-invocation_result_rb.html", "coverage/lib-accidentally-mad_hax_rb.html", "coverage/lib-accidentally-method_invoker_rb.html", "coverage/lib-accidentally-patches-kernel_rb.html", "coverage/lib-accidentally-patches-thread_rb.html", "coverage/lib-accidentally_rb.html", "etc/examples.rb", "etc/textmate_command.rb", "lib/accidentally.rb", "lib/accidentally/invocation_result.rb", "lib/accidentally/mad_hax.rb", "lib/accidentally/method_invoker.rb", "lib/accidentally/patches/kernel.rb", "lib/accidentally/patches/thread.rb", "script/console", "script/destroy", "script/generate", "spec/accidentally_spec.rb", "spec/invocation_result_spec.rb", "spec/method_invoker_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://github.com/nkpart/accidentally}
|
16
|
-
s.post_install_message = %q{
|
16
|
+
s.post_install_message = %q{the whole thing?!}
|
17
17
|
s.rdoc_options = ["--main", "README.rdoc"]
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
s.rubyforge_project = %q{accidentally}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Accidentally
|
2
|
+
class InvocationResult
|
3
|
+
def initialize result, block_used = nil
|
4
|
+
@result= result
|
5
|
+
@block_used = block_used
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :result, :block_used
|
9
|
+
|
10
|
+
def == other
|
11
|
+
self.result == other.result && self.block_used == other.block_used
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/accidentally/mad_hax.rb
CHANGED
@@ -16,7 +16,11 @@ module Accidentally
|
|
16
16
|
:f => proc { |m| MethodInvoker.invoke(original, m, args, &blk) },
|
17
17
|
:candidates => proc { select_candidates(original.methods) }
|
18
18
|
).in {
|
19
|
-
candidates.
|
19
|
+
candidates.inject([]) { |acc, m|
|
20
|
+
v = f(m)
|
21
|
+
acc << "#{m}#{" " + v.block_used if v.block_used}" if v.result == target
|
22
|
+
acc
|
23
|
+
}
|
20
24
|
}
|
21
25
|
end
|
22
26
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'accidentally/patches/kernel'
|
2
2
|
require 'accidentally/patches/thread'
|
3
|
-
|
4
|
-
class InvocationResult < Strucked.build(:result, :block_used); end
|
3
|
+
require 'accidentally/invocation_result'
|
5
4
|
|
6
5
|
module Accidentally
|
7
6
|
class MethodInvoker
|
@@ -14,16 +13,19 @@ module Accidentally
|
|
14
13
|
end
|
15
14
|
|
16
15
|
def invoke meth, args, &blk
|
16
|
+
# TODO This look bad. Too many places where invocation results are getting built
|
17
|
+
# and failure happening.
|
17
18
|
v, warns = yield_and_collect_stderr {
|
18
|
-
|
19
|
-
if should_do_block_execute(
|
20
|
-
either { invoke_and_infer_block(meth, args) }
|
19
|
+
value, fail = either { do_send(meth, args, &blk) }
|
20
|
+
if should_do_block_execute(value, fail) then
|
21
|
+
r, fail = either { invoke_and_infer_block(meth, args) }
|
22
|
+
r || InvocationResult.new(fail)
|
21
23
|
else
|
22
|
-
|
24
|
+
InvocationResult.new(value)
|
23
25
|
end
|
24
26
|
}
|
25
|
-
# TODO handle the warns
|
26
|
-
v
|
27
|
+
# TODO handle the warns
|
28
|
+
v
|
27
29
|
end
|
28
30
|
|
29
31
|
private
|
@@ -47,8 +49,10 @@ module Accidentally
|
|
47
49
|
end
|
48
50
|
|
49
51
|
def invoke_and_infer_block m, args
|
50
|
-
|
51
|
-
|
52
|
+
proc_body = "{ |x| x }"
|
53
|
+
blk = eval "proc #{proc_body}"
|
54
|
+
v = do_send(m, args, &blk)
|
55
|
+
InvocationResult.new(v, proc_body)
|
52
56
|
end
|
53
57
|
end
|
54
58
|
end
|
data/lib/accidentally.rb
CHANGED
data/spec/accidentally_spec.rb
CHANGED
@@ -5,54 +5,42 @@ include Accidentally
|
|
5
5
|
describe Accidentally do
|
6
6
|
it "should figure out length of an array" do
|
7
7
|
methods = "dog".accidentally == 3
|
8
|
-
|
8
|
+
methods.should include("length")
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should figure out array reversal" do
|
12
12
|
methods = [1, 2].accidentally == [2, 1]
|
13
|
-
|
13
|
+
methods.should include("reverse")
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should figure out select" do
|
17
17
|
methods = [1, false, 2].accidentally == [1, 2]
|
18
|
-
|
18
|
+
methods.should include("select { |x| x }")
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should figure out index" do
|
22
22
|
methods = [:a, :b, :c].accidentally == :a
|
23
|
-
|
23
|
+
methods.should include("first")
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should be able to be guided by a parameter" do
|
27
27
|
methods = [:a, :b, :c].accidentally(:b) == 1
|
28
|
-
|
28
|
+
methods.should include("index")
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should be able to be guided by more than one parameter" do
|
32
32
|
methods = [:a, :b, :c, :d, :e].accidentally(1, 2) == [:b, :c]
|
33
|
-
|
33
|
+
methods.should include("slice")
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should be able to take a block suggestion" do
|
37
37
|
m = [1, 2, 3].accidentally{ |a, b| a + b } == 6
|
38
|
-
|
38
|
+
m.should include("inject")
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should not fail for fixnums" do
|
42
42
|
m = 1.accidentally == "1"
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe Accidentally::MethodInvoker do
|
48
|
-
it "should invoke a simple no args method" do
|
49
|
-
r = MethodInvoker.invoke [], :size, []
|
50
|
-
assert_equal 0, r
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should invoke a no args method that takes a block" do
|
54
|
-
r = MethodInvoker.invoke [1], :select, []
|
55
|
-
assert_equal [1], r
|
43
|
+
m.should include("to_s")
|
56
44
|
end
|
57
45
|
end
|
58
46
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
include Accidentally
|
4
|
+
|
5
|
+
describe InvocationResult do
|
6
|
+
it "should be equal to others" do
|
7
|
+
InvocationResult.new(5, "b").should_not ==(InvocationResult.new(5))
|
8
|
+
InvocationResult.new(3, "b").should_not ==(InvocationResult.new(5, "b"))
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
include Accidentally
|
3
|
+
|
4
|
+
describe Accidentally::MethodInvoker do
|
5
|
+
it "should invoke a simple no args method" do
|
6
|
+
r = MethodInvoker.invoke [], :size, []
|
7
|
+
r.should == InvocationResult.new(0, nil)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should invoke a no args method that takes a block" do
|
11
|
+
r = MethodInvoker.invoke [1], :select, []
|
12
|
+
r.should == InvocationResult.new([1], "{ |x| x }")
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nkpart-accidentally
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nkpart
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-11-
|
12
|
+
date: 2008-11-20 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- TODO
|
61
61
|
- accidentally.gemspec
|
62
62
|
- coverage/index.html
|
63
|
+
- coverage/lib-accidentally-invocation_result_rb.html
|
63
64
|
- coverage/lib-accidentally-mad_hax_rb.html
|
64
65
|
- coverage/lib-accidentally-method_invoker_rb.html
|
65
66
|
- coverage/lib-accidentally-patches-kernel_rb.html
|
@@ -68,6 +69,7 @@ files:
|
|
68
69
|
- etc/examples.rb
|
69
70
|
- etc/textmate_command.rb
|
70
71
|
- lib/accidentally.rb
|
72
|
+
- lib/accidentally/invocation_result.rb
|
71
73
|
- lib/accidentally/mad_hax.rb
|
72
74
|
- lib/accidentally/method_invoker.rb
|
73
75
|
- lib/accidentally/patches/kernel.rb
|
@@ -76,12 +78,14 @@ files:
|
|
76
78
|
- script/destroy
|
77
79
|
- script/generate
|
78
80
|
- spec/accidentally_spec.rb
|
81
|
+
- spec/invocation_result_spec.rb
|
82
|
+
- spec/method_invoker_spec.rb
|
79
83
|
- spec/spec.opts
|
80
84
|
- spec/spec_helper.rb
|
81
85
|
- tasks/rspec.rake
|
82
86
|
has_rdoc: true
|
83
87
|
homepage: http://github.com/nkpart/accidentally
|
84
|
-
post_install_message:
|
88
|
+
post_install_message: the whole thing?!
|
85
89
|
rdoc_options:
|
86
90
|
- --main
|
87
91
|
- README.rdoc
|