lookup 0.2.2

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,70 @@
1
+ require 'fileutils'
2
+
3
+ class APILookup
4
+
5
+ class MissingHome < StandardError
6
+ end
7
+
8
+ class LookupBase < ActiveRecord::Base
9
+ end
10
+ if ENV["HOME"].nil?
11
+ puts "The HOME environment variable should be set so lookup knows where"
12
+ puts "to store it's lookup database."
13
+ raise MissingHome, "HOME must be set to know where to store our local db."
14
+ end
15
+
16
+ LookupBase.establish_connection(:adapter => "sqlite3",
17
+ :database => File.join(ENV["HOME"],".lookup", "lookup.sqlite3"))
18
+
19
+ class Api < LookupBase
20
+ set_table_name "apis"
21
+ has_many :constants
22
+ end
23
+
24
+ class Constant < LookupBase
25
+ set_table_name "constants"
26
+ belongs_to :api
27
+ has_many :entries
28
+ end
29
+
30
+ class Entry < LookupBase
31
+ set_table_name "entries"
32
+ belongs_to :constant
33
+ end
34
+
35
+ end
36
+
37
+ class SetupTables < ActiveRecord::Migration
38
+ def self.connection
39
+ APILookup::Api.connection
40
+ end
41
+
42
+ def self.up
43
+ create_table :apis do |t|
44
+ t.string :name, :url
45
+ end
46
+
47
+ create_table :entries do |t|
48
+ t.string :name, :url
49
+ t.references :constant
50
+ t.integer :weighting, :default => 0
51
+ t.integer :count, :default => 0
52
+ end
53
+
54
+ create_table :constants do |t|
55
+ t.string :name, :url
56
+ t.references :api
57
+ t.integer :weighting, :default => 0
58
+ t.integer :count, :default => 0
59
+ end
60
+ end
61
+ end
62
+
63
+ FileUtils.mkdir_p(File.join(ENV["HOME"],".lookup"))
64
+
65
+ if !APILookup::Api.table_exists? &&
66
+ !APILookup::Constant.table_exists? &&
67
+ !APILookup::Entry.table_exists?
68
+ SetupTables.up
69
+ APILookup.update
70
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "Lookup" do
4
+
5
+ def find_constant(name)
6
+ APILookup::Constant.find_by_name(name)
7
+ end
8
+
9
+ def find_entry(constant, name)
10
+ APILookup::Entry.find_by_name_and_constant_id(name, find_constant(constant).id)
11
+ end
12
+
13
+ before do
14
+ end
15
+
16
+ it "should be able to find a constant" do
17
+ APILookup.search("ActiveRecord::Base").should eql([find_constant("ActiveRecord::Base")])
18
+ end
19
+
20
+ it "should be able to find a short constant" do
21
+ APILookup.search("ar::Base").should eql([find_constant("ActiveRecord::Base")])
22
+ end
23
+
24
+ it "should be able to find a constant and a method (using hash symbol)" do
25
+ APILookup.search("ActiveRecord::Base#new").should eql([find_entry("ActiveRecord::Base", "new")])
26
+ end
27
+
28
+ it "should be able to find a constant and a method (using spaces)" do
29
+ APILookup.search("ActiveRecord::Base new").should eql([find_entry("ActiveRecord::Base", "new")])
30
+ end
31
+
32
+ it "should be able to find a constant and a method (specified wildcard)" do
33
+ APILookup.search("ActiveRecord::Base#n*w").should eql([find_entry("ActiveRecord::Base", "new")])
34
+ end
35
+
36
+ it "should be able to find a constant and some methods (fuzzy)" do
37
+ APILookup.search("ActiveRecord::Base#nw").should eql([find_entry("ActiveRecord::Base", "new"), find_entry("ActiveRecord::Base", "new_record?")])
38
+ end
39
+
40
+ it "should be able to search on shortened constants" do
41
+ APILookup.search("ar::base#new").should eql([find_entry("ActiveRecord::Base", "new")])
42
+ end
43
+
44
+ end
@@ -0,0 +1,7 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
+ ENV['HOME'] = File.dirname(__FILE__)
4
+
5
+ require 'rubygems'
6
+ require 'fakeweb'
7
+ require 'lookup'
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lookup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Bigg
8
+ autorequire: lookup
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-28 00:00:00 +10:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sqlite3-ruby
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.5
24
+ version:
25
+ description: A gem that provides a lazy man's ri
26
+ email: radarlistener@gmail.com
27
+ executables:
28
+ - lookup
29
+ - lookup
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - LICENSE
34
+ - README.md
35
+ files:
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - TODO
40
+ - bin/lookup
41
+ - lib/classes
42
+ - lib/config.rb
43
+ - lib/lookup.rb
44
+ - lib/lookup.sqlite3
45
+ - lib/methods
46
+ - lib/models.rb
47
+ - spec/lookup_spec.rb
48
+ - spec/spec_helper.rb
49
+ has_rdoc: true
50
+ homepage: http://gitpilot.com
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --charset=UTF-8
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.5
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: A gem that provides a lazy man's ri
77
+ test_files:
78
+ - spec/lookup_spec.rb
79
+ - spec/spec_helper.rb