devel-which 0.3.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.
@@ -0,0 +1,58 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.co.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the GPL
3
+ (see COPYING.txt file), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) rename any non-standard executables so the names do not conflict
21
+ with standard executables, which must also be provided.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or executable
26
+ form, provided that you do at least ONE of the following:
27
+
28
+ a) distribute the executables and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard executables non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under this terms.
43
+
44
+ They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
45
+ files under the ./missing directory. See each file for the copying
46
+ condition.
47
+
48
+ 5. The scripts and library files supplied as input to or produced as
49
+ output from the software do not automatically fall under the
50
+ copyright of the software, but belong to whomever generated them,
51
+ and may be sold commercially, and may be aggregated with this
52
+ software.
53
+
54
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55
+ IMPLIED WARRANTIES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K\%W%m%0%i%`$r%5%]!<%H(B
51
+ $B$9$k0U;V$O$"$j$^$9$,!$%W%m%0%i%`<+?H$N%P%0$"$k$$$OK\%W(B
52
+ $B%m%0%i%`$N<B9T$J$I$+$iH/@8$9$k$$$+$J$kB;32$KBP$7$F$b@U(B
53
+ $BG$$r;}$A$^$;$s!%(B
@@ -0,0 +1,99 @@
1
+
2
+ # module Devel::Which
3
+
4
+ **Devel::Which - locate a symbol/library in the user's namespace/path**
5
+
6
+ Forked from http://raa.ruby-lang.org/project/devel-which/
7
+
8
+ ## SYNOPSIS
9
+
10
+ require 'devel/which'
11
+
12
+ File.which_constant("TRUNC") #=> File::Constants
13
+ Fixnum.which_method("nonzero?") #=> Numeric
14
+ which_library("net/http") #=> (the path where the net/http exists)
15
+ whereis_library("forwardable") #=> [(path, ... )]
16
+
17
+
18
+ ## DESCRIPTION
19
+
20
+ Devel::Which provides an effective definition finder, for example,
21
+ Fixnum#nonzero? is defined at Numeric and
22
+ Fixnum.which_method("nonzero?") returns Numeric.
23
+
24
+ ## Constants
25
+
26
+ Devel::Which::VERSION
27
+
28
+ Stands for the version of Devel::Which.
29
+
30
+ ## Methods
31
+
32
+ Module::which_constant(name)
33
+
34
+ Returns Devel::Which::ForModule::which_constant(self, name). This
35
+ method is defined in devel/which.
36
+
37
+ Module::which_method(name)
38
+
39
+ Returns Devel::Which::ForClass::which_method(self, name). This method
40
+ is defined in devel/which.
41
+
42
+ Object::which_library(name)
43
+
44
+ Returns Devel::Which::ForObject::which_library(name). This method is
45
+ defined in devel/which.
46
+
47
+ Returns Devel::Which::ForObject::whereis_library(name). This method is
48
+ defined in devel/which.
49
+
50
+ Devel::Which::ForModule::which_constant(mod, name)
51
+
52
+ Returns a Module where the constant name is defined. This method is
53
+ defined in devel/which/formodule.
54
+
55
+ Devel::Which::ForModule::which_method(mod, name)
56
+
57
+ Returns a Class where the method name is defined. This method is
58
+ defined in devel/which/formodule.
59
+
60
+ Devel::Which::ForObject::which_library(name)
61
+
62
+ Returns a file name where the library name exists. This method is
63
+ defined in devel/which/forobject.
64
+
65
+ Devel::Which::ForObject::whereis_library(name)
66
+
67
+ Returns an Array consists of file names where the library name exists.
68
+ This method is defined in devel/which/forobject.
69
+
70
+ ## AUTHORS
71
+
72
+ ### FORK
73
+
74
+ mori_dev <mori.dev.asdf at gmail dot com>
75
+
76
+ ### ORIGINAL
77
+
78
+ GOTO Kentaro aka Gotoken <gotoken at notwork dot org>
79
+
80
+ ## HISTORY
81
+
82
+ ### FORK
83
+
84
+ 2012-02-25: VERSION 0.3.0 - added gem, gemspec, Rakefile.
85
+
86
+ ### ORIGINAL
87
+
88
+ 2002-02-02: VERSION 0.2.0 - which_method moved to
89
+ Devel::Which::ForModule.
90
+
91
+ 2002-01-15: VERSION 0.1.1 - added whereis_library (inspired by eban).
92
+
93
+ 2002-01-13: VERSION 0.1.0
94
+
95
+
96
+ ## LICENSE
97
+
98
+ Ruby's License
99
+ See LICENSE/* for details.
@@ -0,0 +1,33 @@
1
+ require "rake"
2
+ require "rake/clean"
3
+ require "pathname"
4
+
5
+
6
+ task :default do
7
+ sh "rake -T"
8
+ end
9
+
10
+ CLEAN.include "devel-which-*.gem"
11
+
12
+
13
+ namespace :gem do
14
+
15
+ desc "build devel-which gem"
16
+ task :build do
17
+ sh "rake clean && gem build devel-which.gemspec"
18
+ end
19
+
20
+ desc "run gem install on the built gem"
21
+ task :install => :build do
22
+ sh "gem install devel-which*.gem"
23
+ end
24
+
25
+ desc "push devel-which.gem to RubyGems"
26
+ task :release do
27
+ if Pathname.new("~/.gem/credentials").expand_path.exist?
28
+ sh "gem push devel-which*.gem"
29
+ else
30
+ raise "Your rubygems.org credentials aren't set. Run `gem push` to set them."
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "devel/which"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "devel-which"
6
+ s.version = Devel::Which::VERSION
7
+ s.authors = ["GOTO Kentaro aka Gotoken, mori_dev"]
8
+ s.email = ["mori.dev.asdf@gmail.com"]
9
+ s.homepage = "https://github.com/wakaran/devel-which"
10
+ s.summary = %q{Devel::Which - locate a symbol/library in the users namespace/path}
11
+ s.description = <<-EOS
12
+ Devel::Which provides an effective definition finder, for example,
13
+ Fixnum#nonzero? is defined at Numeric and
14
+ Fixnum.which_method("nonzero?") returns Numeric.
15
+ EOS
16
+ s.files = [
17
+ "devel-which.gemspec",
18
+ "lib/devel/which",
19
+ "lib/devel/which/forclass.rb",
20
+ "lib/devel/which/forobject.rb",
21
+ "lib/devel/which/libwhich.rb",
22
+ "lib/devel/which/formodule.rb",
23
+ "lib/devel/which.rb",
24
+ "LICENSE/license_ja.txt",
25
+ "LICENSE/license_en.txt",
26
+ "README.md",
27
+ "Rakefile"
28
+ ]
29
+
30
+ s.require_paths = ["lib"]
31
+
32
+ end
@@ -0,0 +1,97 @@
1
+ #! /usr/local/bin/ruby
2
+ # $kNotwork: which.rb,v 1.3 2002/02/08 19:52:57 gotoken Exp $
3
+
4
+ require "devel/which/forobject"
5
+ require "devel/which/formodule"
6
+
7
+ module Devel
8
+ module Which
9
+ VERSION = "0.3.0"
10
+ end
11
+ end
12
+
13
+ class Object
14
+ def which_library(name)
15
+ Devel::Which::ForObject::which_library(name)
16
+ end
17
+
18
+ def whereis_library(name)
19
+ Devel::Which::ForObject::whereis_library(name)
20
+ end
21
+ end
22
+
23
+ class Module
24
+ def which_constant(name)
25
+ Devel::Which::ForModule::which_constant(self, name)
26
+ end
27
+
28
+ def which_method(name)
29
+ Devel::Which::ForModule::which_method(self, name)
30
+ end
31
+ end
32
+
33
+ if __FILE__ == $0
34
+ def show(str = nil, hidden = nil)
35
+ if str
36
+ print("#{str.ljust(25)}")
37
+ val = eval(str)
38
+ puts(hidden ? "" : " #=> #{val.inspect}" )
39
+ else
40
+ puts("")
41
+ end
42
+ end
43
+
44
+ show %{Fixnum.which_method :nonzero?} #=> Numeric
45
+ show %{Fixnum.which_method :integer?} #=> Integer
46
+ show %{Fixnum.which_method :zero?} #=> Fixnum
47
+ show %{Array.which_method :sort} #=> Array
48
+ show %{Array.which_method :find} #=> Enumerable
49
+ show
50
+ show %{File::Constants.which_constant("IO")} #=> Object
51
+ show %{File::Constants.which_constant("Constants")} #=> File
52
+ show %{File::Constants.which_constant("TRUNC")} #=> File::Constants
53
+ show %{
54
+ module M0
55
+ X = 0
56
+ Z = 0
57
+ end
58
+
59
+ module M1
60
+ X = 1
61
+ Y = "1"
62
+
63
+ module C
64
+ Y = "1"
65
+ end
66
+ end
67
+
68
+ module M2
69
+ include M0
70
+ Z = 0
71
+ end
72
+
73
+ module A
74
+ X = nil
75
+
76
+ module B
77
+ include M1
78
+
79
+ module C
80
+ include M2
81
+ end
82
+ end
83
+ end}, true
84
+ show
85
+ show %{A::B::C.which_constant("X")} #=> A
86
+ show %{A::B::C.which_constant("Y")} #=> nil
87
+ show %{A::B::C.which_constant("Z")} #=> M0
88
+ show
89
+ show %{which_library "xmp"}
90
+ show %{which_library "irb"}
91
+ show %{which_library "irb/xmp"}
92
+ show %{which_library "nkf"}
93
+ show %{which_library "which.rb"}
94
+ show
95
+ show %{whereis_library "uri"}
96
+ show %{whereis_library "tk"}
97
+ end
@@ -0,0 +1,9 @@
1
+ require "devel/which/formodule"
2
+ require "devel/which/libwhich"
3
+
4
+ module Devel
5
+ module Which
6
+ module ForClass
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,47 @@
1
+ require "devel/which/libwhich"
2
+
3
+ module Devel
4
+ module Which
5
+ module ForModule
6
+
7
+ def which_constant(mod, name)
8
+
9
+ name = Devel::Which::name2string(name)
10
+ nest = []
11
+ pos = 0
12
+ space = mod.name
13
+
14
+ begin
15
+ pos -= 1
16
+ space = space[0..pos]
17
+ nest.push(space)
18
+ end while pos = space.rindex(/::/)
19
+
20
+ nest.map!{|i| eval "::#{i}"}
21
+ mod.ancestors.each{|i| nest.push i}
22
+ a = (class << self; self; end).ancestors.each{|i| nest.push i}
23
+ cand = nest.find_all{|m| m.const_defined? name}
24
+ last = cand.shift
25
+ return nil if not last
26
+ value = last.const_get(name)
27
+
28
+ while car = cand.shift
29
+ break if value != car.const_get(name)
30
+ last = car
31
+ end
32
+
33
+ last
34
+ end
35
+ module_function :which_constant
36
+
37
+ def which_method(mod, name)
38
+ name = Devel::Which::name2string(name)
39
+ mod.ancestors.find{|a|
40
+ a.instance_methods.include?(name)
41
+ }
42
+ end
43
+ module_function :which_method
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,72 @@
1
+ require "rbconfig"
2
+
3
+ module Devel
4
+ module Which
5
+ module ForObject
6
+ def which_library(lib)
7
+ unless lib.is_a? String
8
+ raise TypeError,
9
+ "wrong argument type #{lib.type} (expected String)"
10
+ end
11
+ ext = ["rb", Config::CONFIG["DLEXT"], Config::CONFIG["DLEXT2"]]
12
+ ext.map!{|i| i.length > 0 ? ".#{i}" : nil}
13
+ ext.compact!
14
+ ext.push("")
15
+
16
+ at = with = nil
17
+ at = $:.find{|path|
18
+ file = "#{File::expand_path(path)}/#{lib}"
19
+
20
+ begin
21
+ with = ext.find{|i|
22
+ test(?f, file+i) && test(?r, file+i)
23
+ }
24
+ rescue
25
+ next
26
+ end
27
+ }
28
+
29
+ "#{at}/#{lib}#{with}" if at
30
+ end
31
+ module_function :which_library
32
+
33
+ def whereis_library(lib, opt = {})
34
+ unless lib.is_a? String
35
+ raise TypeError,
36
+ "wrong argument type #{lib.type} (expected String)"
37
+ end
38
+ unless opt.is_a? Hash
39
+ raise TypeError,
40
+ "wrong argument type #{lib.type} (expected Hash)"
41
+ end
42
+ optpath = opt[:path] || opt[:p] || []
43
+ optext = opt[:ext] || opt[:e] || ""
44
+ ext = ["rb", Config::CONFIG["DLEXT"], Config::CONFIG["DLEXT2"], optext]
45
+ ext.map!{|i| i.length > 0 ? ".#{i}" : nil}
46
+ ext.compact!
47
+ ext.push("")
48
+
49
+ at = []
50
+
51
+ ($: + optpath).each{|path|
52
+ with = nil
53
+ file = "#{File::expand_path(path)}/#{lib}"
54
+
55
+ begin
56
+ ext.each{|with|
57
+ if (test(?f, file+with) && test(?r, file+with) rescue false)
58
+ at << "#{path}/#{lib}#{with}"
59
+ end
60
+ }
61
+ rescue
62
+ next
63
+ end
64
+ }
65
+
66
+ at
67
+ end
68
+ module_function :whereis_library
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,14 @@
1
+ module Devel
2
+ module Which
3
+ def name2string(name)
4
+ name = name.id2name if name.is_a? Symbol
5
+ unless name.is_a? String
6
+ raise TypeError,
7
+ "wrong argument type #{name.type} (expected String or Symbol)"
8
+ else
9
+ name
10
+ end
11
+ end
12
+ module_function :name2string
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devel-which
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - GOTO Kentaro aka Gotoken, mori_dev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-10 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: ! " Devel::Which provides an effective definition finder, for example,\n
15
+ \ Fixnum#nonzero? is defined at Numeric and\n Fixnum.which_method(\"nonzero?\")
16
+ returns Numeric.\n"
17
+ email:
18
+ - mori.dev.asdf@gmail.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - devel-which.gemspec
24
+ - lib/devel/which/forclass.rb
25
+ - lib/devel/which/forobject.rb
26
+ - lib/devel/which/libwhich.rb
27
+ - lib/devel/which/formodule.rb
28
+ - lib/devel/which.rb
29
+ - LICENSE/license_ja.txt
30
+ - LICENSE/license_en.txt
31
+ - README.md
32
+ - Rakefile
33
+ homepage: https://github.com/wakaran/devel-which
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.13
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Devel::Which - locate a symbol/library in the users namespace/path
57
+ test_files: []