person_name 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ /pkg/
2
+ Gemfile.lock
3
+ .idea
4
+ *.log
5
+ *.sqlite3
6
+ .bundle
7
+ spec/database.yml
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source :gemcutter
2
+
3
+ # Rails 3.0
4
+ gem 'rails', '3.0.0'
5
+ gem 'rspec', '2.0.0.beta.22'
6
+ gem 'sqlite3-ruby', :require => 'sqlite3'
7
+ gem 'mysql'
8
+ gem 'pg'
9
+ gem 'jeweler'
10
+ gem 'rcov'
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2010 Matthijs Groen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
@@ -0,0 +1,98 @@
1
+ Person Name
2
+ ===========
3
+ Person name is an active record plugin to add support for full names.
4
+ A persons name consists of the following parts: prefix, first_name, middle_name, intercalation, last_name and suffix
5
+
6
+ If you have to fill in a name for somebody, you have to display all those fields, and fill them in.
7
+ The goal is to make one field that can split up the name and assign it to the correct fields automatically.
8
+ You can also still use the more precise input if necessary.
9
+
10
+ Usage
11
+ =====
12
+
13
+ Small gem to insert easy person name behaviour into rails models
14
+
15
+ migration:
16
+
17
+ create_table :people do |t|
18
+ t.person_name :name
19
+ t.person_name :birth_name
20
+ t.boolean :female, :null => true
21
+
22
+ t.timestamps
23
+ end
24
+
25
+ In this case the following fields are created:
26
+
27
+ name_prefix
28
+ name_first_name
29
+ name_middle_name
30
+ name_intercalation
31
+ name_last_name
32
+ name_suffix
33
+
34
+ birth_name_prefix
35
+ birth_name_first_name
36
+ birth_name_middle_name
37
+ birth_name_intercalation
38
+ birth_name_last_name
39
+ birth_name_suffix
40
+
41
+ female
42
+ created_at
43
+ updated_at
44
+
45
+ model:
46
+
47
+ class Person < ActiveRecord::Base
48
+
49
+ has_person_name :name, :birth_name
50
+
51
+ end
52
+
53
+
54
+ Now put this thing to use:
55
+
56
+ p = Person.new
57
+ p.name = "Matthijs Jacobus Groen"
58
+ p.name.first_name # Matthijs
59
+ p.name.middle_name # Jacobus
60
+ p.name.last_name # Groen
61
+ p.name.short_name # M.J. Groen
62
+
63
+ p = Person.new
64
+ p.name = "Ariejan de Vroom"
65
+ p.name.first_name # Ariejan
66
+ p.name.intercalation # de
67
+ p.name.last_name # Vroom
68
+ p.name.full_last_name # de Vroom
69
+
70
+ p = Person.new
71
+ p.name = "Cornelia Maria Hendrika Damen-van Valkenberg"
72
+ p.name.first_name # Cornelia
73
+ p.name.middle_name # Maria Hendrika
74
+ p.name.last_name # Damen-van Valkenberg
75
+
76
+ Sometimes, things can go wrong:
77
+
78
+ p = Person.new
79
+ p.name = "Yolanthe Cabau van Kasbergen"
80
+ p.name.first_name # Yolanthe
81
+ p.name.middle_name # Cabau
82
+ p.name.intercalation # van
83
+ p.name.last_name # Kasbergen
84
+
85
+ But, if you correct it, it will remember it:
86
+
87
+ p.name.intercalation = nil
88
+ p.name.middle_name = nil
89
+ p.name.last_name = "Cabau van Kasbergen"
90
+
91
+ # and now change something:
92
+
93
+ p.name = "Yolanthe Truuske Cabau van Kasbergen"
94
+ p.name.first_name # Yolanthe
95
+ p.name.middle_name # Truuske
96
+ p.name.intercalation # nil
97
+ p.name.last_name # Cabau van Kasbergen
98
+
@@ -0,0 +1,62 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "person_name"
8
+ gem.summary = %Q{Easy editing of person names.}
9
+ gem.description = %Q{
10
+ Manages all person name fields (prefix, first name, middle name, intercalation, last name, suffix)
11
+ }
12
+ gem.email = "matthijs.groen@gmail.com"
13
+ gem.homepage = "http://matthijsgroen.posterous.com"
14
+ gem.authors = ["Matthijs Groen"]
15
+ #gem.add_development_dependency "shoulda"
16
+ gem.add_dependency "activerecord", "~> 3.0.0"
17
+ gem.add_dependency "activesupport", "~> 3.0.0"
18
+ gem.add_dependency "arel", "~> 1.0.1"
19
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
24
+ end
25
+
26
+ require 'rake/testtask'
27
+ Rake::TestTask.new(:test) do |test|
28
+ test.libs << 'lib' << 'test'
29
+ test.libs << 'vendor/rails/activerecord/lib'
30
+ test.libs << 'vendor/rails/activesupport/lib'
31
+ test.libs << 'vendor/arel/lib'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ begin
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ end
43
+ rescue LoadError
44
+ task :rcov do
45
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
46
+ end
47
+ end
48
+
49
+ # Don't check dependencies since we're testing with vendored libraries
50
+ # task :test => :check_dependencies
51
+
52
+ task :default => :test
53
+
54
+ require 'rake/rdoctask'
55
+ Rake::RDocTask.new do |rdoc|
56
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
57
+
58
+ rdoc.rdoc_dir = 'rdoc'
59
+ rdoc.title = "meta_where #{version}"
60
+ rdoc.rdoc_files.include('README*')
61
+ rdoc.rdoc_files.include('lib/**/*.rb')
62
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'person_name'
2
+ require 'person_name/migration_support'
3
+
4
+ ActiveRecord::ConnectionAdapters::TableDefinition.send :include, PersonName::MigrationSupport
5
+ ActiveRecord::Base.send :include, PersonName::ActiveRecord
@@ -0,0 +1,78 @@
1
+ module PersonName
2
+
3
+ module ActiveRecord
4
+
5
+ def self.included(base) # :nodoc:
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+
11
+ def has_person_names?
12
+ false
13
+ end
14
+
15
+ def has_person_name(*name_types)
16
+ name_types = name_types.to_a.flatten.compact.map(&:to_sym)
17
+ name_types << :name if name_types.empty?
18
+
19
+ if has_person_names?
20
+ write_inheritable_attribute(:name_types, (self.name_types + name_types).uniq)
21
+ else
22
+ write_inheritable_attribute(:name_types, name_types)
23
+ class_inheritable_reader(:name_types)
24
+
25
+ class_eval do
26
+ def self.has_person_names?
27
+ true
28
+ end
29
+
30
+ include PersonName::ActiveRecord::Core
31
+ end
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ module Core
38
+
39
+ def self.included(base)
40
+ base.send :include, PersonName::ActiveRecord::Core::InstanceMethods
41
+ base.extend PersonName::ActiveRecord::Core::ClassMethods
42
+ base.initialize_person_names
43
+ end
44
+
45
+ module ClassMethods
46
+ def initialize_person_names
47
+ name_types.map(&:to_s).each do |name_type|
48
+ class_eval %(
49
+ def #{name_type}
50
+ person_name_for('#{name_type}')
51
+ end
52
+
53
+ def #{name_type}= new_name
54
+ set_person_name_for('#{name_type}', new_name)
55
+ end
56
+ )
57
+ end
58
+ end
59
+ end
60
+
61
+ module InstanceMethods
62
+
63
+ def person_name_for field
64
+ @person_names ||= {}
65
+ @person_names[field] ||= PersonName::Name.new(field, self)
66
+ end
67
+
68
+ def set_person_name_for field, new_name
69
+ person_name_for(field).full_name = new_name
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
78
+ end
@@ -0,0 +1,12 @@
1
+
2
+ module PersonName::MigrationSupport
3
+
4
+ def person_name(name, *args)
5
+ options = args.extract_options!
6
+ name_parts = PersonName::Name::NAME_PARTS
7
+ name_parts.each do |part|
8
+ column("#{name}_#{part}".to_sym, :string, :null => true)
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,203 @@
1
+ class PersonName::Name
2
+
3
+ NAME_PARTS = %w(prefix first_name middle_name intercalation last_name suffix)
4
+
5
+ def initialize(naming_prefix, record)
6
+ @naming_prefix = naming_prefix
7
+ @record = record
8
+ end
9
+
10
+ def full_name
11
+ NAME_PARTS.collect { |p| self.send(p) }.compact.join " "
12
+ end
13
+
14
+ def full_name= new_name
15
+ # Matthijs Jacobus Groen
16
+ # Patricia Jose Huisman
17
+ # Thijs van de Biggelaar
18
+ # Michael Thijssens
19
+ # Maria Cornelia Hendrina Damen-van Valenberg
20
+ # Dirk Jan van den Abeele
21
+ # Yolanthe Cabau van Kasbergen
22
+ # Yolanthe Sneijder-Cabau
23
+ return if full_name == new_name # no changes
24
+
25
+ parts = new_name.split " "
26
+ names = []
27
+ stage = :prefix
28
+ remember = nil
29
+ parts.each_with_index do |part, index|
30
+ is_upcase = part.first == part.first.upcase
31
+ has_dash = part.include? "-"
32
+ is_last = (parts.length - 1) == index
33
+
34
+ fp = [remember, part].compact.join(" ")
35
+ remember = nil
36
+ did_remember = (fp != part)
37
+ if valid_prefix?(part) and stage == :prefix # if the part is a valid prefix, mark it as such
38
+ names = add_to_last_if :prefix, fp, names
39
+ elsif valid_suffix?(part) and stage == :name # if the part is a valid suffix, mark it as such
40
+ names = add_to_last_if :suffix, fp, names
41
+ elsif part == "-" # if the part is a dash
42
+ if last_stored = names.pop # retrieve the previous name part (if any) and store it with the dash
43
+ # for the part to come (remember)
44
+ remember = [last_stored[0], fp].compact.join(" ")
45
+ else
46
+ # if there is no previous part, just store the current part for later
47
+ remember = fp
48
+ end
49
+ elsif !is_upcase and !did_remember # intercalation words are never with a capital
50
+ names = add_to_last_if :intercalation, fp, names
51
+ stage = :name
52
+ elsif !is_upcase and did_remember
53
+ remember = fp
54
+ elsif is_upcase and !has_dash
55
+ names << [fp, :name]
56
+ stage = :name
57
+ elsif is_upcase and has_dash
58
+ if fp.ends_with? "-"
59
+ if is_last
60
+ names << [fp, :name]
61
+ stage = :name
62
+ else
63
+ remember = fp
64
+ end
65
+ else
66
+ if fp.starts_with?("-") and last_stored = names.pop
67
+ fp = [last_stored[0], fp].compact.join(" ")
68
+ end
69
+ dash_parts = fp.split "-"
70
+ if dash_parts.last.first == dash_parts.last.first.upcase
71
+ names << [fp, :name]
72
+ stage = :name
73
+ elsif is_last
74
+ names << [fp, :name]
75
+ stage = :name
76
+ else
77
+ remember = fp
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ new_name = {}
84
+ stage = O[:prefix]
85
+
86
+ names.each_with_index do |value, index|
87
+ name, name_type = *value
88
+ stage = recheck_stage(name, stage)
89
+
90
+ if name_type == :prefix and stage == O[:prefix]
91
+ elsif name_type == :suffix and (index == names.length - 1)
92
+ stage = [O[:suffix], stage].max
93
+ elsif name_type == :suffix and (index != names.length - 1)
94
+ name_type = :name
95
+ end
96
+
97
+ if name_type == :name
98
+ if (index == names.length - 1) or new_name[:intercalation]
99
+ stage = [O[:last_name], stage].max
100
+ else
101
+ if !new_name[:first_name]
102
+ stage = [O[:first_name], stage].max
103
+ else
104
+ stage = [O[:middle_name], stage].max
105
+ end
106
+ end
107
+ elsif name_type == :intercalation
108
+ stage = [O[:intercalation], stage].max
109
+ end
110
+ new_name = add_part(new_name, stage, name)
111
+ end
112
+ # assignments
113
+ NAME_PARTS.each do |part|
114
+ self.send "#{part}=", (new_name[part.to_sym] || "").blank? ? nil : new_name[part.to_sym]
115
+ end
116
+ end
117
+
118
+ def full_last_name
119
+ [:intercalation, :last_name, :suffix].collect { |p| self.send(p) }.compact.join " "
120
+ end
121
+
122
+ def short_name include_middle_names = true
123
+ parts = []
124
+ parts << "#{self.first_name.first.upcase}." if self.first_name
125
+ if include_middle_names and self.middle_name
126
+ names = self.middle_name.split(" ")
127
+ names.each do |name|
128
+ parts << "#{name.first.upcase}."
129
+ end
130
+ end
131
+ [parts.join, full_last_name] * " "
132
+ end
133
+
134
+ NAME_PARTS.each do |part|
135
+ define_method part do
136
+ @record.send("#{@naming_prefix}_#{part}")
137
+ end
138
+
139
+ define_method "#{part}=" do |value|
140
+ @record.send("#{@naming_prefix}_#{part}=", value)
141
+ end
142
+ end
143
+
144
+
145
+ def to_s
146
+ full_name
147
+ end
148
+
149
+ private
150
+
151
+ O = {
152
+ :prefix => 0,
153
+ :first_name => 1,
154
+ :middle_name => 2,
155
+ :intercalation => 3,
156
+ :last_name => 4,
157
+ :suffix => 5
158
+ }.freeze
159
+ OR = O.invert
160
+
161
+ def add_part new_name, part_score, part
162
+ part_name = OR[part_score]
163
+ new_name[part_name.to_sym] = [new_name[part_name.to_sym], part].compact.join(" ")
164
+ new_name
165
+ end
166
+
167
+ def recheck_stage value, stage
168
+ # test if the given value is already stored in the name right now
169
+ new_stage = stage
170
+ NAME_PARTS.each do |part|
171
+ part_values = (self.send(part) || "").split(" ")
172
+
173
+ part_score = O[part.to_sym]
174
+ if part_values.include? value
175
+ part_score = O[:first_name] if stage == O[:prefix] and part = :middle_name
176
+ new_stage = part_score if part_score > new_stage
177
+ return new_stage
178
+ end
179
+ end
180
+ stage
181
+ end
182
+
183
+ def add_to_last_if part, value, list
184
+ if list.last and list.last[1] == part
185
+ last_part = list.pop
186
+ list << [[last_part[0], value].compact.join(" "), part]
187
+ else
188
+ list << [value, part]
189
+ end
190
+ list
191
+ end
192
+
193
+ attr_reader :naming_prefix, :record
194
+
195
+ def valid_prefix? name_part
196
+ false
197
+ end
198
+
199
+ def valid_suffix? name_part
200
+ false
201
+ end
202
+
203
+ end
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{person_name}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Matthijs Groen"]
12
+ s.date = %q{2010-09-24}
13
+ s.description = %q{
14
+ Manages all person name fields (prefix, first name, middle name, intercalation, last name, suffix)
15
+ }
16
+ s.email = %q{matthijs.groen@gmail.com}
17
+ s.extra_rdoc_files = [
18
+ "README.markdown"
19
+ ]
20
+ s.files = [
21
+ ".gitignore",
22
+ "Gemfile",
23
+ "MIT-LICENSE",
24
+ "README.markdown",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "init.rb",
28
+ "lib/person_name.rb",
29
+ "lib/person_name/migration_support.rb",
30
+ "lib/person_name/name.rb",
31
+ "person_name.gemspec",
32
+ "spec/database.yml.sample",
33
+ "spec/models.rb",
34
+ "spec/person_name/has_person_name_spec.rb",
35
+ "spec/schema.rb",
36
+ "spec/spec_helper.rb"
37
+ ]
38
+ s.homepage = %q{http://matthijsgroen.posterous.com}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.7}
42
+ s.summary = %q{Easy editing of person names.}
43
+ s.test_files = [
44
+ "spec/person_name/has_person_name_spec.rb",
45
+ "spec/spec_helper.rb",
46
+ "spec/models.rb",
47
+ "spec/schema.rb"
48
+ ]
49
+
50
+ if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
+ s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.0"])
56
+ s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0"])
57
+ s.add_runtime_dependency(%q<arel>, ["~> 1.0.1"])
58
+ else
59
+ s.add_dependency(%q<activerecord>, ["~> 3.0.0"])
60
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
61
+ s.add_dependency(%q<arel>, ["~> 1.0.1"])
62
+ end
63
+ else
64
+ s.add_dependency(%q<activerecord>, ["~> 3.0.0"])
65
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
66
+ s.add_dependency(%q<arel>, ["~> 1.0.1"])
67
+ end
68
+ end
69
+
@@ -0,0 +1,17 @@
1
+ sqlite3:
2
+ adapter: sqlite3
3
+ database: has_person_name.sqlite3
4
+
5
+ mysql:
6
+ adapter: mysql
7
+ hostname: localhost
8
+ username: root
9
+ password:
10
+ database: has_person_name
11
+
12
+ postgresql:
13
+ adapter: postgresql
14
+ hostname: localhost
15
+ username: postgres
16
+ password:
17
+ database: has_person_name
@@ -0,0 +1,4 @@
1
+ class Person < ActiveRecord::Base
2
+ has_person_name
3
+ end
4
+
@@ -0,0 +1,96 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "Has Person Name" do
4
+ before(:each) do
5
+ clean_database!
6
+ end
7
+
8
+ describe "Automatic name assignment" do
9
+ before(:each) do
10
+ clean_database!
11
+ @person = Person.new
12
+ end
13
+
14
+ it "should have an accessor for the defined name fields" do
15
+ @person.should respond_to(:name)
16
+ end
17
+
18
+ end
19
+
20
+ describe "Automatic name assignment" do
21
+ before(:each) do
22
+ clean_database!
23
+ @person = Person.new
24
+ end
25
+
26
+ it "should assign name parts to the correct fields" do
27
+ @person.name = "Matthijs Groen"
28
+ @person.name.first_name.should == "Matthijs"
29
+ end
30
+
31
+ end
32
+
33
+ # it "should provide a class method 'taggable?' that is false for untaggable models" do
34
+ # UntaggableModel.should_not be_taggable
35
+ # end
36
+
37
+ # describe "Taggable Method Generation" do
38
+ # before(:each) do
39
+ # clean_database!
40
+ # TaggableModel.write_inheritable_attribute(:tag_types, [])
41
+ # TaggableModel.acts_as_taggable_on(:tags, :languages, :skills, :needs, :offerings)
42
+ # @taggable = TaggableModel.new(:name => "Bob Jones")
43
+ # end
44
+ #
45
+ # it "should respond 'true' to taggable?" do
46
+ # @taggable.class.should be_taggable
47
+ # end
48
+ #
49
+ # it "should create a class attribute for tag types" do
50
+ # @taggable.class.should respond_to(:tag_types)
51
+ # end
52
+ #
53
+ # it "should create an instance attribute for tag types" do
54
+ # @taggable.should respond_to(:tag_types)
55
+ # end
56
+ #
57
+ # it "should have all tag types" do
58
+ # @taggable.tag_types.should == [:tags, :languages, :skills, :needs, :offerings]
59
+ # end
60
+ #
61
+ # it "should generate an association for each tag type" do
62
+ # @taggable.should respond_to(:tags, :skills, :languages)
63
+ # end
64
+ #
65
+ # it "should add tagged_with and tag_counts to singleton" do
66
+ # TaggableModel.should respond_to(:tagged_with, :tag_counts)
67
+ # end
68
+ #
69
+ # it "should generate a tag_list accessor/setter for each tag type" do
70
+ # @taggable.should respond_to(:tag_list, :skill_list, :language_list)
71
+ # @taggable.should respond_to(:tag_list=, :skill_list=, :language_list=)
72
+ # end
73
+ #
74
+ # it "should generate a tag_list accessor, that includes owned tags, for each tag type" do
75
+ # @taggable.should respond_to(:all_tags_list, :all_skills_list, :all_languages_list)
76
+ # end
77
+ # end
78
+
79
+ # describe "Single Table Inheritance" do
80
+ # before do
81
+ # @taggable = TaggableModel.new(:name => "taggable")
82
+ # @inherited_same = InheritingTaggableModel.new(:name => "inherited same")
83
+ # @inherited_different = AlteredInheritingTaggableModel.new(:name => "inherited different")
84
+ # end
85
+ #
86
+ # it "should pass on tag contexts to STI-inherited models" do
87
+ # @inherited_same.should respond_to(:tag_list, :skill_list, :language_list)
88
+ # @inherited_different.should respond_to(:tag_list, :skill_list, :language_list)
89
+ # end
90
+ #
91
+ # it "should have tag contexts added in altered STI models" do
92
+ # @inherited_different.should respond_to(:part_list)
93
+ # end
94
+ # end
95
+
96
+ end
@@ -0,0 +1,11 @@
1
+ ActiveRecord::Schema.define :version => 0 do
2
+ create_table "people", :force => true do |t|
3
+ t.string "name_prefix"
4
+ t.string "name_first_name"
5
+ t.string "name_middle_name"
6
+ t.string "name_intercalation"
7
+ t.string "name_last_name"
8
+ t.string "name_suffix"
9
+ end
10
+
11
+ end
@@ -0,0 +1,59 @@
1
+ $LOAD_PATH << "." unless $LOAD_PATH.include?(".")
2
+
3
+ begin
4
+ require "rubygems"
5
+ require "bundler"
6
+
7
+ if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.5")
8
+ raise RuntimeError, "Your bundler version is too old." +
9
+ "Run `gem install bundler` to upgrade."
10
+ end
11
+
12
+ # Set up load paths for all bundled gems
13
+ Bundler.setup
14
+ rescue Bundler::GemNotFound
15
+ raise RuntimeError, "Bundler couldn't find some gems." +
16
+ "Did you run `bundle install`?"
17
+ end
18
+
19
+ Bundler.require
20
+ require File.expand_path('../../lib/person_name', __FILE__)
21
+
22
+ unless [].respond_to?(:freq)
23
+ class Array
24
+ def freq
25
+ k=Hash.new(0)
26
+ each {|e| k[e]+=1}
27
+ k
28
+ end
29
+ end
30
+ end
31
+
32
+ ENV['DB'] ||= 'sqlite3'
33
+
34
+ database_yml = File.expand_path('../database.yml', __FILE__)
35
+ if File.exists?(database_yml)
36
+ active_record_configuration = YAML.load_file(database_yml)[ENV['DB']]
37
+
38
+ ActiveRecord::Base.establish_connection(active_record_configuration)
39
+ ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
40
+
41
+ ActiveRecord::Base.silence do
42
+ ActiveRecord::Migration.verbose = false
43
+
44
+ load(File.dirname(__FILE__) + '/schema.rb')
45
+ load(File.dirname(__FILE__) + '/models.rb')
46
+ end
47
+
48
+ else
49
+ raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
50
+ end
51
+
52
+ def clean_database!
53
+ models = [Person]
54
+ models.each do |model|
55
+ ActiveRecord::Base.connection.execute "DELETE FROM #{model.table_name}"
56
+ end
57
+ end
58
+
59
+ clean_database!
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: person_name
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Matthijs Groen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-24 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activerecord
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: activesupport
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 7
46
+ segments:
47
+ - 3
48
+ - 0
49
+ - 0
50
+ version: 3.0.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: arel
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 21
62
+ segments:
63
+ - 1
64
+ - 0
65
+ - 1
66
+ version: 1.0.1
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ description: "\n Manages all person name fields (prefix, first name, middle name, intercalation, last name, suffix)\n "
70
+ email: matthijs.groen@gmail.com
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - README.markdown
77
+ files:
78
+ - .gitignore
79
+ - Gemfile
80
+ - MIT-LICENSE
81
+ - README.markdown
82
+ - Rakefile
83
+ - VERSION
84
+ - init.rb
85
+ - lib/person_name.rb
86
+ - lib/person_name/migration_support.rb
87
+ - lib/person_name/name.rb
88
+ - person_name.gemspec
89
+ - spec/database.yml.sample
90
+ - spec/models.rb
91
+ - spec/person_name/has_person_name_spec.rb
92
+ - spec/schema.rb
93
+ - spec/spec_helper.rb
94
+ has_rdoc: true
95
+ homepage: http://matthijsgroen.posterous.com
96
+ licenses: []
97
+
98
+ post_install_message:
99
+ rdoc_options:
100
+ - --charset=UTF-8
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project:
124
+ rubygems_version: 1.3.7
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: Easy editing of person names.
128
+ test_files:
129
+ - spec/person_name/has_person_name_spec.rb
130
+ - spec/spec_helper.rb
131
+ - spec/models.rb
132
+ - spec/schema.rb