Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Adds compatibility with more Rails versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mezis committed Feb 20, 2013
1 parent 099b9ec commit 81f363f
Show file tree
Hide file tree
Showing 15 changed files with 303 additions and 10 deletions.
15 changes: 15 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
appraise "rails23" do
gem "activerecord", "~> 2.3.0"
end

appraise "rails30" do
gem "activerecord", "~> 3.0.0"
end

appraise "rails31" do
gem "activerecord", "~> 3.1.0"
end

appraise "rails32" do
gem "activerecord", "~> 3.2.0"
end
24 changes: 19 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
PATH
remote: .
specs:
fuzzily (0.0.3)
activerecord (~> 2.3)
fuzzily (0.1.0)
activerecord (>= 2.3.17)

GEM
remote: https://rubygems.org/
specs:
activerecord (2.3.17)
activesupport (= 2.3.17)
activesupport (2.3.17)
activemodel (3.2.12)
activesupport (= 3.2.12)
builder (~> 3.0.0)
activerecord (3.2.12)
activemodel (= 3.2.12)
activesupport (= 3.2.12)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activesupport (3.2.12)
i18n (~> 0.6)
multi_json (~> 1.0)
appraisal (0.5.1)
bundler
rake
arel (3.0.2)
builder (3.0.4)
coderay (1.0.9)
diff-lcs (1.1.3)
i18n (0.6.1)
method_source (0.8.1)
multi_json (1.6.1)
pry (0.9.12)
coderay (~> 1.0.5)
method_source (~> 0.8)
Expand All @@ -33,6 +45,7 @@ GEM
rspec-mocks (2.12.2)
slop (3.4.3)
sqlite3 (1.3.7)
tzinfo (0.3.35)

PLATFORMS
ruby
Expand All @@ -42,5 +55,6 @@ DEPENDENCIES
fuzzily!
pry
pry-nav
rake
rspec
sqlite3
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ A fast, [trigram](http://en.wikipedia.org/wiki/N-gram)-based, database-backed [f

Loosely inspired from an [old blog post](http://unirec.blogspot.co.uk/2007/12/live-fuzzy-search-using-n-grams-in.html).

Compatible with ActiveRecord 2.3, 3.0, 3.1, 3.2.

## Installation

Add this line to your application's Gemfile:
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "bundler/gem_tasks"
require 'rspec/core/rake_task'
require 'appraisal'

RSpec::Core::RakeTask.new(:spec)

Expand Down
3 changes: 2 additions & 1 deletion fuzzily.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ Gem::Specification.new do |gem|
gem.summary = %q{A fast, trigram-based, database-backed fuzzy string search/match engine for Rails.}
gem.homepage = ""

gem.add_runtime_dependency 'activerecord', '~> 2.3'
gem.add_runtime_dependency 'activerecord', '>= 2.3.17'

gem.add_development_dependency 'rspec'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'appraisal'
gem.add_development_dependency 'pry'
gem.add_development_dependency 'pry-nav'
Expand Down
7 changes: 7 additions & 0 deletions gemfiles/rails23.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 2.3.0"

gemspec :path=>"../"
48 changes: 48 additions & 0 deletions gemfiles/rails23.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
PATH
remote: /Users/mezis/Dropbox/Development/fuzzily
specs:
fuzzily (0.1.0)
activerecord (>= 2.3.17)

GEM
remote: https://rubygems.org/
specs:
activerecord (2.3.17)
activesupport (= 2.3.17)
activesupport (2.3.17)
appraisal (0.5.1)
bundler
rake
coderay (1.0.9)
diff-lcs (1.1.3)
method_source (0.8.1)
pry (0.9.12)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
pry-nav (0.2.3)
pry (~> 0.9.10)
rake (10.0.3)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2)
slop (3.4.3)
sqlite3 (1.3.7)

PLATFORMS
ruby

DEPENDENCIES
activerecord (~> 2.3.0)
appraisal
fuzzily!
pry
pry-nav
rake
rspec
sqlite3
7 changes: 7 additions & 0 deletions gemfiles/rails30.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 3.0.0"

gemspec :path=>"../"
59 changes: 59 additions & 0 deletions gemfiles/rails30.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
PATH
remote: /Users/mezis/Dropbox/Development/fuzzily
specs:
fuzzily (0.1.0)
activerecord (>= 2.3.17)

GEM
remote: https://rubygems.org/
specs:
activemodel (3.0.20)
activesupport (= 3.0.20)
builder (~> 2.1.2)
i18n (~> 0.5.0)
activerecord (3.0.20)
activemodel (= 3.0.20)
activesupport (= 3.0.20)
arel (~> 2.0.10)
tzinfo (~> 0.3.23)
activesupport (3.0.20)
appraisal (0.5.1)
bundler
rake
arel (2.0.10)
builder (2.1.2)
coderay (1.0.9)
diff-lcs (1.1.3)
i18n (0.5.0)
method_source (0.8.1)
pry (0.9.12)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
pry-nav (0.2.3)
pry (~> 0.9.10)
rake (10.0.3)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2)
slop (3.4.3)
sqlite3 (1.3.7)
tzinfo (0.3.35)

