lookup 0.4.1 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,20 +13,16 @@ Then you'll be able to:
13
13
 
14
14
  ## Example usage:
15
15
 
16
- * `lookup ActiveRecord::Base#new` (returns a single method, since the method name is right)
17
- * `lookup ActiveRecord::Base#destroy` (returns two methods, since there's two methods with that name)
18
- * `lookup ActiveRecord::Base#destro` (returns three methods, uses methods beginning with "destroy")
19
- * `lookup ActiveRecord::Base#d` (tells you to be more specific, because it can't open 35 tabs at once)
20
- * `lookup ActiveRecord::Base` (returns a single consant)
21
- * `lookup av::Base` ("av" maps to ActionView, so returns ActionView::Base constant)
22
-
23
- ## Specifying an API
24
-
25
- You may specify an API to search in by making the first term either `1.8`, `1.9` or `rails` like this:
26
-
27
- * `lookup 1.9 Array#combination`
28
-
29
- By default all APIs are searched.
16
+ This has changed since the pre-1.0 versions. From 1.0 onwards you **must** specify an API that you wish to search.
17
+
18
+ * `lookup v2.3.8 ActiveRecord::Base#new` (returns a single method from the Rails 2.3.8 API, since the method name is right)
19
+ * `lookup v3.0.0 ActiveRecord::Base#destroy` (returns two methods from the Rails 3.0.0 API, since there's two methods with that name)
20
+ * `lookup v2.3.8 ActiveRecord::Base#destro` (returns three methods, uses methods beginning with "destroy")
21
+ * `lookup v2.3.8 ActiveRecord::Base#d` (tells you to be more specific, because it can't open 35 tabs at once)
22
+ * `lookup v2.3.8 ActiveRecord::Base` (returns a single consant)
23
+ * `lookup v2.3.8 av::Base` ("av" maps to ActionView, so returns ActionView::Base constant)
24
+ * `lookup 1.8 Array#join` (Returns a single method from the Ruby 1.8.7 API)
25
+ * `lookup 1.9 Array#join` (Returns a single method from the Ruby 1.9 API)
30
26
 
31
27
  ## Options
32
28
 
@@ -37,9 +33,10 @@ It also takes options:
37
33
 
38
34
  ## How it finds them
39
35
 
40
- 1. Checks if there's constants/methods with that exact name.
41
- 2. Checks if there's constants/methods with names beginning with that name.
42
- 3. Does a "fuzzy match" splitting the name and getting anything containing those letters in that order.
43
- 4. Opens your browser if you're running a DECENT_OPERATING_SYSTEM (may add support for things other than Mac later on)
44
- 5. ???
45
- 6. Profit
36
+ 1. Finds the specified API and uses it to scope future calls.
37
+ 2. Checks if there's constants/methods with that exact name.
38
+ 3. Checks if there's constants/methods with names beginning with that name.
39
+ 4. Does a "fuzzy match" splitting the name and getting anything containing those letters in that order.
40
+ 5. Opens your browser if you're running a DECENT_OPERATING_SYSTEM (may add support for things other than Mac later on)
41
+ 6. ???
42
+ 7. Profit
data/Rakefile CHANGED
@@ -23,6 +23,7 @@ Jeweler::Tasks.new do |s|
23
23
 
24
24
  s.add_dependency("sqlite3-ruby", ">=1.2.5")
25
25
  s.add_dependency("nokogiri")
26
+ s.add_dependency("activerecord", ">= 2.3.8")
26
27
  s.add_development_dependency("webmock")
27
28
 
28
29
  s.require_path = 'lib'
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>update_methods! (APILookup::Api)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/models.rb, line 25</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_methods!</span>
15
+ <span class="ruby-identifier">entries</span> = []
16
+ <span class="ruby-identifier">constants</span> = []
17
+ <span class="ruby-identifier">doc</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get</span>(<span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-node">&quot;#{url}/fr_method_index.html&quot;</span>))
18
+
19
+ <span class="ruby-comment cmt"># Actual HTML on Ruby doc site is invalid. </span>
20
+ <span class="ruby-comment cmt"># This makes it valid.</span>
21
+ <span class="ruby-identifier">doc</span> = <span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">HTML</span>(<span class="ruby-identifier">doc</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/&lt;a(.*?)&gt;(.*?)&lt;\/a&gt;/</span>) { <span class="ruby-node">&quot;&lt;a#{$1}&gt;#{$2.gsub(&quot;&lt;&quot;, &quot;&amp;lt;&quot;).gsub(&quot;&amp;gt;&quot;, &quot;&gt;&quot;)}&quot;</span> })
22
+ <span class="ruby-identifier">doc</span>.<span class="ruby-identifier">css</span>(<span class="ruby-value str">&quot;a&quot;</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span>
23
+ <span class="ruby-identifier">names</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">text</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot; &quot;</span>)
24
+ <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">names</span>.<span class="ruby-identifier">empty?</span>
25
+ <span class="ruby-identifier">method</span> = <span class="ruby-identifier">names</span>[<span class="ruby-value">0</span>]
26
+ <span class="ruby-identifier">constant</span> = <span class="ruby-identifier">names</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/[\(|\)]/</span>, <span class="ruby-value str">&quot;&quot;</span>)
27
+ <span class="ruby-comment cmt"># The same constant can be defined twice in different APIs, be wary!</span>
28
+ <span class="ruby-identifier">url</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">url</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;/classes/&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">constant</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">&quot;::&quot;</span>, <span class="ruby-value str">&quot;/&quot;</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;.html&quot;</span>
29
+ <span class="ruby-identifier">constant</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">constants</span>.<span class="ruby-identifier">find_or_create_by_hash</span>(<span class="ruby-identifier">:name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">constant</span>, <span class="ruby-identifier">:url</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">url</span>)
30
+
31
+ <span class="ruby-identifier">url</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">url</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;/&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">a</span>[<span class="ruby-value str">&quot;href&quot;</span>]
32
+ <span class="ruby-identifier">constant</span>.<span class="ruby-identifier">entries</span>.<span class="ruby-identifier">find_or_create_by_hash</span>(<span class="ruby-identifier">:name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">method</span>, <span class="ruby-identifier">:url</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">url</span>)
33
+ <span class="ruby-keyword kw">end</span>
34
+
35
+ <span class="ruby-comment cmt"># entries.each_slice(100) do |methods|</span>
36
+ <span class="ruby-comment cmt"># LookupBase.connection.execute(&quot;INSERT INTO entries (name, url) &quot;)</span>
37
+ <span class="ruby-comment cmt"># end</span>
38
+ <span class="ruby-keyword kw">end</span></pre>
39
+ </body>
40
+ </html>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>update_classes! (APILookup::Api)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/models.rb, line 51</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_classes!</span>
15
+ <span class="ruby-identifier">doc</span> = <span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">HTML</span>(<span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get</span>(<span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-node">&quot;#{url}/fr_class_index.html&quot;</span>)))
16
+ <span class="ruby-identifier">doc</span>.<span class="ruby-identifier">css</span>(<span class="ruby-value str">&quot;a&quot;</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span>
17
+ <span class="ruby-identifier">constant</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">constants</span>.<span class="ruby-identifier">find_or_create_by_name_and_url</span>(<span class="ruby-identifier">a</span>.<span class="ruby-identifier">text</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">url</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;/&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">a</span>[<span class="ruby-value str">&quot;href&quot;</span>])
18
+ <span class="ruby-keyword kw">end</span>
19
+ <span class="ruby-keyword kw">end</span></pre>
20
+ </body>
21
+ </html>
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>update! (APILookup)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/lookup.rb, line 11</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update!</span>
15
+ <span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;Updating API, this may take a minute or two. Please be patient!&quot;</span>
16
+ [<span class="ruby-constant">Constant</span>, <span class="ruby-constant">Entry</span>, <span class="ruby-constant">Api</span>].<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">klass</span><span class="ruby-operator">|</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">delete_all</span> }
17
+
18
+ <span class="ruby-identifier">update_api!</span>(<span class="ruby-value str">&quot;Rails&quot;</span>, <span class="ruby-value str">&quot;http://api.rubyonrails.org&quot;</span>)
19
+ <span class="ruby-identifier">update_api!</span>(<span class="ruby-value str">&quot;Ruby 1.8.7&quot;</span>, <span class="ruby-value str">&quot;http://www.ruby-doc.org/core&quot;</span>)
20
+ <span class="ruby-identifier">update_api!</span>(<span class="ruby-value str">&quot;Ruby 1.9&quot;</span>, <span class="ruby-value str">&quot;http://ruby-doc.org/ruby-1.9&quot;</span>)
21
+
22
+ <span class="ruby-keyword kw">end</span></pre>
23
+ </body>
24
+ </html>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>update_api! (APILookup)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/lookup.rb, line 21</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update_api!</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">url</span>)
15
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Updating API for #{name}...&quot;</span>
16
+ <span class="ruby-identifier">api</span> = <span class="ruby-constant">Api</span>.<span class="ruby-identifier">find_or_create_by_name_and_url</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">url</span>)
17
+ <span class="ruby-identifier">api</span>.<span class="ruby-identifier">update_methods!</span>
18
+ <span class="ruby-identifier">api</span>.<span class="ruby-identifier">update_classes!</span>
19
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;DONE (with #{name})!&quot;</span>
20
+ <span class="ruby-keyword kw">end</span></pre>
21
+ </body>
22
+ </html>
@@ -0,0 +1,33 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>find_constant (APILookup)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/lookup.rb, line 29</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find_constant</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">entry</span>=<span class="ruby-keyword kw">nil</span>)
15
+ <span class="ruby-comment cmt"># Find by specific name.</span>
16
+ <span class="ruby-identifier">constants</span> = <span class="ruby-constant">Constant</span>.<span class="ruby-identifier">find_all_by_name</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">:include</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;entries&quot;</span>)
17
+ <span class="ruby-comment cmt"># search for class methods, which is prolly what we want if we can find it</span>
18
+ <span class="ruby-identifier">constants</span> = <span class="ruby-constant">Constant</span>.<span class="ruby-identifier">find_all_by_name</span>(<span class="ruby-node">&quot;#{name}::ClassMethods&quot;</span>, <span class="ruby-identifier">:include</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;entries&quot;</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">constants</span>.<span class="ruby-identifier">empty?</span>
19
+ <span class="ruby-comment cmt"># Find by name beginning with &lt;blah&gt;.</span>
20
+ <span class="ruby-identifier">constants</span> = <span class="ruby-constant">Constant</span>.<span class="ruby-identifier">all</span>(<span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-value str">&quot;name LIKE ?&quot;</span>, <span class="ruby-identifier">name</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;%&quot;</span>], <span class="ruby-identifier">:include</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;entries&quot;</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">constants</span>.<span class="ruby-identifier">empty?</span>
21
+ <span class="ruby-comment cmt"># Find by fuzzy.</span>
22
+ <span class="ruby-identifier">match</span>=<span class="ruby-node">&quot;%#{name.split(&quot;&quot;).join(&quot;%&quot;)}%&quot;</span>
23
+ <span class="ruby-identifier">constants</span> = <span class="ruby-constant">Constant</span>.<span class="ruby-identifier">find_by_sql</span>(<span class="ruby-node">&quot;select * from constants where name LIKE '#{match}'&quot;</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">constants</span>.<span class="ruby-identifier">empty?</span>
24
+ <span class="ruby-identifier">regex</span>=<span class="ruby-identifier">build_regex_from_constant</span>(<span class="ruby-identifier">name</span>)
25
+ <span class="ruby-identifier">constants</span> = <span class="ruby-identifier">constants</span>.<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">regex</span> }
26
+ <span class="ruby-comment cmt"># Narrow it down to the constants that only contain the entry we are looking for.</span>
27
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">entry</span>
28
+ <span class="ruby-identifier">constants</span> = <span class="ruby-identifier">constants</span>.<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">constant</span><span class="ruby-operator">|</span> <span class="ruby-operator">!</span><span class="ruby-identifier">constant</span>.<span class="ruby-identifier">entries</span>.<span class="ruby-identifier">find_by_name</span>(<span class="ruby-identifier">entry</span>).<span class="ruby-identifier">nil?</span> }
29
+ <span class="ruby-keyword kw">end</span>
30
+ <span class="ruby-identifier">constants</span>
31
+ <span class="ruby-keyword kw">end</span></pre>
32
+ </body>
33
+ </html>
@@ -0,0 +1,21 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>build_regex_from_constant (APILookup)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/lookup.rb, line 51</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">build_regex_from_constant</span>(<span class="ruby-identifier">name</span>)
15
+ <span class="ruby-identifier">parts</span>=<span class="ruby-identifier">name</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;::&quot;</span>).<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
16
+ <span class="ruby-identifier">c</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;&quot;</span>).<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;[^:]*&quot;</span>)<span class="ruby-operator">+</span><span class="ruby-value str">&quot;[^:]*&quot;</span>
17
+ <span class="ruby-keyword kw">end</span>
18
+ <span class="ruby-node">/#{parts.join(&quot;::&quot;)}/i</span>
19
+ <span class="ruby-keyword kw">end</span></pre>
20
+ </body>
21
+ </html>
@@ -0,0 +1,33 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>smart_rails_constant_substitutions (APILookup)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/lookup.rb, line 58</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">smart_rails_constant_substitutions</span>(<span class="ruby-identifier">name</span>)
15
+ <span class="ruby-identifier">parts</span> = <span class="ruby-identifier">name</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;::&quot;</span>).<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;:&quot;</span>)}.<span class="ruby-identifier">flatten</span>
16
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">parts</span>.<span class="ruby-identifier">first</span>
17
+ <span class="ruby-identifier">rep</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">parts</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">downcase</span>
18
+ <span class="ruby-comment cmt"># so it falls back on fuzzy and matches AR as well as ActiveResource</span>
19
+ <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;ar&quot;</span> <span class="ruby-keyword kw">then</span> <span class="ruby-value str">&quot;ActiveRecord&quot;</span>
20
+ <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;ares&quot;</span> <span class="ruby-keyword kw">then</span> <span class="ruby-value str">&quot;ActiveResource&quot;</span>
21
+ <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;am&quot;</span> <span class="ruby-keyword kw">then</span> <span class="ruby-value str">&quot;ActionMailer&quot;</span>
22
+ <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;as&quot;</span> <span class="ruby-keyword kw">then</span> <span class="ruby-value str">&quot;ActiveSupport&quot;</span>
23
+ <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;ac&quot;</span> <span class="ruby-keyword kw">then</span> <span class="ruby-value str">&quot;ActionController&quot;</span>
24
+ <span class="ruby-keyword kw">when</span> <span class="ruby-value str">&quot;av&quot;</span> <span class="ruby-keyword kw">then</span> <span class="ruby-value str">&quot;ActionView&quot;</span>
25
+ <span class="ruby-keyword kw">else</span>
26
+ <span class="ruby-identifier">parts</span>.<span class="ruby-identifier">first</span>
27
+ <span class="ruby-keyword kw">end</span>
28
+ <span class="ruby-keyword kw">return</span> ([<span class="ruby-identifier">rep</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">parts</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]).<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;::&quot;</span>)
29
+ <span class="ruby-keyword kw">end</span>
30
+ <span class="ruby-identifier">name</span>
31
+ <span class="ruby-keyword kw">end</span></pre>
32
+ </body>
33
+ </html>
@@ -0,0 +1,35 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>find_method (APILookup)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/lookup.rb, line 79</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find_method</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">constant</span>=<span class="ruby-keyword kw">nil</span>)
15
+ <span class="ruby-identifier">methods</span> = []
16
+ <span class="ruby-comment cmt"># Full match</span>
17
+ <span class="ruby-identifier">methods</span> = <span class="ruby-constant">Entry</span>.<span class="ruby-identifier">find_all_by_name</span>(<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span>)
18
+ <span class="ruby-comment cmt"># Start match</span>
19
+ <span class="ruby-identifier">methods</span> = <span class="ruby-constant">Entry</span>.<span class="ruby-identifier">all</span>(<span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> [<span class="ruby-value str">&quot;name LIKE ?&quot;</span>, <span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;%&quot;</span>]) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">methods</span>.<span class="ruby-identifier">empty?</span>
20
+ <span class="ruby-comment cmt"># Wildcard substitution</span>
21
+ <span class="ruby-identifier">methods</span> = <span class="ruby-constant">Entry</span>.<span class="ruby-identifier">find_by_sql</span>(<span class="ruby-node">&quot;select * from entries where name LIKE '#{name.to_s.gsub(&quot;*&quot;, &quot;%&quot;)}'&quot;</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">methods</span>.<span class="ruby-identifier">empty?</span>
22
+ <span class="ruby-comment cmt"># Fuzzy match</span>
23
+ <span class="ruby-identifier">methods</span> = <span class="ruby-constant">Entry</span>.<span class="ruby-identifier">find_by_sql</span>(<span class="ruby-node">&quot;select * from entries where name LIKE '%#{name.to_s.split(&quot;&quot;).join(&quot;%&quot;)}%'&quot;</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">methods</span>.<span class="ruby-identifier">empty?</span>
24
+
25
+ <span class="ruby-comment cmt"># Weight the results, last result is the first one we want shown first</span>
26
+ <span class="ruby-identifier">methods</span> = <span class="ruby-identifier">methods</span>.<span class="ruby-identifier">sort_by</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">:weighting</span>)
27
+
28
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">constant</span>
29
+ <span class="ruby-identifier">constants</span> = <span class="ruby-identifier">find_constant</span>(<span class="ruby-identifier">constant</span>)
30
+ <span class="ruby-identifier">methods</span> = <span class="ruby-identifier">methods</span>.<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span> <span class="ruby-identifier">constants</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">constant</span>) }
31
+ <span class="ruby-keyword kw">end</span>
32
+ <span class="ruby-identifier">methods</span>
33
+ <span class="ruby-keyword kw">end</span></pre>
34
+ </body>
35
+ </html>
@@ -0,0 +1,52 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>search (APILookup)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/lookup.rb, line 100</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">search</span>(<span class="ruby-identifier">msg</span>, <span class="ruby-identifier">options</span>={})
15
+ <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:api</span>] <span class="ruby-operator">||=</span> <span class="ruby-keyword kw">if</span> <span class="ruby-regexp re">/^1\.9/</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">msg</span>)
16
+ <span class="ruby-value str">&quot;Ruby 1.9&quot;</span>
17
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-regexp re">/^1\.8/</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">msg</span>)
18
+ <span class="ruby-value str">&quot;Ruby 1.8.7&quot;</span>
19
+ <span class="ruby-keyword kw">elsif</span> <span class="ruby-regexp re">/^Rails/i</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">msg</span>)
20
+ <span class="ruby-value str">&quot;Rails&quot;</span>
21
+ <span class="ruby-keyword kw">end</span>
22
+
23
+ <span class="ruby-identifier">msg</span> = <span class="ruby-identifier">msg</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/^(.*?)\s/</span>, <span class="ruby-value str">&quot;&quot;</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:api</span>]
24
+
25
+ <span class="ruby-identifier">splitter</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:splitter</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">&quot;#&quot;</span>
26
+ <span class="ruby-identifier">parts</span> = <span class="ruby-identifier">msg</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot; &quot;</span>)[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>].<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">split</span>(<span class="ruby-identifier">splitter</span>) }.<span class="ruby-identifier">flatten!</span>
27
+ <span class="ruby-comment cmt"># It's a constant! Oh... and there's nothing else in the string!</span>
28
+ <span class="ruby-identifier">first</span> = <span class="ruby-identifier">smart_rails_constant_substitutions</span>(<span class="ruby-identifier">parts</span>.<span class="ruby-identifier">first</span>)
29
+ <span class="ruby-identifier">output</span> = <span class="ruby-keyword kw">if</span> <span class="ruby-regexp re">/^[A-Z]/</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">first</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">parts</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
30
+ <span class="ruby-identifier">find_constant</span>(<span class="ruby-identifier">first</span>)
31
+ <span class="ruby-comment cmt"># It's a method!</span>
32
+ <span class="ruby-keyword kw">else</span>
33
+ <span class="ruby-comment cmt"># Right, so they only specified one argument. Therefore, we look everywhere.</span>
34
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">parts</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
35
+ <span class="ruby-identifier">o</span> = <span class="ruby-identifier">find_method</span>(<span class="ruby-identifier">parts</span>.<span class="ruby-identifier">last</span>)
36
+ <span class="ruby-comment cmt"># Left, so they specified two arguments. First is probably a constant, so let's find that!</span>
37
+ <span class="ruby-keyword kw">else</span>
38
+ <span class="ruby-identifier">o</span> = <span class="ruby-identifier">find_method</span>(<span class="ruby-identifier">parts</span>.<span class="ruby-identifier">last</span>, <span class="ruby-identifier">first</span>)
39
+ <span class="ruby-keyword kw">end</span>
40
+ <span class="ruby-identifier">o</span>
41
+ <span class="ruby-keyword kw">end</span>
42
+
43
+ <span class="ruby-identifier">output</span> = <span class="ruby-identifier">search</span>(<span class="ruby-identifier">msg</span>, <span class="ruby-identifier">options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">:splitter</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;.&quot;</span>)) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">output</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">splitter</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">&quot;.&quot;</span>
44
+
45
+ <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:api</span>] <span class="ruby-operator">||=</span> [<span class="ruby-value str">&quot;Ruby 1.8.7&quot;</span>, <span class="ruby-value str">&quot;Rails&quot;</span>]
46
+ <span class="ruby-identifier">selected_output</span> = <span class="ruby-identifier">output</span>.<span class="ruby-identifier">select</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">m</span><span class="ruby-operator">|</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:api</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">m</span>.<span class="ruby-identifier">api</span>.<span class="ruby-identifier">name</span>) }
47
+ <span class="ruby-identifier">selected_output</span> = <span class="ruby-identifier">output</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">selected_output</span>.<span class="ruby-identifier">empty?</span>
48
+
49
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">selected_output</span>
50
+ <span class="ruby-keyword kw">end</span></pre>
51
+ </body>
52
+ </html>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>connection (SetupTables)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/models.rb, line 75</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">connection</span>
15
+ <span class="ruby-constant">APILookup</span><span class="ruby-operator">::</span><span class="ruby-constant">Api</span>.<span class="ruby-identifier">connection</span>
16
+ <span class="ruby-keyword kw">end</span></pre>
17
+ </body>
18
+ </html>
@@ -0,0 +1,34 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>up (SetupTables)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/models.rb, line 79</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">up</span>
15
+ <span class="ruby-identifier">create_table</span> <span class="ruby-identifier">:apis</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
16
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">string</span> <span class="ruby-identifier">:name</span>, <span class="ruby-identifier">:url</span>
17
+ <span class="ruby-keyword kw">end</span>
18
+
19
+ <span class="ruby-identifier">create_table</span> <span class="ruby-identifier">:entries</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
20
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">string</span> <span class="ruby-identifier">:name</span>, <span class="ruby-identifier">:url</span>
21
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">references</span> <span class="ruby-identifier">:constant</span>
22
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">integer</span> <span class="ruby-identifier">:weighting</span>, <span class="ruby-identifier">:default</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
23
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">integer</span> <span class="ruby-identifier">:count</span>, <span class="ruby-identifier">:default</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
24
+ <span class="ruby-keyword kw">end</span>
25
+
26
+ <span class="ruby-identifier">create_table</span> <span class="ruby-identifier">:constants</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">t</span><span class="ruby-operator">|</span>
27
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">string</span> <span class="ruby-identifier">:name</span>, <span class="ruby-identifier">:url</span>
28
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">references</span> <span class="ruby-identifier">:api</span>
29
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">integer</span> <span class="ruby-identifier">:weighting</span>, <span class="ruby-identifier">:default</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
30
+ <span class="ruby-identifier">t</span>.<span class="ruby-identifier">integer</span> <span class="ruby-identifier">:count</span>, <span class="ruby-identifier">:default</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
31
+ <span class="ruby-keyword kw">end</span>
32
+ <span class="ruby-keyword kw">end</span></pre>
33
+ </body>
34
+ </html>
@@ -0,0 +1,112 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>File: lookup.rb</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="fileHeader">
50
+ <h1>lookup.rb</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>lib/lookup.rb
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Sun Jul 04 09:34:49 +1000 2010</td>
60
+ </tr>
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+
72
+ <div id="requires-list">
73
+ <h3 class="section-bar">Required files</h3>
74
+
75
+ <div class="name-list">
76
+ rubygems&nbsp;&nbsp;
77
+ net/http&nbsp;&nbsp;
78
+ active_record&nbsp;&nbsp;
79
+ nokogiri&nbsp;&nbsp;
80
+ find_by_hash&nbsp;&nbsp;
81
+ </div>
82
+ </div>
83
+
84
+ </div>
85
+
86
+
87
+ </div>
88
+
89
+
90
+ <!-- if includes -->
91
+
92
+ <div id="section">
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+ <!-- if method_list -->
102
+
103
+
104
+ </div>
105
+
106
+
107
+ <div id="validator-badges">
108
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
109
+ </div>
110
+
111
+ </body>
112
+ </html>
File without changes