acts_as_human_name 0.0.1
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/MIT-LICENSE +20 -0
- data/README +19 -0
- data/Rakefile +52 -0
- data/init.rb +4 -0
- data/lib/active_record/acts/human_name.rb +70 -0
- metadata +71 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 [name of plugin creator]
|
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.
|
data/README
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
ActsAsHumanName
|
2
|
+
===============
|
3
|
+
|
4
|
+
Adds two methods to your model:
|
5
|
+
|
6
|
+
regular_name: "David Christiansen"
|
7
|
+
full_name: "Christiansen, David Ray III"
|
8
|
+
|
9
|
+
|
10
|
+
The tests don't work yet. I need to figure out how to include shoulda. Also, you can't configure the names of the columns I use yet. They have to be first_name, last_name, middle_name, and suffix.
|
11
|
+
|
12
|
+
|
13
|
+
Example
|
14
|
+
=======
|
15
|
+
|
16
|
+
acts_as_human_name
|
17
|
+
|
18
|
+
|
19
|
+
Copyright (c) 2010 David Christiansen, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
|
6
|
+
PKG_FILES = FileList[
|
7
|
+
'[a-zA-Z]*',
|
8
|
+
'generators/**/*',
|
9
|
+
'lib/**/*',
|
10
|
+
'rails/**/*',
|
11
|
+
'tasks/**/*',
|
12
|
+
'test/**/*'
|
13
|
+
]
|
14
|
+
|
15
|
+
spec = Gem::Specification.new do |s|
|
16
|
+
s.name = "acts_as_human_name"
|
17
|
+
s.version = "0.0.1"
|
18
|
+
s.author = "Dave Christiansen"
|
19
|
+
s.email = "dave@trooptrack.com"
|
20
|
+
s.homepage = "http://trooptrack.com/"
|
21
|
+
s.platform = Gem::Platform::RUBY
|
22
|
+
s.summary = "Easy way to display people's names"
|
23
|
+
s.files = PKG_FILES.to_a
|
24
|
+
s.require_path = "lib"
|
25
|
+
s.has_rdoc = false
|
26
|
+
s.extra_rdoc_files = ["README"]
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'Turn this plugin into a gem.'
|
30
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
31
|
+
pkg.gem_spec = spec
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'Default: run unit tests.'
|
35
|
+
task :default => :test
|
36
|
+
|
37
|
+
desc 'Test the acts_as_human_name plugin.'
|
38
|
+
Rake::TestTask.new(:test) do |t|
|
39
|
+
t.libs << 'lib'
|
40
|
+
t.libs << 'test'
|
41
|
+
t.pattern = 'test/**/*_test.rb'
|
42
|
+
t.verbose = true
|
43
|
+
end
|
44
|
+
|
45
|
+
desc 'Generate documentation for the acts_as_human_name plugin.'
|
46
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = 'ActsAsHumanName'
|
49
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
50
|
+
rdoc.rdoc_files.include('README')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Acts #:nodoc:
|
3
|
+
module HumanName #:nodoc:
|
4
|
+
def self.included(base)
|
5
|
+
base.extend(ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
# This +acts_as+ extension provides the capabilities rendering different representations of a
|
9
|
+
# human name in English. Models need to store last_name, first_name, middle_name, and suffix columns
|
10
|
+
# for this plugin to work.
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
# Configuration options are:
|
14
|
+
#
|
15
|
+
# * +last_name+ - specifies where the last name is stored (default: +last_name+)
|
16
|
+
# * +first_name+ - specifies where the first name is stored (default: +first_name+)
|
17
|
+
# * +middle_name+ - specifies where the middle name is stored (default: +middle_name+)
|
18
|
+
# * +suffix+ - specifies where the suffix is stored (default: +suffix+)
|
19
|
+
# Example: <tt>acts_as_human_name :last_name => "surname"</tt>
|
20
|
+
# HEY!!! This configuration stuff doesn't actually work yet!!!
|
21
|
+
def acts_as_human_name(options = {})
|
22
|
+
configuration = { :last_name => "last_name",
|
23
|
+
:first_name => "first_name",
|
24
|
+
:middle_name => "middle_name",
|
25
|
+
:suffix => "suffix" }
|
26
|
+
|
27
|
+
configuration.update(options) if options.is_a?(Hash)
|
28
|
+
|
29
|
+
class_eval <<-EOV
|
30
|
+
include ActiveRecord::Acts::HumanName::InstanceMethods
|
31
|
+
|
32
|
+
def acts_as_human_name_class
|
33
|
+
::#{self.name}
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
EOV
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module InstanceMethods
|
42
|
+
def regular_name
|
43
|
+
if first_name and last_name
|
44
|
+
"#{self.first_name} #{self.last_name}"
|
45
|
+
elsif first_name
|
46
|
+
first_name
|
47
|
+
elsif last_name
|
48
|
+
last_name
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def full_name
|
53
|
+
if first_name and last_name and middle_name and suffix
|
54
|
+
"#{last_name}, #{first_name} #{middle_name} #{suffix}"
|
55
|
+
elsif first_name and last_name and middle_name
|
56
|
+
"#{last_name}, #{first_name} #{middle_name}"
|
57
|
+
elsif first_name and last_name and suffix
|
58
|
+
"#{last_name}, #{first_name} #{suffix}"
|
59
|
+
elsif first_name and last_name
|
60
|
+
"#{last_name}, #{first_name}"
|
61
|
+
elsif last_name
|
62
|
+
last_name
|
63
|
+
elsif first_name
|
64
|
+
first_name
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_human_name
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Dave Christiansen
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-09-07 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email: dave@trooptrack.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README
|
30
|
+
files:
|
31
|
+
- init.rb
|
32
|
+
- MIT-LICENSE
|
33
|
+
- Rakefile
|
34
|
+
- README
|
35
|
+
- lib/active_record/acts/human_name.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://trooptrack.com/
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.3.7
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Easy way to display people's names
|
70
|
+
test_files: []
|
71
|
+
|