PLATFORMS
ruby

DEPENDENCIES
activerecord (~> 3.0.0)
appraisal
fuzzily!
pry
pry-nav
rake
rspec
sqlite3
7 changes: 7 additions & 0 deletions gemfiles/rails31.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 3.1.0"

gemspec :path=>"../"
61 changes: 61 additions & 0 deletions gemfiles/rails31.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
PATH
remote: /Users/mezis/Dropbox/Development/fuzzily
specs:
fuzzily (0.1.0)
activerecord (>= 2.3.17)

GEM
remote: https://rubygems.org/
specs:
activemodel (3.1.11)
activesupport (= 3.1.11)
builder (~> 3.0.0)
i18n (~> 0.6)
activerecord (3.1.11)
activemodel (= 3.1.11)
activesupport (= 3.1.11)
arel (~> 2.2.3)
tzinfo (~> 0.3.29)
activesupport (3.1.11)
multi_json (~> 1.0)
appraisal (0.5.1)
bundler
rake
arel (2.2.3)
builder (3.0.4)
coderay (1.0.9)
diff-lcs (1.1.3)
i18n (0.6.1)
method_source (0.8.1)
multi_json (1.6.1)
pry (0.9.12)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
pry-nav (0.2.3)
pry (~> 0.9.10)
rake (10.0.3)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2)
slop (3.4.3)
sqlite3 (1.3.7)
tzinfo (0.3.35)

PLATFORMS
ruby

DEPENDENCIES
activerecord (~> 3.1.0)
appraisal
fuzzily!
pry
pry-nav
rake
rspec
sqlite3
7 changes: 7 additions & 0 deletions gemfiles/rails32.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 3.2.0"

gemspec :path=>"../"
61 changes: 61 additions & 0 deletions gemfiles/rails32.gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
PATH
remote: /Users/mezis/Dropbox/Development/fuzzily
specs:
fuzzily (0.1.0)
activerecord (>= 2.3.17)

GEM
remote: https://rubygems.org/
specs:
activemodel (3.2.12)
activesupport (= 3.2.12)
builder (~> 3.0.0)
activerecord (3.2.12)
activemodel (= 3.2.12)
activesupport (= 3.2.12)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activesupport (3.2.12)
i18n (~> 0.6)
multi_json (~> 1.0)
appraisal (0.5.1)
bundler
rake
arel (3.0.2)
builder (3.0.4)
coderay (1.0.9)
diff-lcs (1.1.3)
i18n (0.6.1)
method_source (0.8.1)
multi_json (1.6.1)
pry (0.9.12)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
pry-nav (0.2.3)
pry (~> 0.9.10)
rake (10.0.3)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2)
slop (3.4.3)
sqlite3 (1.3.7)
tzinfo (0.3.35)

PLATFORMS
ruby

DEPENDENCIES
activerecord (~> 3.2.0)
appraisal
fuzzily!
pry
pry-nav
rake
rspec
sqlite3
9 changes: 6 additions & 3 deletions lib/fuzzily/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module Model

def self.included(by)
by.ancestors.include?(ActiveRecord::Base) or raise 'Not included in an ActiveRecord subclass'

scope_method = ActiveRecord::VERSION::MAJOR == 2 ? :named_scope : :scope

by.class_eval do
return if class_variable_defined?(:@@fuzzily_trigram_model)

Expand All @@ -15,13 +18,13 @@ def self.included(by)
validates_presence_of :score
validates_presence_of :fuzzy_field

named_scope :for_model, lambda { |model| {
send scope_method, :for_model, lambda { |model| {
:conditions => { :owner_type => model.kind_of?(Class) ? model.name : model }
}}
named_scope :for_field, lambda { |field_name| {
send scope_method, :for_field, lambda { |field_name| {
:conditions => { :fuzzy_field => field_name }
}}
named_scope :with_trigram, lambda { |trigrams| {
send scope_method, :with_trigram, lambda { |trigrams| {
:conditions => { :trigram => trigrams }
}}

Expand Down
2 changes: 1 addition & 1 deletion lib/fuzzily/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Fuzzily
VERSION = "0.0.3"
VERSION = "0.1.0"
end

0 comments on commit 81f363f

Please sign in to comment.