acts_as_human 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -0
- data/lib/acts_as_human.rb +4 -83
- metadata +4 -4
data/README.rdoc
CHANGED
data/lib/acts_as_human.rb
CHANGED
@@ -1,83 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
self.acceptable_name = /\A[^[:cntrl:]\\<>\/&]*\z/
|
6
|
-
self.bad_name_message = "some characters in your name are not allowed".freeze
|
7
|
-
|
8
|
-
def self.included(base)
|
9
|
-
base.send :extend, ClassMethods
|
10
|
-
end
|
11
|
-
|
12
|
-
module ClassMethods
|
13
|
-
|
14
|
-
def acts_as_human(options={})
|
15
|
-
cattr_accessor :require_last_name
|
16
|
-
|
17
|
-
if options.has_key? :require_last_name
|
18
|
-
@require_last_name = options[:require_last_name]
|
19
|
-
else
|
20
|
-
@require_last_name = true
|
21
|
-
end
|
22
|
-
send :include, InstanceMethods
|
23
|
-
|
24
|
-
class_eval do
|
25
|
-
validates_presence_of :first_name, :message => 'first name is required'
|
26
|
-
validates_length_of :first_name, :maximum => 40,
|
27
|
-
:message => 'first name is too long (max 40 characters)'
|
28
|
-
validates_as_person_name :first_name
|
29
|
-
|
30
|
-
validates_length_of :middle_names, :maximum => 40,
|
31
|
-
:allow_blank => true,
|
32
|
-
:message => 'middle names are too long (max 40 characters)'
|
33
|
-
validates_as_person_name :middle_names, :allow_nil => true
|
34
|
-
|
35
|
-
validates_presence_of :last_name, :if => Proc.new { @require_last_name },
|
36
|
-
:message => 'last name is required'
|
37
|
-
validates_length_of :last_name, :maximum => 40,
|
38
|
-
:allow_blank => true,
|
39
|
-
:message => 'last name is too long (max 40 characters)'
|
40
|
-
validates_as_person_name :last_name
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
module InstanceMethods
|
47
|
-
def full_name
|
48
|
-
return '' if first_name.blank? and last_name.blank?
|
49
|
-
|
50
|
-
return "#{first_name} #{last_name}" if middle_names.blank?
|
51
|
-
return "#{first_name} #{middle_names} #{last_name}"
|
52
|
-
end
|
53
|
-
|
54
|
-
def full_name=(names)
|
55
|
-
names_array = names.titlecase.split
|
56
|
-
|
57
|
-
self.first_name = names_array.first
|
58
|
-
return if names_array.size < 2
|
59
|
-
|
60
|
-
self.last_name = names_array.last
|
61
|
-
|
62
|
-
assign_middle_names(names_array)
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def assign_middle_names(names_array)
|
68
|
-
if names_array.size > 2
|
69
|
-
self.middle_names = get_middle_names(names_array)
|
70
|
-
else
|
71
|
-
self.middle_names = nil
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def get_middle_names(names_array)
|
76
|
-
names_array[1..(names_array.size-2)].join(' ')
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
ActiveRecord::Base.send(:include, ActsAs::Human)
|
83
|
-
|
1
|
+
require 'acts_as_human/validations'
|
2
|
+
require 'acts_as_human/instance_methods'
|
3
|
+
require 'acts_as_human/class_methods'
|
4
|
+
require 'acts_as_human'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_human
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 1
|
10
|
+
version: 2.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brent Greeff
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-29 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|