sqlite3_ar_regexp 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sqlite3_ar_regexp.gemspec
4
+ gemspec
@@ -0,0 +1,12 @@
1
+ # SQLite3 ActiveRecord REGEXP
2
+ This adds REGEXP support to SQLite3 in ActiveRecord.
3
+
4
+ ## Installation
5
+ $ gem install sqlite3_ar_regexp
6
+
7
+ If you're using Bundler, add this to your Gemfile.
8
+
9
+ gem 'sqlite3_ar_regexp'
10
+
11
+ ## Credits
12
+ The original code for this was done by Joe Yates and can be found at http://titusd.co.uk/2010/01/31/regular-expressions-in-sqlite/.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ ## 1.0.0
2
+ * initial release
@@ -0,0 +1,6 @@
1
+ require 'active_record'
2
+ require 'active_record/connection_adapters/sqlite3_adapter'
3
+ require 'sqlite3_ar_regexp/extension'
4
+ require 'sqlite3_ar_regexp/version'
5
+
6
+ ActiveRecord::ConnectionAdapters::SQLite3Adapter.send(:include, SQLite3ARRegexp::Extension)
@@ -0,0 +1,21 @@
1
+ # borrowed from http://titusd.co.uk/2010/01/31/regular-expressions-in-sqlite/
2
+
3
+ module SQLite3ARRegexp
4
+ module Extension
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ def initialize(db, logger, config)
9
+ super
10
+ db.create_function('regexp', 2) do |func, pattern, expression|
11
+ regexp = Regexp.new(pattern.to_s, Regexp::IGNORECASE)
12
+ if expression.to_s.match(regexp)
13
+ func.result = 1
14
+ else
15
+ func.result = 0
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module SQLite3ARRegexp
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,17 @@
1
+ require 'sqlite3_ar_regexp'
2
+
3
+ describe 'SQLite3ARRegexp::Extension' do
4
+ before(:all) do
5
+ ActiveRecord::Base.establish_connection(
6
+ :adapter => 'sqlite3',
7
+ :database => 'spec/test.sqlite3'
8
+ )
9
+
10
+ class NobelPrizeWinner < ActiveRecord::Base
11
+ end
12
+ end
13
+
14
+ it 'should give ActiveRecord::ConnectionAdapters::SQLite3Adapter "REGEXP" support' do
15
+ NobelPrizeWinner.where('first_name REGEXP "al|ma"').count.should == 3
16
+ end
17
+ end
Binary file
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sqlite3_ar_regexp/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sqlite3_ar_regexp"
7
+ s.version = SQLite3ARRegexp::VERSION
8
+ s.authors = ["Aaron Lasseigne"]
9
+ s.email = ["alasseigne@sei-mi.com"]
10
+ s.homepage = "https://github.com/sei-mi/sqlite3_ar_regexp"
11
+ s.summary = %q{Adds REGEXP support for SQLite3 in ActiveRecord.}
12
+ s.description = %q{Adds REGEXP support for SQLite3 in ActiveRecord.}
13
+
14
+ s.rubyforge_project = "sqlite3_ar_regexp"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency 'sqlite3'
22
+ s.add_runtime_dependency 'activerecord', '~> 3.0'
23
+
24
+ s.add_development_dependency 'rspec'
25
+ s.add_development_dependency 'rake'
26
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sqlite3_ar_regexp
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aaron Lasseigne
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-11 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sqlite3
16
+ requirement: &70304124621440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70304124621440
25
+ - !ruby/object:Gem::Dependency
26
+ name: activerecord
27
+ requirement: &70304124620940 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70304124620940
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70304124620520 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70304124620520
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &70304124620060 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70304124620060
58
+ description: Adds REGEXP support for SQLite3 in ActiveRecord.
59
+ email:
60
+ - alasseigne@sei-mi.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - Gemfile
67
+ - README.markdown
68
+ - Rakefile
69
+ - changelog.markdown
70
+ - lib/sqlite3_ar_regexp.rb
71
+ - lib/sqlite3_ar_regexp/extension.rb
72
+ - lib/sqlite3_ar_regexp/version.rb
73
+ - spec/regexp_spec.rb
74
+ - spec/test.sqlite3
75
+ - sqlite3_ar_regexp.gemspec
76
+ homepage: https://github.com/sei-mi/sqlite3_ar_regexp
77
+ licenses: []
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ segments:
89
+ - 0
90
+ hash: 1598588507831330270
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ segments:
98
+ - 0
99
+ hash: 1598588507831330270
100
+ requirements: []
101
+ rubyforge_project: sqlite3_ar_regexp
102
+ rubygems_version: 1.8.6
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Adds REGEXP support for SQLite3 in ActiveRecord.
106
+ test_files:
107
+ - spec/regexp_spec.rb
108
+ - spec/test.sqlite3