ori 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.
@@ -0,0 +1,118 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe "::ORI::ListMethod" do
4
+ klass = ::ORI::ListMethod
5
+
6
+ describe "#access" do
7
+ meth = :access
8
+
9
+ it "generally works" do
10
+ inputs = []
11
+ inputs << [{:obj => ::Sample::BasicInheritance::Son, :method_name => "grandpa_protected", :inspector => "protected_instance_methods"}, "#"]
12
+ inputs << [{:obj => ::Sample::BasicInheritance::Son, :method_name => "grandpa_protected_singleton", :inspector => "protected_methods"}, "::"]
13
+ inputs.each do |attrs, expected|
14
+ r = klass.new(attrs)
15
+ ##p "r", r
16
+ r.send(meth).should == expected
17
+ end
18
+ end
19
+ end
20
+
21
+ describe "#format" do
22
+ meth = :format
23
+
24
+ it "generally works" do
25
+ inputs = []
26
+ inputs << [{:obj => 5, :method_name => "%", :inspector => "public_methods"}, [/\bFixnum#%/]]
27
+ inputs << [{:obj => 5, :method_name => "between?", :inspector => "public_methods"}, [/\bFixnum\b/, /\bComparable\b/, /#between\?/]]
28
+ inputs << [{:obj => 5, :method_name => "puts", :inspector => "private_methods"}, [/\bFixnum\b/, /\bKernel\b/, /private/]]
29
+ inputs << [{:obj => nil, :method_name => "to_s", :inspector => "public_methods"}, [/\bNilClass#to_s/]]
30
+ inputs << [{:obj => Hash, :method_name => "<", :inspector => "public_methods"}, [/\bHash\b/, /\bModule\b/, /</]]
31
+ inputs << [{:obj => [], :method_name => "&", :inspector => "public_methods"}, [/\bArray#&/]]
32
+ inputs << [{:obj => Kernel, :method_name => "puts", :inspector => "public_methods"}, [/\bKernel::puts/]]
33
+ inputs << [{:obj => ::Sample::BasicExtension::OtherMo, :method_name => "public_meth", :inspector => "public_methods"}, [/\bSample::BasicExtension::OtherMo\b/, /\bSample::BasicExtension::Mo\b/, /::public_meth/]]
34
+ inputs << [{:obj => ::Sample::BasicExtension::OtherMo, :method_name => "protected_meth", :inspector => "protected_methods"}, [/\bSample::BasicExtension::OtherMo\b/, /\bSample::BasicExtension::Mo\b/, /::protected_meth/]]
35
+ inputs << [{:obj => ::Sample::BasicExtension::OtherMo, :method_name => "private_meth", :inspector => "private_methods"}, [/\bSample::BasicExtension::OtherMo\b/, /\bSample::BasicExtension::Mo\b/, /::private_meth/]]
36
+
37
+ inputs.each do |attrs, checks|
38
+ r = klass.new(attrs)
39
+ ##p "r", r
40
+ checks.each do |re|
41
+ ##p "re", re
42
+ r.send(meth, :color => false).should match re
43
+ end
44
+ end
45
+ end
46
+
47
+ it "supports colored and plain output" do
48
+ inputs = []
49
+ inputs << {:obj => 5, :method_name => "%", :inspector => "public_methods"}
50
+ inputs << {:obj => 5, :method_name => "between?", :inspector => "public_methods"}
51
+ inputs << {:obj => 5, :method_name => "puts", :inspector => "private_methods"}
52
+ inputs << {:obj => nil, :method_name => "to_s", :inspector => "public_methods"}
53
+ inputs << {:obj => Hash, :method_name => "<", :inspector => "public_methods"}
54
+ inputs << {:obj => [], :method_name => "&", :inspector => "public_methods"}
55
+ inputs << {:obj => Kernel, :method_name => "puts", :inspector => "public_methods"}
56
+
57
+ inputs.each do |attrs|
58
+ r = klass.new(attrs)
59
+ ##p "r", r
60
+ r.send(meth, :color => true).should match Regexp.new(Regexp.escape(attrs[:method_name]))
61
+ r.send(meth, :color => true).should match Regexp.new(Regexp.escape("\e"))
62
+ r.send(meth, :color => false).should match Regexp.new(Regexp.escape(attrs[:method_name]))
63
+ r.send(meth, :color => false).should_not match Regexp.new(Regexp.escape("\e"))
64
+ end
65
+ end
66
+ end # #format
67
+
68
+ describe "#own?" do
69
+ meth = :own?
70
+
71
+ it "generally works" do
72
+ inputs = []
73
+ inputs << [{:obj => 5, :method_name => "%", :inspector => "public_methods"}, true]
74
+ inputs << [{:obj => 5, :method_name => "between?", :inspector => "public_methods"}, false]
75
+ inputs << [{:obj => Kernel, :method_name => "puts", :inspector => "public_methods"}, true]
76
+ inputs << [{:obj => Kernel, :method_name => "dup", :inspector => "public_instance_methods"}, true]
77
+
78
+ inputs.each do |attrs, expected|
79
+ r = klass.new(attrs)
80
+ ##p "r", r
81
+ r.send(meth).should == expected
82
+ end
83
+ end
84
+ end # #own?
85
+
86
+ describe "#ri_topics" do
87
+ meth = :ri_topics
88
+
89
+ include HelperMethods
90
+
91
+ it "generally works" do
92
+ r = glm(5, "#is_a?")
93
+ r.ri_topics.should include ["Fixnum", "#", "is_a?"]
94
+ r.ri_topics.should include ["Object", "#", "is_a?"]
95
+
96
+ r = glm(Hash, "#[]")
97
+ r.ri_topics.should include ["Hash", "#", "[]"]
98
+
99
+ r = glm(Sample::BasicInheritance::Son, "grandpa_public")
100
+ r.ri_topics.should include ["Sample::BasicInheritance::Son", "#", "grandpa_public"]
101
+ r.ri_topics.should include ["Sample::BasicInheritance::Grandpa", "#", "grandpa_public"]
102
+
103
+ r = glm(Sample::BasicInheritance::Son, "grandpa_public_singleton")
104
+ r.ri_topics.should include ["Sample::BasicInheritance::Son", "::", "grandpa_public_singleton"]
105
+ r.ri_topics.should include ["Sample::BasicInheritance::Papa", "::", "grandpa_public_singleton"]
106
+ r.ri_topics.should include ["Sample::BasicInheritance::Grandpa", "::", "grandpa_public_singleton"]
107
+
108
+ r = glm(Sample::BasicExtension::Klass, "public_meth")
109
+ r.ri_topics.should include ["Sample::BasicExtension::Klass", "::", "public_meth"]
110
+ r.ri_topics.should include ["Sample::BasicExtension::Mo", "#", "public_meth"]
111
+ end
112
+
113
+ it "does not contain duplicates" do
114
+ r = glm(Module, "#public")
115
+ r.ri_topics.should == r.ri_topics.uniq
116
+ end
117
+ end # #ri_topics
118
+ end
@@ -0,0 +1,72 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe "::ORI::Request" do
4
+ klass = ::ORI::Request
5
+
6
+ it "generally works" do
7
+ # NOTE: Order is: self, method, list, error. Thinnest first, fattest last. Then errors.
8
+
9
+ r = klass.parse()
10
+ r.self?.should == true
11
+ r.glm_options[:objs].should == []
12
+
13
+ ###
14
+
15
+ r = klass.parse(:puts)
16
+ r.method?.should == true
17
+ r.glm_options[:all].should == true
18
+ "puts".should match r.glm_options[:re]
19
+ ##p "r.glm_options", r.glm_options
20
+
21
+ r = klass.parse("#puts")
22
+ r.method?.should == true
23
+ r.glm_options[:all].should == true
24
+ "puts".should match r.glm_options[:re]
25
+ r.glm_options[:access].should == "#"
26
+
27
+ r = klass.parse("::puts")
28
+ r.method?.should == true
29
+ r.glm_options[:all].should == true
30
+ "puts".should match r.glm_options[:re]
31
+ r.glm_options[:access].should == "::"
32
+
33
+ ###
34
+
35
+ r = klass.parse(/kk/)
36
+ r.list?.should == true
37
+ r.glm_options[:objs].should == []
38
+ r.glm_options[:re].should == /kk/
39
+
40
+ r = klass.parse(/kk/, :all, :own)
41
+ r.glm_options[:all].should == true
42
+ r.glm_options[:own].should == true
43
+ r.glm_options[:objs].should == []
44
+ r.glm_options[:re].should == /kk/
45
+
46
+ ###
47
+
48
+ r = klass.parse(//, :join => 1)
49
+ r.list?.should == true
50
+ r.glm_options.should_not have_key(:join)
51
+ r.glm_options[:objs].should == [1]
52
+ r.glm_options[:re].should == //
53
+
54
+ r = klass.parse(//, :join => [1])
55
+ r.list?.should == true
56
+ r.glm_options.should_not have_key(:join)
57
+ r.glm_options[:objs].should == [1]
58
+ r.glm_options[:re].should == //
59
+
60
+ r = klass.parse(//, :join => [1, [2]])
61
+ r.list?.should == true
62
+ r.glm_options.should_not have_key(:join)
63
+ r.glm_options[:objs].should == [1, [2]]
64
+ r.glm_options[:re].should == //
65
+
66
+ ###
67
+
68
+ r = klass.parse(5678)
69
+ r.error?.should == true
70
+ r.message.should match /5678/
71
+ end
72
+ end
@@ -0,0 +1,3 @@
1
+ These specs depend on a particular OS, environment and setup.
2
+
3
+ They SHOULD pass, but if the setup is incorrect, they may fail.
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ require "rbconfig"
4
+
5
+ describe "ORI::Library" do
6
+ klass = ::ORI::Library
7
+
8
+ # NOTES:
9
+ # * We recreate object every time if we are not specifically testing caching.
10
+ # * We rely upon AutoConfig to detect OS settings.
11
+
12
+ autoconf = ::ORI::AutoConfig.new((k = "host_os") => RbConfig::CONFIG[k])
13
+ fresh = klass.new({
14
+ (k = :frontend) => autoconf.send(k),
15
+ (k = :shell_escape) => autoconf.send(k),
16
+ })
17
+ ##p "fresh", fresh
18
+
19
+ describe "#lookup" do
20
+ meth = :lookup
21
+
22
+ it "generally works" do
23
+ r = fresh.dup
24
+ r.lookup("Object#is_a?").should_not be_nil
25
+
26
+ r = fresh.dup
27
+ r.lookup("Object#is_kk?").should be_nil
28
+
29
+ r = fresh.dup
30
+ r.lookup("Object#kakamakaka").should be_nil
31
+ end
32
+ end
33
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), "../spec_helper")
@@ -0,0 +1,26 @@
1
+ # Library files.
2
+ require File.join(File.dirname(__FILE__), "../lib/ori")
3
+
4
+ # Samples.
5
+ Dir[File.join(File.dirname(__FILE__), "../samples/**/*.rb")].each {|fn| require fn}
6
+
7
+ module HelperMethods
8
+ # Quickly fetch ONE named ListMethod of <tt>obj</tt>.
9
+ #
10
+ # glm(Hash, "::[]")
11
+ # glm(Hash, "#[]")
12
+ def glm(obj, method_name)
13
+ req = ::ORI::Request.parse(method_name)
14
+ raise ArgumentError, "glm: Not a method request" if not req.method?
15
+
16
+ req.glm_options[:objs].unshift(obj)
17
+ ar = ::ORI::Internals.get_list_methods(req.glm_options)
18
+ if ar.size < 1
19
+ raise "glm: No methods found"
20
+ elsif ar.size > 1
21
+ raise "glm: #{ar.size} methods found, please be more specific"
22
+ end
23
+
24
+ ar[0]
25
+ end
26
+ end
@@ -0,0 +1,109 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe "::ORI::Tools" do
4
+ mod = ::ORI::Tools
5
+
6
+ describe ".ansi" do
7
+ meth = :ansi
8
+
9
+ it "returns empty string if no attrs are given" do
10
+ mod.send(meth).should == ""
11
+ end
12
+
13
+ it "refuses to take unknown attributes" do
14
+ proc do
15
+ mod.send(meth, :kaka)
16
+ end.should raise_error(ArgumentError)
17
+ end
18
+
19
+ it "generally works" do
20
+ mod.send(meth, :red).should == "\e[31m"
21
+ mod.send(meth, :red, :on_green).should == "\e[31;42m"
22
+ end
23
+ end # .ansi
24
+
25
+ describe ".get_methods" do
26
+ meth = :get_methods
27
+
28
+ it "allows to fetch own methods only" do
29
+ ar = mod.send(meth, ::Sample::BasicInheritance::Son, :inspector_arg => false)
30
+ ##p "ar", ar
31
+ h = Hash[*ar.flatten(1)]
32
+ ##p "h", h
33
+
34
+ h["public_instance_methods"].should == ["son_public"]
35
+ h["protected_instance_methods"].should == ["son_protected"]
36
+ h["private_instance_methods"].should == ["son_private"]
37
+ h["public_methods"].should include("son_public_singleton", "papa_public_singleton", "grandpa_public_singleton")
38
+ h["protected_methods"].should include("son_protected_singleton", "papa_protected_singleton", "grandpa_protected_singleton")
39
+ h["private_methods"].should include("son_private_singleton", "papa_private_singleton", "grandpa_private_singleton")
40
+ end
41
+
42
+ it "supports MAV mode" do
43
+ ar = mod.send(meth, ::Sample::BasicInheritance::Son, :to_mav => true)
44
+ ##p "ar", ar
45
+ ar.should include(["son_public", "#", :public], ["son_protected", "#", :protected], ["son_private", "#", :private])
46
+ ar.should include(["son_public_singleton", "::", :public], ["son_protected_singleton", "::", :protected], ["son_private_singleton", "::", :private])
47
+ ar.should include(["papa_public", "#", :public], ["papa_protected", "#", :protected], ["papa_private", "#", :private])
48
+ ar.should include(["papa_public_singleton", "::", :public], ["papa_protected_singleton", "::", :protected], ["papa_private_singleton", "::", :private])
49
+
50
+ ar = mod.send(meth, ::Sample::BasicExtension::OtherMo, :to_mav => true)
51
+ ar.should include(["public_meth", "::", :public], ["protected_meth", "::", :protected], ["private_meth", "::", :private])
52
+
53
+ ar = mod.send(meth, ::Sample::BasicExtension::Klass, :to_mav => true)
54
+ ar.should include(["public_meth", "::", :public], ["protected_meth", "::", :protected], ["private_meth", "::", :private])
55
+ end
56
+ end # .get_methods
57
+
58
+ describe ".get_module_name" do
59
+ meth = :get_module_name
60
+
61
+ it "works for normal classes and modules" do
62
+ mod.send(meth, Kernel).should == "Kernel"
63
+ mod.send(meth, String).should == "String"
64
+ end
65
+
66
+ it "works for class singletons" do
67
+ klass = class << String; self; end
68
+ mod.send(meth, klass).should == "String"
69
+ end
70
+
71
+ it "works for module singletons" do
72
+ klass = class << Enumerable; self; end
73
+ mod.send(meth, klass).should == "Enumerable"
74
+ end
75
+
76
+ it "works for instance singletons" do
77
+ klass = class << "kk"; self; end
78
+ mod.send(meth, klass).should == "String"
79
+
80
+ klass = class << []; self; end
81
+ mod.send(meth, klass).should == "Array"
82
+
83
+ klass = class << (class << []; self; end); self; end
84
+ mod.send(meth, klass).should == "Class"
85
+ end
86
+
87
+ it "works for namespaced names" do
88
+ klass = class << ::Sample::BasicExtension::Mo; self; end
89
+ mod.send(meth, klass).should == "Sample::BasicExtension::Mo"
90
+
91
+ klass = class << ::Sample::BasicExtension::Klass; self; end
92
+ mod.send(meth, klass).should == "Sample::BasicExtension::Klass"
93
+
94
+ klass = class << ::Sample::BasicExtension::Klass.new; self; end
95
+ mod.send(meth, klass).should == "Sample::BasicExtension::Klass"
96
+ end
97
+ end # .get_module_name
98
+
99
+ describe ".shell_escape" do
100
+ meth = :shell_escape
101
+
102
+ it "generally works" do
103
+ mod.send(meth, "").should == "''"
104
+ mod.send(meth, "one two").should == "one\\ two"
105
+ mod.send(meth, "one\ntwo").should == "one'\n'two"
106
+ mod.send(meth, "Kernel#`").should == "Kernel\\#\\`"
107
+ end
108
+ end # .shell_escape
109
+ end # ::ORI::Tools
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ori
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Alex Fortuna
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-02 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Object-Oriented RI for IRB Console
22
+ email: alex.r@askit.org
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.html
29
+ - README.md
30
+ files:
31
+ - MIT-LICENSE
32
+ - README.html
33
+ - README.md
34
+ - Rakefile
35
+ - VERSION.yml
36
+ - lib/misc/method_aliases.rb
37
+ - lib/ori.rb
38
+ - lib/ori/auto_config.rb
39
+ - lib/ori/colorize.rb
40
+ - lib/ori/config.rb
41
+ - lib/ori/extensions.rb
42
+ - lib/ori/extensions/object/ri.rb
43
+ - lib/ori/internals.rb
44
+ - lib/ori/library.rb
45
+ - lib/ori/list_method.rb
46
+ - lib/ori/request.rb
47
+ - lib/ori/tools.rb
48
+ - ori.gemspec
49
+ - samples/NOTES
50
+ - samples/basic_extension.rb
51
+ - samples/basic_inheritance.rb
52
+ - samples/self_singletons.rb
53
+ - samples/singleton_class_includes_module.rb
54
+ - spec/auto_config_spec.rb
55
+ - spec/colorize_spec.rb
56
+ - spec/inspector_spec.rb
57
+ - spec/internals_spec.rb
58
+ - spec/list_method_spec.rb
59
+ - spec/request_spec.rb
60
+ - spec/site/NOTES
61
+ - spec/site/library_spec.rb
62
+ - spec/site/spec_helper.rb
63
+ - spec/spec_helper.rb
64
+ - spec/tools_spec.rb
65
+ has_rdoc: true
66
+ homepage: http://github.com/dadooda/ori
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options: []
71
+
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ requirements: []
91
+
92
+ rubyforge_project:
93
+ rubygems_version: 1.3.7
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Object-Oriented RI for IRB Console
97
+ test_files:
98
+ - spec/auto_config_spec.rb
99
+ - spec/colorize_spec.rb
100
+ - spec/inspector_spec.rb
101
+ - spec/internals_spec.rb
102
+ - spec/list_method_spec.rb
103
+ - spec/request_spec.rb
104
+ - spec/site/library_spec.rb
105
+ - spec/site/spec_helper.rb
106
+ - spec/spec_helper.rb
107
+ - spec/tools_spec.rb