pirate 0.1.4 → 0.1.6
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/.gitignore +45 -0
- data/Gemfile +2 -17
- data/Gemfile.lock +21 -47
- data/LICENSE.txt +1 -1
- data/README.rdoc +1 -1
- data/Rakefile +1 -51
- data/VERSION +1 -1
- data/lib/pirate.rb +47 -4
- data/lib/pirate/version.rb +3 -0
- data/pirate.gemspec +26 -72
- data/spec/pirate_spec.rb +9 -7
- data/spec/spec_helper.rb +100 -5
- metadata +71 -79
data/.gitignore
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# jeweler generated
|
15
|
+
pkg
|
16
|
+
|
17
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
18
|
+
#
|
19
|
+
# * Create a file at ~/.gitignore
|
20
|
+
# * Include files you want ignored
|
21
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
22
|
+
#
|
23
|
+
# After doing this, these files will be ignored in all your git projects,
|
24
|
+
# saving you from having to 'pollute' every project you touch with them
|
25
|
+
#
|
26
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
27
|
+
#
|
28
|
+
# For MacOS:
|
29
|
+
#
|
30
|
+
#.DS_Store
|
31
|
+
#
|
32
|
+
# For TextMate
|
33
|
+
#*.tmproj
|
34
|
+
#tmtags
|
35
|
+
#
|
36
|
+
# For emacs:
|
37
|
+
#*~
|
38
|
+
#\#*
|
39
|
+
#.\#*
|
40
|
+
#
|
41
|
+
# For vim:
|
42
|
+
#*.swp
|
43
|
+
#
|
44
|
+
# For rvm:
|
45
|
+
.rvmrc
|
data/Gemfile
CHANGED
@@ -1,19 +1,4 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
2
|
|
6
|
-
gem
|
7
|
-
|
8
|
-
|
9
|
-
gem 'searchlogic', '2.4.27'
|
10
|
-
gem 'amatch', '0.2.5'
|
11
|
-
|
12
|
-
# Add dependencies to develop your gem here.
|
13
|
-
# Include everything needed to run rake, tests, features, etc.
|
14
|
-
group :development do
|
15
|
-
gem "rspec", "~> 1.3.0"
|
16
|
-
gem "bundler", "~> 1.0.0"
|
17
|
-
gem "jeweler", "~> 1.5.2"
|
18
|
-
gem "rcov", ">= 0"
|
19
|
-
end
|
3
|
+
# Specify your gem's dependencies in pirate.gemspec
|
4
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,59 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pirate (0.1.6)
|
5
|
+
activerecord (= 2.3.9)
|
6
|
+
activesupport (= 2.3.9)
|
7
|
+
acts-as-taggable-on (= 2.0.3)
|
8
|
+
amatch (= 0.2.5)
|
9
|
+
bundler (~> 1.0.0)
|
10
|
+
rspec (~> 1.3.0)
|
11
|
+
searchlogic (= 2.4.27)
|
12
|
+
sqlite3 (= 1.3.3)
|
13
|
+
will_paginate (= 2.3.15)
|
14
|
+
|
1
15
|
GEM
|
2
16
|
remote: http://rubygems.org/
|
3
17
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
builder (~> 2.1.2)
|
9
|
-
erubis (~> 2.6.6)
|
10
|
-
i18n (~> 0.4)
|
11
|
-
rack (~> 1.2.1)
|
12
|
-
rack-mount (~> 0.6.13)
|
13
|
-
rack-test (~> 0.5.6)
|
14
|
-
tzinfo (~> 0.3.23)
|
15
|
-
activemodel (3.0.3)
|
16
|
-
activesupport (= 3.0.3)
|
17
|
-
builder (~> 2.1.2)
|
18
|
-
i18n (~> 0.4)
|
19
|
-
activerecord (3.0.3)
|
20
|
-
activemodel (= 3.0.3)
|
21
|
-
activesupport (= 3.0.3)
|
22
|
-
arel (~> 2.0.2)
|
23
|
-
tzinfo (~> 0.3.23)
|
24
|
-
activesupport (3.0.3)
|
18
|
+
activerecord (2.3.9)
|
19
|
+
activesupport (= 2.3.9)
|
20
|
+
activesupport (2.3.9)
|
21
|
+
acts-as-taggable-on (2.0.3)
|
25
22
|
amatch (0.2.5)
|
26
|
-
arel (2.0.6)
|
27
|
-
builder (2.1.2)
|
28
|
-
erubis (2.6.6)
|
29
|
-
abstract (>= 1.0.0)
|
30
|
-
git (1.2.5)
|
31
|
-
i18n (0.5.0)
|
32
|
-
jeweler (1.5.2)
|
33
|
-
bundler (~> 1.0.0)
|
34
|
-
git (>= 1.2.5)
|
35
|
-
rake
|
36
|
-
rack (1.2.1)
|
37
|
-
rack-mount (0.6.13)
|
38
|
-
rack (>= 1.0.0)
|
39
|
-
rack-test (0.5.6)
|
40
|
-
rack (>= 1.0)
|
41
|
-
rake (0.8.7)
|
42
|
-
rcov (0.9.9)
|
43
23
|
rspec (1.3.1)
|
44
24
|
searchlogic (2.4.27)
|
45
25
|
activerecord (>= 2.0.0)
|
46
|
-
|
26
|
+
sqlite3 (1.3.3)
|
27
|
+
will_paginate (2.3.15)
|
47
28
|
|
48
29
|
PLATFORMS
|
49
30
|
ruby
|
50
31
|
|
51
32
|
DEPENDENCIES
|
52
|
-
|
53
|
-
activesupport
|
54
|
-
amatch (= 0.2.5)
|
55
|
-
bundler (~> 1.0.0)
|
56
|
-
jeweler (~> 1.5.2)
|
57
|
-
rcov
|
58
|
-
rspec (~> 1.3.0)
|
59
|
-
searchlogic (= 2.4.27)
|
33
|
+
pirate!
|
data/LICENSE.txt
CHANGED
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -1,52 +1,2 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'bundler'
|
3
|
-
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'rake'
|
11
|
-
|
12
|
-
require 'jeweler'
|
13
|
-
Jeweler::Tasks.new do |gem|
|
14
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
-
gem.name = "pirate"
|
16
|
-
gem.homepage = "http://github.com/58Phases/pirate"
|
17
|
-
gem.license = ""
|
18
|
-
gem.summary = %Q{Custom search function for 58Phases}
|
19
|
-
gem.description = %Q{Custom search function for 58Phases}
|
20
|
-
gem.email = "david@yibs.com"
|
21
|
-
gem.authors = ["David Hsu"]
|
22
|
-
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
-
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
-
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
-
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
-
gem.add_dependency 'searchlogic', '>= 2.4.27'
|
27
|
-
gem.add_dependency 'amatch', '>= 0.2.5'
|
28
|
-
end
|
29
|
-
Jeweler::RubygemsDotOrgTasks.new
|
30
|
-
|
31
|
-
#require 'rspec/core'
|
32
|
-
#require 'rspec/core/rake_task'
|
33
|
-
#RSpec::Core::RakeTask.new(:spec) do |spec|
|
34
|
-
# spec.pattern = FileList['spec/**/*_spec.rb']
|
35
|
-
#end
|
36
|
-
#
|
37
|
-
#RSpec::Core::RakeTask.new(:rcov) do |spec|
|
38
|
-
# spec.pattern = 'spec/**/*_spec.rb'
|
39
|
-
# spec.rcov = true
|
40
|
-
#end
|
41
|
-
|
42
|
-
task :default => :spec
|
43
|
-
|
44
|
-
require 'rake/rdoctask'
|
45
|
-
Rake::RDocTask.new do |rdoc|
|
46
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
-
|
48
|
-
rdoc.rdoc_dir = 'rdoc'
|
49
|
-
rdoc.title = "pirate #{version}"
|
50
|
-
rdoc.rdoc_files.include('README*')
|
51
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
-
end
|
2
|
+
Bundler::GemHelper.install_tasks
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/lib/pirate.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'uri'
|
2
|
+
require 'activesupport'
|
3
|
+
require 'active_record'
|
4
|
+
require 'amatch'
|
5
|
+
require 'will_paginate'
|
6
|
+
WillPaginate.enable_activerecord
|
7
|
+
WillPaginate.enable_named_scope
|
8
|
+
|
9
|
+
require 'searchlogic'
|
2
10
|
|
3
11
|
module Pirate
|
4
12
|
# Problems:
|
@@ -8,7 +16,7 @@ module Pirate
|
|
8
16
|
# - pagination
|
9
17
|
# http://www.mail-archive.com/rubyonrails-talk@googlegroups.com/msg49775.html
|
10
18
|
|
11
|
-
mattr_accessor :result, :
|
19
|
+
mattr_accessor :result, :store_per_page, :coupon_per_page
|
12
20
|
|
13
21
|
# :redirect => 'exact' || 'partial' || 'levenshtein' || nil
|
14
22
|
@@result = { :redirect => nil, :instance => nil, :stores => [], :coupons => [], :tags => [], :notice => nil }
|
@@ -19,6 +27,24 @@ module Pirate
|
|
19
27
|
|
20
28
|
@@page = { :stores => 1, :coupons => 1 }
|
21
29
|
|
30
|
+
def self.enable_tag
|
31
|
+
@@tag_enabled = true
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.tag_enabled?
|
35
|
+
@@tag_enabled
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.tag_enabled=(value)
|
39
|
+
ActiveSupport::Deprecation.warn "Pirate.tag_enabled= is deprecated, please use Pirate.enable_tag instead"
|
40
|
+
@@tag_enabled = value
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.tag_enabled
|
44
|
+
ActiveSupport::Deprecation.warn "Pirate.tag_enabled is deprecated, please use Pirate.tag_enabled? instead"
|
45
|
+
@@tag_enabled
|
46
|
+
end
|
47
|
+
|
22
48
|
def self.reset_result
|
23
49
|
@@result = { :redirect => nil, :instance => nil, :stores => [], :coupons => [], :tags => [], :notice => nil }
|
24
50
|
end
|
@@ -62,7 +88,7 @@ module Pirate
|
|
62
88
|
end
|
63
89
|
|
64
90
|
# Partial Match -- a known store name or tag name exists within the search query
|
65
|
-
foundstores = Store.active.find(:all, :conditions => [ "? LIKE
|
91
|
+
foundstores = Store.active.find(:all, :conditions => [ "? LIKE #{DB.db_concat("\'%\'", 'LOWER(name)', "\'%\'")}", query.downcase ])
|
66
92
|
if !foundstores.nil? and foundstores.length == 1
|
67
93
|
store = foundstores.first
|
68
94
|
@@result = { :redirect => 'partial', :instance => store,
|
@@ -164,4 +190,21 @@ module Pirate
|
|
164
190
|
|
165
191
|
end
|
166
192
|
|
167
|
-
|
193
|
+
|
194
|
+
module DB
|
195
|
+
# Symbols should be used for field names, everything else will be quoted as a string
|
196
|
+
def self.db_concat(*args)
|
197
|
+
adapter = ActiveRecord::Base.configurations[RAILS_ENV]['adapter'].to_sym
|
198
|
+
args.map!{ |arg| arg.class==Symbol ? arg.to_s : arg }
|
199
|
+
|
200
|
+
case adapter
|
201
|
+
when :mysql
|
202
|
+
"CONCAT(#{args.join(',')})"
|
203
|
+
when :sqlserver
|
204
|
+
args.join('+')
|
205
|
+
else
|
206
|
+
args.join('||')
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
end
|
data/pirate.gemspec
CHANGED
@@ -3,81 +3,35 @@
|
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
# -*- encoding: utf-8 -*-
|
7
|
+
$:.push File.expand_path("../lib", __FILE__)
|
8
|
+
require "pirate/version"
|
9
9
|
|
10
|
-
|
11
|
-
s.
|
12
|
-
s.
|
10
|
+
Gem::Specification.new do |s|
|
11
|
+
s.name = "pirate"
|
12
|
+
s.version = Pirate::VERSION
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
s.authors = ["David Hsu"]
|
15
|
+
s.email = ["david@yibs.com"]
|
16
|
+
s.homepage = "http://rubygems.org/gems/pirate"
|
17
|
+
s.summary = %q{Custom search function for 58Phases}
|
13
18
|
s.description = %q{Custom search function for 58Phases}
|
14
|
-
s.email = %q{david@yibs.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE.txt",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".rspec",
|
22
|
-
"Gemfile",
|
23
|
-
"Gemfile.lock",
|
24
|
-
"LICENSE.txt",
|
25
|
-
"README.rdoc",
|
26
|
-
"Rakefile",
|
27
|
-
"VERSION",
|
28
|
-
"lib/pirate.rb",
|
29
|
-
"pirate.gemspec",
|
30
|
-
"spec/pirate_spec.rb",
|
31
|
-
"spec/spec_helper.rb"
|
32
|
-
]
|
33
|
-
s.homepage = %q{http://github.com/58Phases/pirate}
|
34
|
-
s.licenses = [""]
|
35
|
-
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version = %q{1.3.7}
|
37
|
-
s.summary = %q{Custom search function for 58Phases}
|
38
|
-
s.test_files = [
|
39
|
-
"spec/pirate_spec.rb",
|
40
|
-
"spec/spec_helper.rb"
|
41
|
-
]
|
42
19
|
|
43
|
-
|
44
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
-
s.specification_version = 3
|
20
|
+
s.rubyforge_project = "pirate"
|
46
21
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
s.add_dependency(%q<searchlogic>, ["= 2.4.27"])
|
62
|
-
s.add_dependency(%q<amatch>, ["= 0.2.5"])
|
63
|
-
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
64
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
66
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
-
s.add_dependency(%q<searchlogic>, [">= 2.4.27"])
|
68
|
-
s.add_dependency(%q<amatch>, [">= 0.2.5"])
|
69
|
-
end
|
70
|
-
else
|
71
|
-
s.add_dependency(%q<activesupport>, [">= 0"])
|
72
|
-
s.add_dependency(%q<actionpack>, [">= 0"])
|
73
|
-
s.add_dependency(%q<searchlogic>, ["= 2.4.27"])
|
74
|
-
s.add_dependency(%q<amatch>, ["= 0.2.5"])
|
75
|
-
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
76
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
77
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
78
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
79
|
-
s.add_dependency(%q<searchlogic>, [">= 2.4.27"])
|
80
|
-
s.add_dependency(%q<amatch>, [">= 0.2.5"])
|
81
|
-
end
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
|
27
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
28
|
+
s.add_dependency(%q<activerecord>, ["= 2.3.9"])
|
29
|
+
s.add_dependency(%q<activesupport>, ["= 2.3.9"])
|
30
|
+
s.add_dependency(%q<amatch>, ["= 0.2.5"])
|
31
|
+
s.add_dependency(%q<searchlogic>, ["= 2.4.27"])
|
32
|
+
s.add_dependency(%q<will_paginate>, ["= 2.3.15"])
|
33
|
+
s.add_dependency(%q<acts-as-taggable-on>, ["= 2.0.3"])
|
34
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.0"])
|
35
|
+
s.add_dependency(%q<sqlite3>, ["= 1.3.3"])
|
82
36
|
end
|
83
37
|
|
data/spec/pirate_spec.rb
CHANGED
@@ -7,24 +7,26 @@ describe "Pirate" do
|
|
7
7
|
[['1', "Abe's of Maine"], ['2', "E.L.F."], ['3', "80's Purple"], ['4', "Adagio Teas"],
|
8
8
|
['5', "Akademiks"], ['6', "Discount Contact Lenses"], ['7', "Lens.com"], ['8', "Brylane Home"],
|
9
9
|
['9', "Directly Home"], ['10', "HomeClick"]].each do |store|
|
10
|
-
@stores[store[0]] = Factory(:approved_store, :name => store[1])
|
10
|
+
@stores[store[0]] = Store.create(:name => store[1], :state => 'approved') #Factory(:approved_store, :name => store[1])
|
11
11
|
end
|
12
12
|
|
13
13
|
@tags = {}
|
14
14
|
[['1', "shoes"], ['2', "discount"], ['3', "free shipping"], ['4', "home"],
|
15
15
|
['5', "electronics"], ['6', "promotion code"]].each do |tag|
|
16
|
-
@tags[tag[0]] = Factory(:tag, :name => tag[1])
|
16
|
+
@tags[tag[0]] = Tag.create(:name => tag[1]) #Factory(:tag, :name => tag[1])
|
17
17
|
end
|
18
18
|
|
19
|
-
Pirate.
|
19
|
+
Pirate.tag_enabled = true
|
20
|
+
|
21
|
+
Pirate.find(:searchInput => "discount")
|
20
22
|
Pirate.result[:redirect].should == 'exact'
|
21
23
|
Pirate.result[:instance].should == @tags['2']
|
22
24
|
|
23
|
-
Pirate.find(:searchInput => "free shipping coupon"
|
25
|
+
Pirate.find(:searchInput => "free shipping coupon")
|
24
26
|
Pirate.result[:redirect].should == 'levenshtein'
|
25
27
|
Pirate.result[:instance].should == @tags['3']
|
26
28
|
|
27
|
-
Pirate.find(:searchInput => "Discount Contact"
|
29
|
+
Pirate.find(:searchInput => "Discount Contact")
|
28
30
|
Pirate.result[:redirect].should == 'levenshtein'
|
29
31
|
Pirate.result[:instance].should == @stores['6']
|
30
32
|
end
|
@@ -36,7 +38,7 @@ describe "Pirate" do
|
|
36
38
|
[['1', "Abe's of Maine"], ['2', "E.L.F."], ['3', "80's Purple"], ['4', "Adagio Teas"],
|
37
39
|
['5', "Akademiks"], ['6', "Discount Contact Lenses"], ['7', "Lens.com"], ['8', "Brylane Home"],
|
38
40
|
['9', "Directly Home"], ['10', "HomeClick"]].each do |store|
|
39
|
-
@stores[store[0]] =
|
41
|
+
@stores[store[0]] = Store.create(:name => store[1], :state => 'approved')
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
@@ -89,7 +91,7 @@ describe "Pirate" do
|
|
89
91
|
[['1', "Abe's of Maine"], ['2', "E.L.F."], ['3', "80's Purple"], ['4', "Adagio Teas"],
|
90
92
|
['5', "Akademiks"], ['6', "Discount Contact Lenses"], ['7', "Lens.com"], ['8', "Brylane Home"],
|
91
93
|
['9', "Directly Home"], ['10', "HomeClick"]].each do |tag|
|
92
|
-
@tags[tag[0]] =
|
94
|
+
@tags[tag[0]] = Tag.create(:name => tag[1])
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,107 @@
|
|
1
|
+
# refer to https://github.com/binarylogic/searchlogic/blob/master/spec/spec_helper.rb
|
2
|
+
|
1
3
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
4
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
|
5
|
+
|
6
|
+
require 'spec'
|
4
7
|
require 'pirate'
|
8
|
+
require 'rubygems'
|
9
|
+
#require 'ruby-debug'
|
10
|
+
|
11
|
+
ENV['TZ'] = 'UTC'
|
12
|
+
Time.zone = 'Eastern Time (US & Canada)'
|
5
13
|
|
6
|
-
|
7
|
-
|
8
|
-
|
14
|
+
RAILS_ENV = 'test'
|
15
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
16
|
+
ActiveRecord::Base.configurations[RAILS_ENV] = { 'adapter' => "sqlite3" }
|
9
17
|
|
10
|
-
|
18
|
+
ActiveRecord::Schema.verbose = false
|
19
|
+
ActiveRecord::Schema.define(:version => 1) do
|
20
|
+
create_table :stores do |t|
|
21
|
+
t.string :name
|
22
|
+
t.string :homepage
|
23
|
+
t.string :state
|
24
|
+
end
|
11
25
|
|
26
|
+
create_table :deals do |t|
|
27
|
+
t.string :name
|
28
|
+
t.text :description
|
29
|
+
t.string :state
|
30
|
+
t.integer :store_id
|
31
|
+
t.integer :store_order
|
32
|
+
end
|
33
|
+
|
34
|
+
create_table :tags do |t|
|
35
|
+
t.string :name
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Spec::Runner.configure do |config|
|
40
|
+
config.before(:each) do
|
41
|
+
class ::Store < ActiveRecord::Base
|
42
|
+
named_scope :approved, :conditions => { :state => "approved" }, :order => 'stores.name ASC'
|
43
|
+
named_scope :remove_punct_from_name, lambda { |query| { :conditions => ["LOWER(REPLACE(REPLACE(REPLACE(name,\"'\",''), '-', ''), '.', '')) LIKE ?", "%#{query}%"] } }
|
44
|
+
|
45
|
+
def self.active
|
46
|
+
approved
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
class ::Deal < ActiveRecord::Base
|
52
|
+
begin
|
53
|
+
acts_as_taggable_on :tags
|
54
|
+
rescue
|
55
|
+
"Error when loading acts_as_taggable_on"
|
56
|
+
end
|
57
|
+
|
58
|
+
belongs_to :store
|
59
|
+
|
60
|
+
named_scope :ordered, :order => "store_order ASC"
|
61
|
+
named_scope :approved, :conditions => { :state => "approved" }, :order => 'name ASC'
|
62
|
+
|
63
|
+
def self.active
|
64
|
+
approved
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.related_tags(input)
|
68
|
+
vars = []
|
69
|
+
clauses = ""
|
70
|
+
input.split(" ").each do |word|
|
71
|
+
vars << word
|
72
|
+
vars << word.upcase
|
73
|
+
vars << word.downcase
|
74
|
+
end
|
75
|
+
|
76
|
+
vars.each_with_index do |var,idx|
|
77
|
+
clauses << "name LIKE ?"
|
78
|
+
clauses << " or " if (idx+1) < vars.size
|
79
|
+
end
|
80
|
+
conditions = [clauses] + vars
|
81
|
+
tags = Tag.find(:all,:conditions => conditions)
|
82
|
+
|
83
|
+
if tags.size > 0
|
84
|
+
return self.active.tagged_with(tags.collect {|tag| tag.name}.join(","))
|
85
|
+
else
|
86
|
+
return []
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class ::Coupon < Deal
|
92
|
+
end
|
93
|
+
|
94
|
+
class ::Tag < ActiveRecord::Base
|
95
|
+
end
|
96
|
+
|
97
|
+
::Store.destroy_all
|
98
|
+
::Deal.destroy_all
|
99
|
+
::Tag.destroy_all
|
100
|
+
end
|
101
|
+
|
102
|
+
config.after(:each) do
|
103
|
+
Object.send(:remove_const, :Store)
|
104
|
+
Object.send(:remove_const, :Coupon)
|
105
|
+
Object.send(:remove_const, :Tag)
|
106
|
+
end
|
12
107
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pirate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Hsu
|
@@ -15,51 +15,55 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-03-21 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: bundler
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 23
|
30
30
|
segments:
|
31
|
+
- 1
|
31
32
|
- 0
|
32
|
-
|
33
|
+
- 0
|
34
|
+
version: 1.0.0
|
33
35
|
type: :runtime
|
34
36
|
version_requirements: *id001
|
35
37
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
38
|
+
name: activerecord
|
37
39
|
prerelease: false
|
38
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
41
|
none: false
|
40
42
|
requirements:
|
41
|
-
- - "
|
43
|
+
- - "="
|
42
44
|
- !ruby/object:Gem::Version
|
43
|
-
hash:
|
45
|
+
hash: 17
|
44
46
|
segments:
|
45
|
-
-
|
46
|
-
|
47
|
+
- 2
|
48
|
+
- 3
|
49
|
+
- 9
|
50
|
+
version: 2.3.9
|
47
51
|
type: :runtime
|
48
52
|
version_requirements: *id002
|
49
53
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
54
|
+
name: activesupport
|
51
55
|
prerelease: false
|
52
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
57
|
none: false
|
54
58
|
requirements:
|
55
59
|
- - "="
|
56
60
|
- !ruby/object:Gem::Version
|
57
|
-
hash:
|
61
|
+
hash: 17
|
58
62
|
segments:
|
59
63
|
- 2
|
60
|
-
-
|
61
|
-
-
|
62
|
-
version: 2.
|
64
|
+
- 3
|
65
|
+
- 9
|
66
|
+
version: 2.3.9
|
63
67
|
type: :runtime
|
64
68
|
version_requirements: *id003
|
65
69
|
- !ruby/object:Gem::Dependency
|
@@ -79,110 +83,97 @@ dependencies:
|
|
79
83
|
type: :runtime
|
80
84
|
version_requirements: *id004
|
81
85
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
86
|
+
name: searchlogic
|
83
87
|
prerelease: false
|
84
88
|
requirement: &id005 !ruby/object:Gem::Requirement
|
85
89
|
none: false
|
86
90
|
requirements:
|
87
|
-
- -
|
91
|
+
- - "="
|
88
92
|
- !ruby/object:Gem::Version
|
89
|
-
hash:
|
93
|
+
hash: 41
|
90
94
|
segments:
|
91
|
-
-
|
92
|
-
-
|
93
|
-
-
|
94
|
-
version:
|
95
|
-
type: :
|
95
|
+
- 2
|
96
|
+
- 4
|
97
|
+
- 27
|
98
|
+
version: 2.4.27
|
99
|
+
type: :runtime
|
96
100
|
version_requirements: *id005
|
97
101
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
102
|
+
name: will_paginate
|
99
103
|
prerelease: false
|
100
104
|
requirement: &id006 !ruby/object:Gem::Requirement
|
101
105
|
none: false
|
102
106
|
requirements:
|
103
|
-
- -
|
107
|
+
- - "="
|
104
108
|
- !ruby/object:Gem::Version
|
105
|
-
hash:
|
109
|
+
hash: 29
|
106
110
|
segments:
|
107
|
-
-
|
108
|
-
-
|
109
|
-
-
|
110
|
-
version:
|
111
|
-
type: :
|
111
|
+
- 2
|
112
|
+
- 3
|
113
|
+
- 15
|
114
|
+
version: 2.3.15
|
115
|
+
type: :runtime
|
112
116
|
version_requirements: *id006
|
113
117
|
- !ruby/object:Gem::Dependency
|
114
|
-
name:
|
118
|
+
name: acts-as-taggable-on
|
115
119
|
prerelease: false
|
116
120
|
requirement: &id007 !ruby/object:Gem::Requirement
|
117
121
|
none: false
|
118
122
|
requirements:
|
119
|
-
- -
|
123
|
+
- - "="
|
120
124
|
- !ruby/object:Gem::Version
|
121
|
-
hash:
|
125
|
+
hash: 9
|
122
126
|
segments:
|
123
|
-
- 1
|
124
|
-
- 5
|
125
127
|
- 2
|
126
|
-
|
127
|
-
|
128
|
+
- 0
|
129
|
+
- 3
|
130
|
+
version: 2.0.3
|
131
|
+
type: :runtime
|
128
132
|
version_requirements: *id007
|
129
133
|
- !ruby/object:Gem::Dependency
|
130
|
-
name:
|
134
|
+
name: rspec
|
131
135
|
prerelease: false
|
132
136
|
requirement: &id008 !ruby/object:Gem::Requirement
|
133
137
|
none: false
|
134
138
|
requirements:
|
135
|
-
- -
|
139
|
+
- - ~>
|
136
140
|
- !ruby/object:Gem::Version
|
137
|
-
hash:
|
141
|
+
hash: 27
|
138
142
|
segments:
|
143
|
+
- 1
|
144
|
+
- 3
|
139
145
|
- 0
|
140
|
-
version:
|
141
|
-
type: :
|
146
|
+
version: 1.3.0
|
147
|
+
type: :runtime
|
142
148
|
version_requirements: *id008
|
143
149
|
- !ruby/object:Gem::Dependency
|
144
|
-
name:
|
150
|
+
name: sqlite3
|
145
151
|
prerelease: false
|
146
152
|
requirement: &id009 !ruby/object:Gem::Requirement
|
147
153
|
none: false
|
148
154
|
requirements:
|
149
|
-
- - "
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
hash: 41
|
152
|
-
segments:
|
153
|
-
- 2
|
154
|
-
- 4
|
155
|
-
- 27
|
156
|
-
version: 2.4.27
|
157
|
-
type: :runtime
|
158
|
-
version_requirements: *id009
|
159
|
-
- !ruby/object:Gem::Dependency
|
160
|
-
name: amatch
|
161
|
-
prerelease: false
|
162
|
-
requirement: &id010 !ruby/object:Gem::Requirement
|
163
|
-
none: false
|
164
|
-
requirements:
|
165
|
-
- - ">="
|
155
|
+
- - "="
|
166
156
|
- !ruby/object:Gem::Version
|
167
157
|
hash: 29
|
168
158
|
segments:
|
169
|
-
-
|
170
|
-
-
|
171
|
-
-
|
172
|
-
version:
|
159
|
+
- 1
|
160
|
+
- 3
|
161
|
+
- 3
|
162
|
+
version: 1.3.3
|
173
163
|
type: :runtime
|
174
|
-
version_requirements: *
|
164
|
+
version_requirements: *id009
|
175
165
|
description: Custom search function for 58Phases
|
176
|
-
email:
|
166
|
+
email:
|
167
|
+
- david@yibs.com
|
177
168
|
executables: []
|
178
169
|
|
179
170
|
extensions: []
|
180
171
|
|
181
|
-
extra_rdoc_files:
|
182
|
-
|
183
|
-
- README.rdoc
|
172
|
+
extra_rdoc_files: []
|
173
|
+
|
184
174
|
files:
|
185
175
|
- .document
|
176
|
+
- .gitignore
|
186
177
|
- .rspec
|
187
178
|
- Gemfile
|
188
179
|
- Gemfile.lock
|
@@ -191,13 +182,14 @@ files:
|
|
191
182
|
- Rakefile
|
192
183
|
- VERSION
|
193
184
|
- lib/pirate.rb
|
185
|
+
- lib/pirate/version.rb
|
194
186
|
- pirate.gemspec
|
195
187
|
- spec/pirate_spec.rb
|
196
188
|
- spec/spec_helper.rb
|
197
189
|
has_rdoc: true
|
198
|
-
homepage: http://
|
199
|
-
licenses:
|
200
|
-
|
190
|
+
homepage: http://rubygems.org/gems/pirate
|
191
|
+
licenses: []
|
192
|
+
|
201
193
|
post_install_message:
|
202
194
|
rdoc_options: []
|
203
195
|
|
@@ -223,8 +215,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
223
215
|
version: "0"
|
224
216
|
requirements: []
|
225
217
|
|
226
|
-
rubyforge_project:
|
227
|
-
rubygems_version: 1.
|
218
|
+
rubyforge_project: pirate
|
219
|
+
rubygems_version: 1.4.2
|
228
220
|
signing_key:
|
229
221
|
specification_version: 3
|
230
222
|
summary: Custom search function for 58Phases
|