soundcord_rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +87 -0
- data/Rakefile +1 -0
- data/lib/generators/initializer_generator.rb +10 -0
- data/lib/generators/soundcord_rails/USAGE +0 -0
- data/lib/generators/soundcord_rails/soundcord_rails_generator.rb +32 -0
- data/lib/generators/soundcord_rails/templates/soundcord_rails_migration.rb.erb +15 -0
- data/lib/soundcord_rails/glue.rb +8 -0
- data/lib/soundcord_rails/railtie.rb +25 -0
- data/lib/soundcord_rails/version.rb +3 -0
- data/lib/soundcord_rails.rb +50 -0
- data/soundcord_rails.gemspec +22 -0
- metadata +75 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#SoundCord Rails
|
2
|
+
SoundCord Rails is intended as an easy phonetic engine for Active Record. The intent behind it was to keep setup, and dealing with it, as easy as possible and to treat phonetic database searchs as much like other attributes as possible. This means that the possible results for a query are maximized by the phonetic algorithm, even when the input has writing errors.
|
3
|
+
|
4
|
+
The basics of soundcord_rails are quite simple: Declare that your model has a phonetic field with the `phonetized` method and give it a name.
|
5
|
+
|
6
|
+
Soundcord_rails will automatically set its phonetized counterpart.
|
7
|
+
|
8
|
+
##Installation
|
9
|
+
SoundCord Rails is distributed as a gem, which is how it should be used is your app.
|
10
|
+
|
11
|
+
Include the gem in you gemfile.
|
12
|
+
|
13
|
+
```
|
14
|
+
gem "soundcord_rails"
|
15
|
+
```
|
16
|
+
|
17
|
+
Or, if you want to get the latest, you can get master from the main soundcord_rails repository:
|
18
|
+
|
19
|
+
```
|
20
|
+
gem "soundcord_rails", :git => "git@github.com:lukasalexandre/soundcord_rails.git"
|
21
|
+
```
|
22
|
+
|
23
|
+
If you`are trying to use features that don't seem to be in the latest released gem, but are mentioned in the README, then you probably need to specify the master branch if you want to use them. This README is probably ahead of the latest released version, if you're reading it on GitHub.
|
24
|
+
|
25
|
+
##Quick start
|
26
|
+
In your model:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Class User < ActiveRecord::Base
|
30
|
+
phonetized :name
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
In your migrations:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
class addPhonetizedColumnsToUsers < ActiveRecord::Migration
|
38
|
+
def self.up
|
39
|
+
change_table :users do |t|
|
40
|
+
t.string :name_phonetized
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.down
|
45
|
+
remove_column :users, :name_phonetized
|
46
|
+
end
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
Or you can use migration generator: `rails generate soundcord_rails user name`
|
51
|
+
|
52
|
+
##Information
|
53
|
+
|
54
|
+
###To do:
|
55
|
+
|
56
|
+
* Add initializer options;
|
57
|
+
* Search within database.
|
58
|
+
|
59
|
+
##How to contribute
|
60
|
+
Please ensure that you provide appropriate test coverage and ensure the documentation is up-to-date. It is encouraged that you perform changes in a clean topic branch rather than a master and that you create a pull request for them. This will facilitate discussion and revision.
|
61
|
+
|
62
|
+
Please be clean, keep your commits atomic and with the smallest possible logical change. This will increase the likelihood of your submission to be used.
|
63
|
+
|
64
|
+
###Bug reports
|
65
|
+
|
66
|
+
If you discover any bugs, feel free to create an issue on GitHub. Please add as much information as possible to help us fixing the possible bug.
|
67
|
+
|
68
|
+
https://github.com/lukasalexandre/soundcord_rails/issues
|
69
|
+
|
70
|
+
##License
|
71
|
+
Copyright (c) 2012 Lukas Alexandre. http://www.devinscene.com.br/
|
72
|
+
|
73
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
74
|
+
a copy of this software and associated documentation files (the
|
75
|
+
"Software"), to use, copy and modify copies of the Software, subject
|
76
|
+
to the following conditions:
|
77
|
+
|
78
|
+
The above copyright notice and this permission notice shall be
|
79
|
+
included in all copies or substantial portions of the Software.
|
80
|
+
|
81
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
82
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
83
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
84
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
85
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
86
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
87
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
class InitializerGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
|
6
|
+
desc "This generator creates an initializer file at config/initializers"
|
7
|
+
def copy_initializer_file
|
8
|
+
copy_file "initializer.rb", "config/initializers/#{file_name}.rb"
|
9
|
+
end
|
10
|
+
end
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
class SoundcordRailsGenerator < ActiveRecord::Generators::Base
|
4
|
+
desc "Create a migration to add soundcord-specific field to your model. " +
|
5
|
+
"The NAME argument is the name of your model, and the following " +
|
6
|
+
"arguments are the name of the columns to be phonetized"
|
7
|
+
|
8
|
+
argument :column_names, :required => true, :type => :array, :desc => "The names of the column(s) to phonetize.",
|
9
|
+
:banner => "field_one field_two field_three ..."
|
10
|
+
|
11
|
+
def self.source_root
|
12
|
+
@source_root ||= File.expand_path('../templates', __FILE__)
|
13
|
+
end
|
14
|
+
|
15
|
+
def generate_migration
|
16
|
+
migration_template "soundcord_rails_migration.rb.erb", "db/migrate/#{migration_file_name}"
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def migration_name
|
22
|
+
"add_phonetized_columns_#{column_names.join("_")}_to_#{name.underscore.pluralize}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def migration_file_name
|
26
|
+
"#{migration_name}.rb"
|
27
|
+
end
|
28
|
+
|
29
|
+
def migration_class_name
|
30
|
+
migration_name.camelize
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_table :<%= table_name %> do |t|
|
4
|
+
<% column_names.each do |column| -%>
|
5
|
+
t.string :<%= column %>_phonetized
|
6
|
+
<% end -%>
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
<% column_names.each do |column| -%>
|
12
|
+
remove_column :<%= table_name %>, :<%= column %>
|
13
|
+
<% end -%>
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'soundcord_rails'
|
2
|
+
require 'soundcord_rails/glue'
|
3
|
+
|
4
|
+
module SoundcordRails
|
5
|
+
require 'rails'
|
6
|
+
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
initializer 'soundcord_rails.insert_into_active_record' do |app|
|
9
|
+
ActiveSupport.on_load :active_record do
|
10
|
+
SoundcordRails::Railtie.insert
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Railtie
|
16
|
+
def self.insert
|
17
|
+
# SoundcordRails.options[:logger] = Rails.logger
|
18
|
+
|
19
|
+
if defined?(ActiveRecord)
|
20
|
+
# SoundcordRails.options[:logger] = ActiveRecord::Base.logger
|
21
|
+
ActiveRecord::Base.send(:include, SoundcordRails::Glue)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# SoundCord Rails is intended as an easy phonetic engine for Active Record.
|
2
|
+
# The intent behind it was to keep setup, and dealing with it, as easy as
|
3
|
+
# possible and to treat phonetic database searchs as much like other attributes
|
4
|
+
# as possible. This means that the possible results for a query are maximized by
|
5
|
+
# the phonetic algorithm, even when the input has writing errors.
|
6
|
+
#
|
7
|
+
# Author:: Lukas Alexandre
|
8
|
+
# Copyright:: Copyright (c) 2012 thoughtbot, inc.
|
9
|
+
# License:: MIT License (http://www.opensource.org/licenses/mit-license.php)
|
10
|
+
|
11
|
+
require "soundcord_rails/version"
|
12
|
+
require 'soundcord'
|
13
|
+
|
14
|
+
require 'soundcord_rails/railtie' if defined?(Rails)
|
15
|
+
|
16
|
+
# The base module that gets included in ActiveRecord::Base. See the
|
17
|
+
# documentation for SoundcordRails::ClassMethods for more useful information.
|
18
|
+
module SoundcordRails
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
# +phonetized+ gives the class, it is called on, an attribute that maps to the phonetized
|
22
|
+
# version of him self. The phonetized field will be automatically filled upon record +save+.
|
23
|
+
# Likewise, if the attribute is set to +nil+ is the phonetized field will *not* be deleted
|
24
|
+
# until +save+ is called.
|
25
|
+
#
|
26
|
+
# class Person < ActiveRecord::Base
|
27
|
+
# phonetized :name
|
28
|
+
# end
|
29
|
+
def phonetized(name)
|
30
|
+
|
31
|
+
if phonetized_definitions.nil?
|
32
|
+
self.phonetized_definitions = {}
|
33
|
+
else
|
34
|
+
self.phonetized_definitions = self.phonetized_definitions.dup
|
35
|
+
end
|
36
|
+
|
37
|
+
define_method "update_#{name}_phonetized" do
|
38
|
+
send("#{name}_phonetized=", send(name).phonetize)
|
39
|
+
end
|
40
|
+
|
41
|
+
before_save "update_#{name}_phonetized"
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns the attachment definitions defined by each call to
|
45
|
+
# has_attached_file.
|
46
|
+
def phonetized_definitions
|
47
|
+
self.phonetized_definitions
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "soundcord_rails/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "soundcord_rails"
|
7
|
+
s.version = SoundcordRails::VERSION
|
8
|
+
s.authors = ["Lukas Alexandre"]
|
9
|
+
s.email = ["lukeskytm@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/lukasalexandre/soundcord_rails"
|
11
|
+
s.summary = %q{Phonetic fields as attributes for ActiveRecord}
|
12
|
+
s.description = %q{Easy phonetic comparisons for ActiveRecord}
|
13
|
+
|
14
|
+
s.rubyforge_project = "soundcordrails"
|
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_dependency 'soundcord', '~> 0.1.1'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: soundcord_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lukas Alexandre
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: soundcord
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.1.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.1.1
|
30
|
+
description: Easy phonetic comparisons for ActiveRecord
|
31
|
+
email:
|
32
|
+
- lukeskytm@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .travis.yml
|
39
|
+
- Gemfile
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/generators/initializer_generator.rb
|
43
|
+
- lib/generators/soundcord_rails/USAGE
|
44
|
+
- lib/generators/soundcord_rails/soundcord_rails_generator.rb
|
45
|
+
- lib/generators/soundcord_rails/templates/soundcord_rails_migration.rb.erb
|
46
|
+
- lib/soundcord_rails.rb
|
47
|
+
- lib/soundcord_rails/glue.rb
|
48
|
+
- lib/soundcord_rails/railtie.rb
|
49
|
+
- lib/soundcord_rails/version.rb
|
50
|
+
- soundcord_rails.gemspec
|
51
|
+
homepage: https://github.com/lukasalexandre/soundcord_rails
|
52
|
+
licenses: []
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project: soundcordrails
|
71
|
+
rubygems_version: 1.8.24
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Phonetic fields as attributes for ActiveRecord
|
75
|
+
test_files: []
|