acts_as_human 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/acts_as_human/class_methods.rb +48 -0
- data/lib/acts_as_human/instance_methods.rb +39 -0
- data/lib/acts_as_human.rb +0 -1
- metadata +5 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.2
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module ActsAs
|
2
|
+
module Human
|
3
|
+
mattr_accessor :acceptable_name, :bad_name_message
|
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
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
ActiveRecord::Base.send(:include, ActsAs::Human)
|
48
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module ActsAs
|
2
|
+
module Human
|
3
|
+
|
4
|
+
module InstanceMethods
|
5
|
+
def full_name
|
6
|
+
return '' if first_name.blank? and last_name.blank?
|
7
|
+
|
8
|
+
return "#{first_name} #{last_name}" if middle_names.blank?
|
9
|
+
return "#{first_name} #{middle_names} #{last_name}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def full_name=(names)
|
13
|
+
names_array = names.titlecase.split
|
14
|
+
|
15
|
+
self.first_name = names_array.first
|
16
|
+
return if names_array.size < 2
|
17
|
+
|
18
|
+
self.last_name = names_array.last
|
19
|
+
|
20
|
+
assign_middle_names(names_array)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def assign_middle_names(names_array)
|
26
|
+
if names_array.size > 2
|
27
|
+
self.middle_names = get_middle_names(names_array)
|
28
|
+
else
|
29
|
+
self.middle_names = nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_middle_names(names_array)
|
34
|
+
names_array[1..(names_array.size-2)].join(' ')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
data/lib/acts_as_human.rb
CHANGED
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: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 2
|
10
|
+
version: 2.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brent Greeff
|
@@ -35,6 +35,8 @@ files:
|
|
35
35
|
- VERSION
|
36
36
|
- lib/acts_as_human.rb
|
37
37
|
- lib/acts_as_human/validations.rb
|
38
|
+
- lib/acts_as_human/instance_methods.rb
|
39
|
+
- lib/acts_as_human/class_methods.rb
|
38
40
|
- test/acts_as_human_test.rb
|
39
41
|
- test/database.yml
|
40
42
|
- test/schema.rb
|