mthdspool 0.1.0 → 0.1.1

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.
@@ -6,4 +6,5 @@ $stderr.sync = true
6
6
 
7
7
  require_relative '../lib/mthdspool'
8
8
 
9
+ ARGV << '--help' if ARGV.empty?
9
10
  MthdsPool::CLI.new.parse_options(ARGV)
@@ -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", "--lib [library]", "Library path") { |l|
16
- options[:lib] = l
15
+ o.on("-l", "--library [library]", "Library path") { |l|
16
+ options[:libs] = l
17
17
  }
18
- o.on("-o", "--object [object]", "Object to inspect") { |o|
19
- options[:obj] = o
18
+ o.on("-r", "--require [require]", "Require path") { |r|
19
+ options[:reqr] = r
20
20
  }
21
- o.on("-i", "--instance [intance]", "Instance to inspect") { |i|
22
- options[:inst] = i
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 "> signifies inherited method."
29
- o.separator "< signifies object specific method."
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 -i \\$stderr -f methods"
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
- prnt.objects_methods if options.include?(:obj)
40
- prnt.instance_objects_methods if options.include?(:inst)
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
@@ -1,26 +1,28 @@
1
1
  module MthdsPool
2
2
  class Mthds
3
- attr_accessor :lib, :obj, :filter, :inst
3
+ attr_accessor :libs, :obj, :filter, :reqr, :nspct, :gemfile
4
4
 
5
5
  def initialize opts={}
6
- @lib = opts[:lib]
7
- @obj = opts[:obj]
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
- @inst = eval("#{opts[:inst]}").class
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 instance_objects_methods
23
- get_instace_objects.each { |o| print_methods(o) }
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
@@ -1,3 +1,3 @@
1
1
  module MthdsPool
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require 'test_helper'
3
+ require 'minitest/autorun'
3
4
 
4
5
  module MthdsPool
5
6
  class CLITest < MiniTest::Unit::TestCase
@@ -1,11 +1,4 @@
1
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
2
  $TEST = true
10
3
 
11
4
  lib_dir = File.join(File.dirname(__FILE__), '..', 'lib')
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.0
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-05 00:00:00.000000000 Z
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.10
57
+ rubygems_version: 1.8.17
58
58
  signing_key:
59
59
  specification_version: 3
60
60
  summary: Lists Ruby objects methods.