lookup 1.0.0.beta2 → 1.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source 'http://rubygems.org'
2
- gem 'activerecord'
2
+ gem 'activerecord', :require => "active_record"
3
3
  gem 'nokogiri'
4
4
  gem 'find_by_hash'
5
5
  gem 'sqlite3-ruby'
data/bin/lookup CHANGED
@@ -1,5 +1,6 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
  require 'optparse'
3
+ require 'pathname'
3
4
 
4
5
  # How many methods / constants to return.
5
6
  THRESHOLD = 5
@@ -7,7 +8,7 @@ MAC = !!/darwin/.match(RUBY_PLATFORM)
7
8
  WINDOWS = !!/win/.match(RUBY_PLATFORM) if not MAC
8
9
 
9
10
  def clear_database
10
- file = File.join(File.dirname(__FILE__), "lookup.sqlite3")
11
+ file = Pathname.new(ENV["HOME"]) + ".lookup/lookup.sqlite3"
11
12
  FileUtils.rm(file) if File.exists?(file)
12
13
  end
13
14
 
@@ -45,9 +46,27 @@ def display_results(results, search_string)
45
46
  end
46
47
  end
47
48
 
49
+ local_lib=File.join(File.dirname(__FILE__), "../lib/lookup")
50
+ if File.exists?(local_lib + ".rb")
51
+ require local_lib
52
+ else
53
+ require 'rubygems'
54
+ require 'lookup'
55
+ end
56
+
48
57
  OPTIONS = {}
58
+ output = nil
49
59
  op=OptionParser.new do |opts|
50
- opts.banner = "Usage: lookup <constant|method> [method] [OPTIONS]"
60
+ opts.banner = %Q{
61
+ Usage: lookup <api> <constant|method> [method] [OPTIONS]
62
+ APIs are:
63
+ v3.0.0 - Rails 3.0.0
64
+ v2.3.8 - Rails 2.3.8
65
+ 1.9 - Ruby 1.9
66
+ 1.8 - Ruby 1.8
67
+
68
+ Example: lookup v3.0.0 ActiveRecord::Base new
69
+ }
51
70
 
52
71
  opts.on("-c", "--clear", "Clear database") do
53
72
  OPTIONS[:clear] = true
@@ -56,25 +75,27 @@ op=OptionParser.new do |opts|
56
75
  opts.on("-t", "--text", "Text only") do
57
76
  OPTIONS[:text] = true
58
77
  end
78
+
79
+ opts.on("-v", "--version", "Version of lookup") do
80
+ output = Lookup::VERSION
81
+ end
59
82
  end
60
83
  op.parse!
61
84
 
62
85
  clear_database if OPTIONS[:clear]
86
+ unless output
87
+ begin
88
+ search_string=ARGV[0..-1].join(" ")
89
+ if search_string.strip.empty?
90
+ puts op.help
63
91
 
64
-
65
- local_lib=File.join(File.dirname(__FILE__), "../lib/lookup")
66
- if File.exists?(local_lib + ".rb")
67
- require local_lib
92
+ else
93
+ results=Lookup.search(search_string)
94
+ display_results(results, search_string)
95
+ end
96
+ rescue Lookup::APINotFound => e
97
+ puts e.message
98
+ end
68
99
  else
69
- require 'rubygems'
70
- require 'lookup'
100
+ puts output
71
101
  end
72
-
73
- search_string=ARGV[0..-1].join(" ")
74
- if search_string.strip.empty?
75
- puts op.help
76
- puts
77
- else
78
- results=Lookup.search(search_string)
79
- display_results(results, search_string)
80
- end
data/lib/lookup.rb CHANGED
@@ -1,12 +1,16 @@
1
1
  require 'rubygems'
2
- require 'bundler'
3
2
  require 'net/http'
4
3
 
5
- Bundler.setup
4
+ gemfile = File.expand_path('../../Gemfile', __FILE__)
5
+ require 'bundler'
6
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
7
  Bundler.require(:default)
7
- require 'active_record'
8
8
 
9
9
  module Lookup
10
+ VERSION = "1.0.0.beta3"
11
+ APIS = []
12
+
13
+ class APINotFound < StandardError; end
10
14
 
11
15
  class << self
12
16
  def update!
@@ -23,6 +27,7 @@ module Lookup
23
27
  def update_api!(name, url)
24
28
  puts "Updating API for #{name}..."
25
29
  api = Api.find_or_create_by_name_and_url(name, url)
30
+ APIS << api
26
31
  api.update_methods!
27
32
  api.update_classes!
28
33
  puts "DONE (with #{name})!"
@@ -110,6 +115,16 @@ module Lookup
110
115
  "Rails v#{$1}"
111
116
  end
112
117
 
