ohio_state_person 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,60 @@
|
|
1
|
+
require "ohio_state_person/version"
|
2
|
+
|
3
|
+
module OhioStatePerson
|
4
|
+
|
5
|
+
module ModelAdditions
|
6
|
+
def is_a_buckeye
|
7
|
+
extend ClassMethods
|
8
|
+
include InstanceMethods
|
9
|
+
|
10
|
+
validates_uniqueness_of :name_n
|
11
|
+
validates_format_of :name_n, :with => /\A[a-z]([a-z-]*[a-z])?\.[1-9]\d*\z/, :message => 'must be in format: name.#'
|
12
|
+
|
13
|
+
validates_uniqueness_of :emplid
|
14
|
+
validates_format_of :emplid, :with => /\A\d{8,9}\z/, :message => 'must be 8 or 9 digits'
|
15
|
+
|
16
|
+
before_validation :set_id, :on => :create
|
17
|
+
validate :id_is_emplid
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module ClassMethods
|
22
|
+
def search(q)
|
23
|
+
q.strip! if q
|
24
|
+
case q
|
25
|
+
when /\A\d+\z/
|
26
|
+
where(:emplid => q)
|
27
|
+
when /\A\D+\.\d+\z/
|
28
|
+
where(:name_n => q)
|
29
|
+
when /(\S+),\s*(\S+)/
|
30
|
+
where('last_name LIKE ? AND first_name LIKE ?', $1, "#{$2}%")
|
31
|
+
when /(\S+)\s+(\S+)/
|
32
|
+
where('first_name LIKE ? AND last_name LIKE ?', $1, "#{$2}%")
|
33
|
+
when /\S/
|
34
|
+
where('last_name LIKE ?', "#{q}%")
|
35
|
+
else
|
36
|
+
where('1=2')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module InstanceMethods
|
42
|
+
def email
|
43
|
+
name_n.present? ? "#{name_n}@osu.edu" : ''
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
def set_id
|
48
|
+
self.id = self.emplid.to_i
|
49
|
+
end
|
50
|
+
|
51
|
+
def id_is_emplid
|
52
|
+
unless self.id == self.emplid.to_i
|
53
|
+
errors.add(:id, 'must be the same as the emplid')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
::ActiveRecord::Base.send :extend, OhioStatePerson::ModelAdditions
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "
|
3
|
+
require "ohio_state_person/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "ohio_state_person"
|
7
7
|
s.version = OhioStatePerson::VERSION
|
8
8
|
s.authors = ["mikegee"]
|
9
9
|
s.email = ["gee.24@osu.edu"]
|
10
|
-
s.homepage = "https://github.com/ASCTech/
|
10
|
+
s.homepage = "https://github.com/ASCTech/ohio_state_person"
|
11
11
|
s.summary = %q{ActiveRecord mixin for people at Ohio State University}
|
12
12
|
s.description = %q{requires fields: name_n, emplid; sets id to emplid.to_i; provides a search method; etc.}
|
13
13
|
|
14
|
-
s.rubyforge_project = "
|
14
|
+
s.rubyforge_project = "ohio_state_person"
|
15
15
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohio_state_person
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- mikegee
|
@@ -44,11 +44,11 @@ extra_rdoc_files: []
|
|
44
44
|
files:
|
45
45
|
- .gitignore
|
46
46
|
- Gemfile
|
47
|
-
- OhioStatePerson.gemspec
|
48
47
|
- Rakefile
|
49
|
-
- lib/
|
50
|
-
- lib/
|
51
|
-
|
48
|
+
- lib/ohio_state_person.rb
|
49
|
+
- lib/ohio_state_person/version.rb
|
50
|
+
- ohio_state_person.gemspec
|
51
|
+
homepage: https://github.com/ASCTech/ohio_state_person
|
52
52
|
licenses: []
|
53
53
|
|
54
54
|
post_install_message:
|
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: "0"
|
77
77
|
requirements: []
|
78
78
|
|
79
|
-
rubyforge_project:
|
79
|
+
rubyforge_project: ohio_state_person
|
80
80
|
rubygems_version: 1.8.10
|
81
81
|
signing_key:
|
82
82
|
specification_version: 3
|
data/lib/OhioStatePerson.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require "OhioStatePerson/version"
|
2
|
-
|
3
|
-
module OhioStatePerson
|
4
|
-
|
5
|
-
def self.included(base)
|
6
|
-
base.instance_eval do
|
7
|
-
validates_uniqueness_of :name_n
|
8
|
-
validates_format_of :name_n, :with => /\A[a-z]([a-z-]*[a-z])?\.[1-9]\d*\z/, :message => 'must be in format: name.#'
|
9
|
-
|
10
|
-
validates_uniqueness_of :emplid
|
11
|
-
validates_format_of :emplid, :with => /\A\d{8,9}\z/, :message => 'must be 8 or 9 digits'
|
12
|
-
|
13
|
-
before_validation :set_id, :on => :create
|
14
|
-
validate :id_is_emplid
|
15
|
-
|
16
|
-
|
17
|
-
def self.search(q)
|
18
|
-
q.strip! if q
|
19
|
-
case q
|
20
|
-
when /\A\d+\z/
|
21
|
-
where(:emplid => q)
|
22
|
-
when /\A\D+\.\d+\z/
|
23
|
-
where(:name_n => q)
|
24
|
-
when /(\S+),\s*(\S+)/
|
25
|
-
where('last_name LIKE ? AND first_name LIKE ?', $1, "#{$2}%")
|
26
|
-
when /(\S+)\s+(\S+)/
|
27
|
-
where('first_name LIKE ? AND last_name LIKE ?', $1, "#{$2}%")
|
28
|
-
when /\S/
|
29
|
-
where('last_name LIKE ?', "#{q}%")
|
30
|
-
else
|
31
|
-
where('1=2')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def email
|
39
|
-
name_n.present? ? "#{name_n}@osu.edu" : ''
|
40
|
-
end
|
41
|
-
|
42
|
-
protected
|
43
|
-
|
44
|
-
def set_id
|
45
|
-
self.id = self.emplid.to_i
|
46
|
-
end
|
47
|
-
|
48
|
-
def id_is_emplid
|
49
|
-
unless self.id == self.emplid.to_i
|
50
|
-
errors.add(:id, 'must be the same as the emplid')
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|