mthdspool 0.1.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/.gitignore +17 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +60 -0
- data/Rakefile +16 -0
- data/bin/mthdspool +9 -0
- data/lib/mthdspool.rb +5 -0
- data/lib/mthdspool/cli.rb +43 -0
- data/lib/mthdspool/mthds.rb +77 -0
- data/lib/mthdspool/version.rb +3 -0
- data/mthdspool.gemspec +17 -0
- data/test/mthdspool/test_mthds.rb +27 -0
- data/test/test_helper.rb +14 -0
- metadata +64 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 jpablobr
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Mthdspool [][travis]
|
2
|
+
|
3
|
+
[travis]: http://travis-ci.org/jpablobr/mthdspool
|
4
|
+
|
5
|
+
Lists Ruby objects methods from `ObjectSpace` and later on filters them with `#grep`.
|
6
|
+
|
7
|
+
## <a name="Installation"></a>Installation:
|
8
|
+
|
9
|
+
For specific Ruby version requirements, see the [Travis build](http://travis-ci.org/#!/jpablobr/mthdspool). ATM > 1.9.
|
10
|
+
|
11
|
+
With RubyGems, simply open a terminal and type:
|
12
|
+
|
13
|
+
$ {sudo} gem install mthdspool
|
14
|
+
|
15
|
+
Local installation:
|
16
|
+
|
17
|
+
[Download](http://github.com/jpablobr/mthdspool/download) the tarball package and:
|
18
|
+
|
19
|
+
$ tar -xvzf mthdspool-{version}.tgz
|
20
|
+
|
21
|
+
or
|
22
|
+
|
23
|
+
$ git clone https://github.com/jpablobr/mthdspool.git
|
24
|
+
|
25
|
+
then
|
26
|
+
|
27
|
+
$ cd mthdspool-{version}
|
28
|
+
$ {sudo} rake install
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
Usage: mthdspool [-v] [-h] command [<args>]
|
33
|
+
|
34
|
+
-h, --help Print this help.
|
35
|
+
-v, --version Print version.
|
36
|
+
-l, --lib [library] Library path
|
37
|
+
-o, --object [object] Object to inspect
|
38
|
+
-i, --instance [intance] Instance to inspect
|
39
|
+
-f, --filter [filter] Object methods filter
|
40
|
+
|
41
|
+
> signifies inherited method.
|
42
|
+
< signifies object specific method.
|
43
|
+
|
44
|
+
Examples:
|
45
|
+
mthdspool -o String -l ~/code/app/lib/app -f methods
|
46
|
+
mthdspool -o String -f methods
|
47
|
+
mthdspool -i \$stderr -f methods
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create new Pull Request
|
56
|
+
|
57
|
+
## <a name="copyright"></a>Copyright
|
58
|
+
Copyright (c) 2012 Jose Pablo Barrantes. See [LICENSE][] for details.
|
59
|
+
|
60
|
+
[license]: https://github.com/jpablobr/mthdspool/blob/master/LICENSE
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
|
7
|
+
namespace :test do
|
8
|
+
Rake::TestTask.new do |t|
|
9
|
+
t.name = "minitest"
|
10
|
+
t.libs << "test"
|
11
|
+
t.test_files = FileList['test/mthdspool/test_*.rb', 'test/test_*.rb']
|
12
|
+
t.verbose = true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => "test:minitest"
|
data/bin/mthdspool
ADDED
data/lib/mthdspool.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module MthdsPool
|
2
|
+
class CLI
|
3
|
+
require 'optparse'
|
4
|
+
def parse_options argv
|
5
|
+
options={}
|
6
|
+
opts = OptionParser.new do |o|
|
7
|
+
o.banner = "Usage: mthdspool [-v] [-h] command [<args>]"
|
8
|
+
o.separator ""
|
9
|
+
o.on("-h", "--help", "Print this help.") {
|
10
|
+
$stderr.puts(opts)
|
11
|
+
}
|
12
|
+
o.on("-v", "--version", "Print version.") {
|
13
|
+
return $stderr.puts(VERSION)
|
14
|
+
}
|
15
|
+
o.on("-l", "--lib [library]", "Library path") { |l|
|
16
|
+
options[:lib] = l
|
17
|
+
}
|
18
|
+
o.on("-o", "--object [object]", "Object to inspect") { |o|
|
19
|
+
options[:obj] = o
|
20
|
+
}
|
21
|
+
o.on("-i", "--instance [intance]", "Instance to inspect") { |i|
|
22
|
+
options[:inst] = i
|
23
|
+
}
|
24
|
+
o.on("-f", "--filter [filter]", "Object methods filter") { |f|
|
25
|
+
options[:filter] = f
|
26
|
+
}
|
27
|
+
o.separator ""
|
28
|
+
o.separator "> signifies inherited method."
|
29
|
+
o.separator "< signifies object specific method."
|
30
|
+
o.separator ""
|
31
|
+
o.separator "Examples:"
|
32
|
+
o.separator "mthdspool -o String -l ~/code/app/lib/app -f methods"
|
33
|
+
o.separator "mthdspool -o String -f methods"
|
34
|
+
o.separator "mthdspool -i \\$stderr -f methods"
|
35
|
+
end
|
36
|
+
$stderr.puts(opts) if argv.empty?
|
37
|
+
opts.parse!(argv) rescue return $stderr.puts(opts)
|
38
|
+
prnt = Mthds.new(options)
|
39
|
+
prnt.objects_methods if options.include?(:obj)
|
40
|
+
prnt.instance_objects_methods if options.include?(:inst)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module MthdsPool
|
2
|
+
class Mthds
|
3
|
+
attr_accessor :lib, :obj, :filter, :inst
|
4
|
+
|
5
|
+
def initialize opts={}
|
6
|
+
@lib = opts[:lib]
|
7
|
+
@obj = opts[:obj]
|
8
|
+
begin
|
9
|
+
@inst = eval("#{opts[:inst]}").class
|
10
|
+
rescue NameError => e
|
11
|
+
puts e.message
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
@filter = opts[:filter]
|
15
|
+
require_relative @lib unless @lib.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
def objects_methods
|
19
|
+
get_objects.each { |o| print_methods(o) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def instance_objects_methods
|
23
|
+
get_instace_objects.each { |o| print_methods(o) }
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def get_objects
|
29
|
+
ObjectSpace.each_object(Class).select { |obj|
|
30
|
+
obj.to_s.match(/#{@obj}/) ? obj.to_s.gsub(/#{@obj}/, '') : nil
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
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
|
+
def print_methods obj
|
41
|
+
if obj.respond_to?(:singleton_methods)
|
42
|
+
print_singleton_methods(obj)
|
43
|
+
print_all_singleton_methods(obj)
|
44
|
+
end
|
45
|
+
if obj.respond_to?(:instance_methods)
|
46
|
+
print_instance_methods(obj)
|
47
|
+
print_all_instance_methods(obj)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def print_all_singleton_methods obj
|
52
|
+
mthds = obj.singleton_methods - (obj.instance_methods - Object.new.methods)
|
53
|
+
mthds.grep(/#{@filter}/).each { |m|
|
54
|
+
puts ">SM " + obj.name + "#" + m.to_s
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def print_all_instance_methods obj
|
59
|
+
mthds = obj.instance_methods - (obj.instance_methods - Object.new.methods)
|
60
|
+
mthds.grep(/#{@filter}/).each { |m|
|
61
|
+
puts ">IM " + obj.name + "#" + m.to_s
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def print_singleton_methods obj
|
66
|
+
(obj.singleton_methods - Object.new.methods).grep(/#{@filter}/).each { |m|
|
67
|
+
puts "<SM " + obj.name + "#" + m.to_s
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def print_instance_methods obj
|
72
|
+
(obj.instance_methods - Object.new.methods).grep(/#{@filter}/).each { |m|
|
73
|
+
puts "<IM " + obj.name + "#" + m.to_s
|
74
|
+
}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/mthdspool.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/mthdspool/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["jpablobr"]
|
6
|
+
gem.email = ["xjpablobrx@gmail.com"]
|
7
|
+
gem.description = %q{Lists Ruby objects methods by searching them in ObjectSpace and filtering them with grep.}
|
8
|
+
gem.summary = %q{Lists Ruby objects methods.}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "mthdspool"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = MthdsPool::VERSION
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
module MthdsPool
|
5
|
+
class CLITest < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
def test_instance_object_should_receive_valid_constants
|
8
|
+
assert_raises(NameError) {
|
9
|
+
Mthds.new({inst: KDFGJ})
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_print_instance_object
|
14
|
+
print = Mthds.new({inst: ARGV, filter: 'try_convert'})
|
15
|
+
assert_output("<SM Array#try_convert\n>SM Array#try_convert\n") {
|
16
|
+
print.instance_objects_methods
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_print_object
|
21
|
+
print = Mthds.new({obj: 'Sring', filter: 'singleton_methods'})
|
22
|
+
assert_output(">IM NilClass#singleton_methods\n") {
|
23
|
+
print.instance_objects_methods
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
if RUBY_VERSION < "1.9"
|
3
|
+
require 'test/unit'
|
4
|
+
else
|
5
|
+
require 'test/unit'
|
6
|
+
require 'minitest/unit'
|
7
|
+
end
|
8
|
+
|
9
|
+
$TEST = true
|
10
|
+
|
11
|
+
lib_dir = File.join(File.dirname(__FILE__), '..', 'lib')
|
12
|
+
$LOAD_PATH.unshift lib_dir, File.dirname(__FILE__)
|
13
|
+
|
14
|
+
require 'mthdspool'
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mthdspool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- jpablobr
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-05 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Lists Ruby objects methods by searching them in ObjectSpace and filtering
|
15
|
+
them with grep.
|
16
|
+
email:
|
17
|
+
- xjpablobrx@gmail.com
|
18
|
+
executables:
|
19
|
+
- mthdspool
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- .gitignore
|
24
|
+
- .travis.yml
|
25
|
+
- Gemfile
|
26
|
+
- LICENSE
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- bin/mthdspool
|
30
|
+
- lib/mthdspool.rb
|
31
|
+
- lib/mthdspool/cli.rb
|
32
|
+
- lib/mthdspool/mthds.rb
|
33
|
+
- lib/mthdspool/version.rb
|
34
|
+
- mthdspool.gemspec
|
35
|
+
- test/mthdspool/test_mthds.rb
|
36
|
+
- test/test_helper.rb
|
37
|
+
homepage: ''
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.8.10
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Lists Ruby objects methods.
|
61
|
+
test_files:
|
62
|
+
- test/mthdspool/test_mthds.rb
|
63
|
+
- test/test_helper.rb
|
64
|
+
has_rdoc:
|