118
+ raise Lookup::APINotFound, %Q{You must specify a valid API as the first keyword. Included APIs:
119
+ v2.3.8 - Rails 2.3.8
120
+ v3.0.0 - Rails 3.0.0
121
+ 1.9 - Ruby 1.9
122
+ 1.8 - Ruby 1.8
123
+
124
+ Example usage: lookup v2.3.8 ActiveRecord::Base
125
+ } if options[:api].blank?
126
+
127
+
113
128
  options[:api] = Api.find_by_name!(options[:api]) unless options[:api].is_a?(Api)
114
129
 
115
130
  msg = msg.gsub(/^(.*?)\s/, "") if options[:api]
data/lib/models.rb CHANGED
@@ -6,7 +6,6 @@ module Lookup
6
6
  end
7
7
 
8
8
  class LookupBase < ActiveRecord::Base
9
- include FindByHash
10
9
  end
11
10
 
12
11
  if ENV["HOME"].nil?
data/lookup.gemspec CHANGED
@@ -4,7 +4,7 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  # -*- encoding: utf-8 -*-
7
- require File.expand_path("../lib/lookup/version", __FILE__)
7
+ require File.expand_path("../lib/lookup", __FILE__)
8
8
 
9
9
  Gem::Specification.new do |s|
10
10
  s.name = "lookup"
@@ -5,4 +5,8 @@ describe "testing for regressions" do
5
5
  lambda { Lookup.search("v2.3.8 #today?") }.should_not raise_error
6
6
  end
7
7
 
8
+ it "must have an API specified" do
9
+ lambda { Lookup.search("ActiveRecord::Base") }.should raise_error(Lookup::APINotFound)
10
+ end
11
+
8
12
  end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
3
  ENV['HOME'] = File.dirname(__FILE__)
4
4
  require 'rubygems'
5
5
  require 'bundler'
6
+
6
7
  Bundler.require(:default, :test)
7
8
 
8
9
  def here
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: -1848230054
4
+ hash: -1848230053
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
- - beta2
11
- version: 1.0.0.beta2
10
+ - beta3
11
+ version: 1.0.0.beta3
12
12
  platform: ruby
13
13
  authors:
14
14
  - Ryan Bigg
@@ -16,13 +16,14 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-09-10 00:00:00 +10:00
19
+ date: 2010-09-11 00:00:00 +10:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: bundler
24
+ type: :development
24
25
  prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
26
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
27
  none: false
27
28
  requirements:
28
29
  - - ">="
@@ -33,12 +34,12 @@ dependencies:
33
34
  - 0
34
35
  - 0
35
36
  version: 1.0.0
36
- type: :development
37
- version_requirements: *id001
37
+ requirement: *id001
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: sqlite3-ruby
40
+ type: :runtime
40
41
  prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
42
+ version_requirements: &id002 !ruby/object:Gem::Requirement
42
43
  none: false
43
44
  requirements:
44
45
  - - ">="
@@ -49,12 +50,12 @@ dependencies:
49
50
  - 2
50
51
  - 5
51
52
  version: 1.2.5
52
- type: :runtime
53
- version_requirements: *id002
53
+ requirement: *id002
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: nokogiri
56
+ type: :runtime
56
57
  prerelease: false
57
- requirement: &id003 !ruby/object:Gem::Requirement
58
+ version_requirements: &id003 !ruby/object:Gem::Requirement
58
59
  none: false
59
60
  requirements:
60
61
  - - ">="
@@ -63,12 +64,12 @@ dependencies:
63
64
  segments:
64
65
  - 0
65
66
  version: "0"
66
- type: :runtime
67
- version_requirements: *id003
67
+ requirement: *id003
68
68
  - !ruby/object:Gem::Dependency
69
69
  name: activerecord
70
+ type: :runtime
70
71
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
72
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
73
  none: false
73
74
  requirements:
74
75
  - - ">="
@@ -79,12 +80,12 @@ dependencies:
79
80
  - 3
80
81
  - 8
81
82
  version: 2.3.8
82
- type: :runtime
83
- version_requirements: *id004
83
+ requirement: *id004
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: webmock
86
+ type: :runtime
86
87
  prerelease: false
87
- requirement: &id005 !ruby/object:Gem::Requirement
88
+ version_requirements: &id005 !ruby/object:Gem::Requirement
88
89
  none: false
89
90
  requirements:
90
91
  - - ">="
@@ -93,8 +94,7 @@ dependencies:
93
94
  segments:
94
95
  - 0
95
96
  version: "0"
96
- type: :runtime
97
- version_requirements: *id005
97
+ requirement: *id005
98
98
  description: A gem that provides a lazy man's ri
99
99
  email:
100
100
  - radarlistener@gmail.com
@@ -115,7 +115,6 @@ files:
115
115
  - install.rb
116
116
  - lib/lookup.rb
117
117
  - lib/lookup.sqlite3
118
- - lib/lookup/version.rb
119
118
  - lib/models.rb
120
119
  - lookup.gemspec
121
120
  - spec/.lookup/lookup.sqlite3
@@ -1,3 +0,0 @@
1
- module Lookup
2
- VERSION = "1.0.0.beta2"
3
- end