mthdspool 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/mthdspool +1 -0
- data/lib/mthdspool/cli.rb +19 -12
- data/lib/mthdspool/mthds.rb +30 -14
- data/lib/mthdspool/version.rb +1 -1
- data/test/mthdspool/test_mthds.rb +1 -0
- data/test/test_helper.rb +0 -7
- metadata +3 -3
data/bin/mthdspool
CHANGED
data/lib/mthdspool/cli.rb
CHANGED
@@ -12,32 +12,39 @@ module MthdsPool
|
|
12
12
|
o.on("-v", "--version", "Print version.") {
|
13
13
|
return $stderr.puts(VERSION)
|
14
14
|
}
|
15
|
-
o.on("-l", "--
|
16
|
-
options[:
|
15
|
+
o.on("-l", "--library [library]", "Library path") { |l|
|
16
|
+
options[:libs] = l
|
17
17
|
}
|
18
|
-
o.on("-
|
19
|
-
options[:
|
18
|
+
o.on("-r", "--require [require]", "Require path") { |r|
|
19
|
+
options[:reqr] = r
|
20
20
|
}
|
21
|
-
o.on("-
|
22
|
-
options[:
|
21
|
+
o.on("-g", "--gemfile [gemfile]", "Gemfile") { |g|
|
22
|
+
options[:gemfile] = g
|
23
|
+
}
|
24
|
+
o.on("-i", "--inspect [inspect]", "Instance to inspect") { |i|
|
25
|
+
options[:nspct] = i
|
23
26
|
}
|
24
27
|
o.on("-f", "--filter [filter]", "Object methods filter") { |f|
|
25
28
|
options[:filter] = f
|
26
29
|
}
|
27
30
|
o.separator ""
|
28
|
-
o.separator ">
|
29
|
-
o.separator "<
|
31
|
+
o.separator "> = inherited method."
|
32
|
+
o.separator "< = object specific method."
|
33
|
+
o.separator "IM = instance method."
|
34
|
+
o.separator "SM = Singleton method."
|
30
35
|
o.separator ""
|
31
36
|
o.separator "Examples:"
|
32
37
|
o.separator "mthdspool -o String -l ~/code/app/lib/app -f methods"
|
33
38
|
o.separator "mthdspool -o String -f methods"
|
34
|
-
o.separator "mthdspool -
|
39
|
+
o.separator "mthdspool -o \\$stderr -f methods"
|
40
|
+
o.separator "mthdspool -i CONST -r ~/code/app/lib/app/test/test_helper.rb"
|
35
41
|
end
|
36
|
-
$stderr.puts(opts) if argv.empty?
|
37
42
|
opts.parse!(argv) rescue return $stderr.puts(opts)
|
38
43
|
prnt = Mthds.new(options)
|
39
|
-
|
40
|
-
|
44
|
+
case
|
45
|
+
when options.has_key?(:obj); prnt.objects_methods
|
46
|
+
when options.has_key?(:nspct); prnt.inspect_instance
|
47
|
+
end
|
41
48
|
end
|
42
49
|
end
|
43
50
|
end
|
data/lib/mthdspool/mthds.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
module MthdsPool
|
2
2
|
class Mthds
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :libs, :obj, :filter, :reqr, :nspct, :gemfile
|
4
4
|
|
5
5
|
def initialize opts={}
|
6
|
-
@
|
7
|
-
@
|
6
|
+
@obj = opts[:obj]
|
7
|
+
@libs = opts[:libs]
|
8
|
+
@reqr = opts[:reqr]
|
9
|
+
@filter = opts[:filter]
|
10
|
+
@gemfile = opts[:gemfile]
|
11
|
+
setup
|
8
12
|
begin
|
9
|
-
@
|
13
|
+
@nspct = eval("#{opts[:nspct]}")
|
10
14
|
rescue NameError => e
|
11
15
|
puts e.message
|
12
16
|
exit 1
|
13
17
|
end
|
14
|
-
@filter = opts[:filter]
|
15
|
-
require_relative @lib unless @lib.nil?
|
16
18
|
end
|
17
19
|
|
18
20
|
def objects_methods
|
19
21
|
get_objects.each { |o| print_methods(o) }
|
20
22
|
end
|
21
23
|
|
22
|
-
def
|
23
|
-
|
24
|
+
def inspect_instance
|
25
|
+
puts @nspct.inspect
|
24
26
|
end
|
25
27
|
|
26
28
|
private
|
@@ -31,12 +33,6 @@ module MthdsPool
|
|
31
33
|
}
|
32
34
|
end
|
33
35
|
|
34
|
-
def get_instace_objects
|
35
|
-
ObjectSpace.each_object(Class).select { |obj|
|
36
|
-
obj.to_s.match(/#{@inst}/) ? obj.to_s.gsub(/#{@inst}/, '') : nil
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
36
|
def print_methods obj
|
41
37
|
if obj.respond_to?(:singleton_methods)
|
42
38
|
print_singleton_methods(obj)
|
@@ -73,5 +69,25 @@ module MthdsPool
|
|
73
69
|
puts "<IM " + obj.name + "#" + m.to_s
|
74
70
|
}
|
75
71
|
end
|
72
|
+
|
73
|
+
def setup
|
74
|
+
bundler_setup unless @gemfile.nil?
|
75
|
+
load_path_setup unless @libs.nil?
|
76
|
+
requires_setup unless @reqr.nil?
|
77
|
+
end
|
78
|
+
|
79
|
+
def bundler_setup
|
80
|
+
ENV['BUNDLE_GEMFILE'] = @gemfile
|
81
|
+
require 'rubygems'
|
82
|
+
require 'bundler/setup'
|
83
|
+
end
|
84
|
+
|
85
|
+
def load_path_setup
|
86
|
+
libs.split(":").each { |l| $LOAD_PATH.unshift(l) }
|
87
|
+
end
|
88
|
+
|
89
|
+
def requires_setup
|
90
|
+
reqr.split(":").each { |f| require f }
|
91
|
+
end
|
76
92
|
end
|
77
93
|
end
|
data/lib/mthdspool/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mthdspool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Lists Ruby objects methods by searching them in ObjectSpace and filtering
|
15
15
|
them with grep.
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
56
|
rubyforge_project:
|
57
|
-
rubygems_version: 1.8.
|
57
|
+
rubygems_version: 1.8.17
|
58
58
|
signing_key:
|
59
59
|
specification_version: 3
|
60
60
|
summary: Lists Ruby objects methods.
|