bananas 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45592ce4ca7ba5cd1be46e2c59f778af34d3aa9b
4
- data.tar.gz: 70d2bf4ef9cd0f23019bae0fa436ab8d7ee6070c
3
+ metadata.gz: 33b1a9a6463cca250a15f3450ce46ca9de278b32
4
+ data.tar.gz: 46f6b7cf2952b44d765da830a4802d80cdc6dba1
5
5
  SHA512:
6
- metadata.gz: 90cba2100ef61a62f784b27a4243d3f410795c57bfb3c88fdfe5cb14e21a874fd8d5bd560908a70640810eff5c8347c9ba6f3c7e5ccef93b069ba30c3399d004
7
- data.tar.gz: e6a8904c97c7ff87d60202f9e10f5376ae80ecd5e8a39b89a0f1ce0dd8b9f547c810baa0d20c81d76d1d26eb75c6a5746989214afaedac4b7d8df9011de0d97a
6
+ metadata.gz: b9f5e8a24b184d811665dd869d06e75f91202990ab0e4b25c77f6c7108add73af395f8e567cf9d0914fe26aa22be53aba79236ae65a95bf29d243d80f126e5be
7
+ data.tar.gz: fc1b2e08ad5ecadfe6b480d58996ff32f01edaa8466569fe4246d59e8ff9e5abb5cdb3fded16938419cd1c8effb36624d49de0aced96fed05e7968149cdd3370
@@ -6,44 +6,39 @@ ARGV << "-h" if ARGV.empty?
6
6
 
7
7
  options = {}
8
8
  o = OptionParser.new do |opts|
9
- opts.banner = "usage: bananas.rb [options]"
9
+ opts.banner = "usage: bananas.rb [options]"
10
+ options[:module] = "Object"
11
+ options[:with] = []
10
12
 
11
13
  opts.on("-m", "--module [MOD]", "The module to search for monkey patches. Required.") do |m|
12
14
  options[:module] = m.capitalize
15
+ Object.const_defined? options[:module] or raise TypeError
13
16
  end
14
17
 
15
18
  opts.on("-r", "--require X,Y,Z", "The list of dependencies to search with.") do |r|
16
- options[:with] = Array( String(r).split(",") )
19
+ options[:with].concat String(r).split(",")
20
+ options[:with].each {|r| require r }
17
21
  end
18
22
 
19
23
  opts.on("-h", "--help", "Print this message.") do |h|
20
24
  puts opts
21
25
  exit
22
26
  end
23
- end
24
-
25
- begin
26
- o.parse!
27
- rescue
28
- puts o
29
- exit
30
- end
31
27
 
32
- if options[:module].nil?
33
- puts o
34
- exit
28
+ opts.on("-v", "--version", "Print version information.") do |v|
29
+ puts Bananas::VERSION
30
+ exit
31
+ end
35
32
  end
36
33
 
37
34
  begin
38
- options[:with].each {|r| require r } if options[:with]
35
+ o.parse!
36
+ fail unless o.default_argv.empty?
37
+ Bananas.monkey_patches(Object.const_get options[:module])
39
38
  rescue LoadError
40
39
  puts "fatal: Couldn't require dependencies. '#{options[:with].join}'"
41
- exit
42
- end
43
-
44
- if Kernel.const_defined?(options[:module])
45
- Bananas.monkey_patches(Kernel.const_get options[:module].capitalize)
46
- else
40
+ rescue TypeError
47
41
  puts "fatal: Couldn't find a module. '#{options[:module]}'"
48
- exit
42
+ rescue
43
+ puts o
49
44
  end
@@ -1,7 +1,7 @@
1
1
  require "bananas/version"
2
2
 
3
3
  module Bananas
4
- GEMS = `gem list`
4
+ GEMS = Gem::Specification.to_a.map(&:name).join
5
5
  private_constant :GEMS
6
6
 
7
7
  module_function def monkey_patches(mod = Object)
@@ -10,8 +10,8 @@ module Bananas
10
10
  .keep_if {|c| c.respond_to?(:instance_methods) }
11
11
  .map {|c| Hash[object: c, methods: c.instance_methods(false)
12
12
  .map {|m| Hash[name: m, location: (Array(c.instance_method(m).source_location).first || next)] }.compact] }
13
- .map {|h| h[:methods].keep_if {|m| m[:location].match(ENV["GEM_HOME"]) }; h }
14
- .map {|h| h[:methods].reject! {|m| GEMS.match(/#{h[:object].instance_method(m[:name]).owner.to_s.split("::").first}/i)}; h }
13
+ .map {|h| h[:methods].keep_if {|m| m[:location].include? ENV["GEM_HOME"] }; h }
14
+ .map {|h| h[:methods].reject! {|m| GEMS.include? h[:object].instance_method(m[:name]).owner.to_s.downcase.split("::").first}; h }
15
15
  .reject {|h| h[:methods].empty? }
16
16
  .tap {|c| puts "Couldn't find any monkey patches for module '#{mod}'" if c.empty?}
17
17
  .each {|c| puts "%{object}:" % c; c[:methods].each {|m| puts "\t%-20{name} %{location}" % m }; putc "\n" }
@@ -1,3 +1,3 @@
1
1
  module Bananas
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bananas
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nitroo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-07 00:00:00.000000000 Z
11
+ date: 2015-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler