mthdspool 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.9.3
3
+
4
+ script: "rake"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mthdspool.gemspec
4
+ gemspec
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 [![Build Status](https://secure.travis-ci.org/jpablobr/mthdspool.png?branch=master)][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
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Stdout/stderr should not buffer output
4
+ $stdout.sync = true
5
+ $stderr.sync = true
6
+
7
+ require_relative '../lib/mthdspool'
8
+
9
+ MthdsPool::CLI.new.parse_options(ARGV)
data/lib/mthdspool.rb ADDED
@@ -0,0 +1,5 @@
1
+ module MthdsPool
2
+ require_relative "./mthdspool/version"
3
+ require_relative "./mthdspool/cli"
4
+ require_relative "./mthdspool/mthds"
5
+ end
@@ -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
@@ -0,0 +1,3 @@
1
+ module MthdsPool
2
+ VERSION = "0.1.0"
3
+ 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
@@ -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: