lookup 1.0.0.beta3 → 1.0.0.beta7

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.
data/Gemfile CHANGED
@@ -2,9 +2,9 @@ source 'http://rubygems.org'
2
2
  gem 'activerecord', :require => "active_record"
3
3
  gem 'nokogiri'
4
4
  gem 'find_by_hash'
5
- gem 'sqlite3-ruby'
5
+ gem 'sqlite3-ruby', '1.3.1'
6
6
 
7
7
  group :test do
8
8
  gem 'rspec', '~> 2.0.0.beta.20'
9
9
  gem 'webmock'
10
- end
10
+ end
data/Gemfile.lock CHANGED
@@ -43,5 +43,5 @@ DEPENDENCIES
43
43
  find_by_hash
44
44
  nokogiri
45
45
  rspec (~> 2.0.0.beta.20)
46
- sqlite3-ruby
46
+ sqlite3-ruby (= 1.3.1)
47
47
  webmock
data/lib/lookup.rb CHANGED
@@ -7,30 +7,48 @@ ENV['BUNDLE_GEMFILE'] = gemfile
7
7
  Bundler.require(:default)
8
8
 
9
9
  module Lookup
10
- VERSION = "1.0.0.beta3"
10
+ VERSION = "1.0.0.beta7"
11
11
  APIS = []
12
12
 
13
13
  class APINotFound < StandardError; end
14
14
 
15
15
  class << self
16
+ def config
17
+ YAML::load_file(ENV["HOME"] + "/.lookup/config")
18
+ end
19
+
16
20
  def update!
17
- puts "Updating API, this may take a minute or two. Please be patient!"
21
+ puts "Updating API listings this may take a minute or two. Please be patient!"
22
+ puts "Big APIs (like Ruby + Rails) can take some time."
23
+ 2.times { puts " " }
18
24
  [Constant, Entry, Api].map { |klass| klass.delete_all }
25
+ 2.times { puts " " }
26
+ puts "Loading the following APIs:"
27
+ apis = config["apis"].values
28
+ for api in apis
29
+ puts " " + api["name"]
30
+ end
19
31
 
20
- update_api!("Rails v3.0.0", "http://api.rubyonrails.org")
21
- update_api!("Rails v2.3.8", "http://api.rubyonrails.org/v2.3.8")
22
- update_api!("Ruby 1.8.7", "http://www.ruby-doc.org/core")
23
- update_api!("Ruby 1.9", "http://ruby-doc.org/ruby-1.9")
32
+ for api in apis
33
+ update_api!(api["name"], api["url"])
34
+ end
24
35
 
25
36
  end
26
37
 
27
38
  def update_api!(name, url)
28
- puts "Updating API for #{name}..."
39
+ puts " Loading API for #{name}"
29
40
  api = Api.find_or_create_by_name_and_url(name, url)
30
41
  APIS << api
42
+
43
+ print " methods..."
31
44
  api.update_methods!
45
+ puts " ✓"
46
+
47
+ print " classes..."
32
48
  api.update_classes!
33
- puts "DONE (with #{name})!"
49
+ puts " "
50
+
51
+ puts " ✓ #{name}"
34
52
  end
35
53
 
36
54
  def find_constant(name, entry=nil, options={})
data/lib/models.rb CHANGED
@@ -31,7 +31,11 @@ module Lookup
31
31
  # This makes it valid.
32
32
  doc = Nokogiri::HTML(doc.gsub(/<a(.*?)>(.*?)<\/a>/m) { "<a#{$1}>#{$2.gsub("<", "&lt;").gsub(">", "&gt;")}" })
33
33
 
34
- doc.css("a").each do |a|
34
+ # All the a tags on this page are methods
35
+ methods = doc.css("a")
36
+ print " #{methods.size} to index"
37
+
38
+ methods.each do |a|
35
39
  names = a.text.split(" ")
36
40
  next if names.empty?
37
41
  method = names[0]
@@ -40,17 +44,22 @@ module Lookup
40
44
  url = self.url + "/classes/" + constant.gsub("::", "/") + ".html"
41
45
  constant = self.constants.find_or_create_by_name_and_url(constant, url)
42
46
 
43
- url = self.url + "/" + a["href"]
47
+ if !/^http:\/\//.match(a["href"])
48
+ url = self.url + "/" + a["href"]
49
+ else
50
+ url = a["href"]
51
+ end
44
52
  constant.entries.find_or_create_by_name_and_url(method, url)
45
53
  end
46
-
47
- # entries.each_slice(100) do |methods|
48
- # LookupBase.connection.execute("INSERT INTO entries (name, url) ")
49
- # end
50
54
  end
51
55
 
52
56
  def update_classes!
53
57
  doc = Nokogiri::HTML(Net::HTTP.get(URI.parse("#{url}/fr_class_index.html")))
58
+
59
+ # All the a tags on this page are classes
60
+ classes = doc.css("a")
61
+ print " #{classes.size} to index"
62
+
54
63
  doc.css("a").each do |a|
55
64
  constant = self.constants.find_or_create_by_name_and_url(a.text, self.url + "/" + a["href"])
56
65
  end
data/lookup.gemspec CHANGED
@@ -21,10 +21,9 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_development_dependency "bundler", ">= 1.0.0"
23
23
 
24
- s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
24
+ s.add_dependency(%q<sqlite3-ruby>, [">= 1.3.0"])
25
25
  s.add_dependency(%q<nokogiri>, [">= 0"])
26
26
  s.add_dependency(%q<activerecord>, [">= 2.3.8"])
27
- s.add_dependency(%q<webmock>, [">= 0"])
28
27
 
29
28
  s.files = `git ls-files`.split("\n")
30
29
  s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
Binary file
data/spec/lookup_spec.rb CHANGED
@@ -1,10 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- describe "Lookup" do
4
- before(:all) do
5
- # Lookup.update!
6
- end
7
-
3
+ describe "Lookup" do
8
4
  def find_api(name)
9
5
  Lookup::Api.find_by_name(name)
10
6
  end
@@ -9,4 +9,8 @@ describe "testing for regressions" do
9
9
  lambda { Lookup.search("ActiveRecord::Base") }.should raise_error(Lookup::APINotFound)
10
10
  end
11
11
 
12
+ it "must have a valid URL" do
13
+ Lookup.search("1.9 Array#shuffle").first.url.scan("http").size.should eql(1)
14
+ end
15
+
12
16
  end
data/spec/spec_helper.rb CHANGED
@@ -39,10 +39,16 @@ stub_request(:get, "http://www.ruby-doc.org/core/fr_class_index.html").to_return
39
39
  stub_request(:get, "http://ruby-doc.org/ruby-1.9/fr_method_index.html").to_return(:body => entries("1.9"))
40
40
  stub_request(:get, "http://ruby-doc.org/ruby-1.9/fr_class_index.html").to_return(:body => classes("1.9"))
41
41
 
42
+ stub_request(:get, "http://faker.rubyforge.org/rdoc//fr_method_index.html").to_return(:body => entries("faker"))
43
+ stub_request(:get, "http://faker.rubyforge.org/rdoc//fr_class_index.html").to_return(:body => classes("faker"))
44
+
42
45
 
43
46
  require 'lookup'
44
47
  # require 'pathname'
45
48
 
46
49
  RSpec.configure do |config|
47
-
50
+ config.before(:all) do
51
+ FileUtils.cp(here + "../config/lookup", ENV["HOME"] + "/.lookup/config")
52
+ Lookup.update!
53
+ end
48
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookup
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1848230053
4
+ hash: -1848230057
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
- - beta3
11
- version: 1.0.0.beta3
10
+ - beta7
11
+ version: 1.0.0.beta7
12
12
  platform: ruby
13
13
  authors:
14
14
  - Ryan Bigg
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-09-11 00:00:00 +10:00
19
+ date: 2010-09-21 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -44,12 +44,12 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- hash: 21
47
+ hash: 27
48
48
  segments:
49
49
  - 1
50
- - 2
51
- - 5
52
- version: 1.2.5
50
+ - 3
51
+ - 0
52
+ version: 1.3.0
53
53
  requirement: *id002
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: nokogiri
@@ -81,20 +81,6 @@ dependencies:
81
81
  - 8
82
82
  version: 2.3.8
83
83
  requirement: *id004
84
- - !ruby/object:Gem::Dependency
85
- name: webmock
86
- type: :runtime
87
- prerelease: false
88
- version_requirements: &id005 !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- hash: 3
94
- segments:
95
- - 0
96
- version: "0"
97
- requirement: *id005
98
84
  description: A gem that provides a lazy man's ri
99
85
  email:
100
86
  - radarlistener@gmail.com