Skip to content

Commit 444fb3d

Browse files
committed
logging and refactoring
1 parent 95c3477 commit 444fb3d

File tree

11 files changed

+198
-114
lines changed

11 files changed

+198
-114
lines changed

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ gem "shale"
77
gem "rexml"
88
gem "thor"
99
gem "yabeda-prometheus"
10+
gem "semantic_logger"
11+
12+
gem "milemarker",
13+
git: "https://github.com/niquerio/milemarker",
14+
branch: "add-logger-to-runtime-dependencies"
1015

1116
group :development, :test do
1217
gem "pry"

Gemfile.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
GIT
2+
remote: https://github.com/niquerio/milemarker
3+
revision: ce3cf65886015c08e9467254a0a9670f00abfc4b
4+
branch: add-logger-to-runtime-dependencies
5+
specs:
6+
milemarker (1.0.1)
7+
logger
8+
19
GEM
210
remote: https://rubygems.org/
311
specs:
@@ -16,6 +24,7 @@ GEM
1624
json (2.15.1)
1725
language_server-protocol (3.17.0.5)
1826
lint_roller (1.1.0)
27+
logger (1.7.0)
1928
method_source (1.1.0)
2029
net-ldap (0.20.0)
2130
base64
@@ -71,6 +80,8 @@ GEM
7180
rubocop-ast (>= 1.38.0, < 2.0)
7281
ruby-next-core (1.1.2)
7382
ruby-progressbar (1.13.0)
83+
semantic_logger (4.17.0)
84+
concurrent-ruby (~> 1.0)
7485
shale (1.2.2)
7586
bigdecimal
7687
simplecov (0.22.0)
@@ -111,11 +122,13 @@ DEPENDENCIES
111122
base64
112123
byebug
113124
csv
125+
milemarker!
114126
net-ldap
115127
pry
116128
rack-test
117129
rexml
118130
rspec
131+
semantic_logger
119132
shale
120133
simplecov
121134
standard

lib/patron.rb

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,19 @@ def initialize(data:, name: Name.new(data), current_schedule: CurrentSchedule.ne
8080
@exclude_reasons = []
8181
end
8282

83-
def includable?
84-
raise NotImplementedError
83+
[
84+
"campus_code",
85+
"email_type",
86+
"exclude_reason",
87+
"includable?",
88+
"job_description",
89+
"statistic_category",
90+
"umich_address_type",
91+
"user_group"
92+
].each do |method|
93+
define_method method do
94+
raise NotImplementedError, "#{self.class}.#{method}"
95+
end
8596
end
8697

8798
def uniqname
@@ -108,33 +119,13 @@ def purge_date
108119
expiry_date.next_year(2)
109120
end
110121

111-
def campus_code
112-
raise NotImplementedError
113-
end
114-
115-
def user_group
116-
raise NotImplementedError
117-
end
118-
119122
def status
120123
"ACTIVE"
121124
end
122125

123126
def sponsor_reason
124127
end
125128

126-
def job_description
127-
raise NotImplementedError
128-
end
129-
130-
def statistic_category
131-
raise NotImplementedError
132-
end
133-
134-
def umich_address_type
135-
raise NotImplementedError
136-
end
137-
138129
def umich_address
139130
raw_address = [@data["umichpostaladdressdata"]&.first, @data["umichhomepostaladdressdata"]&.first].compact.first
140131
return if raw_address.nil?
@@ -171,10 +162,6 @@ def email_address
171162
@data["mail"]&.first
172163
end
173164

174-
def email_type
175-
raise NotImplementedError
176-
end
177-
178165
def phone_number
179166
@data["telephonenumber"]&.first || @data["umichpermanentphone"]&.first
180167
end

lib/patron/employee.rb

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,49 @@ class Employee < Patron
66
"um_dearborn" => "UMDB"
77
}
88

9-
def includable?
10-
!hr_data.nil?
11-
end
12-
13-
def user_group
14-
raise NotImplementedError
15-
end
16-
179
def role
1810
raise NotImplementedError
1911
end
2012

21-
def statistic_category
22-
raise NotImplementedError
23-
end
24-
25-
def exclude_reason
13+
def hr_criteria(hr_item)
2614
raise NotImplementedError
2715
end
2816

29-
def hr_criteria(hr_item)
30-
raise NotImplementedError
17+
[
18+
"statistic_category",
19+
"user_group",
20+
"exclude_reason"
21+
].each do |method|
22+
define_method method do
23+
# all of these are NotImplementedError
24+
super
25+
end
3126
end
3227

3328
def campus_code
3429
HR_CAMPUS_MAP[hr_data.campus.downcase]
3530
end
3631

37-
def job_description
38-
"#{hr_data.deptDescription} (#{hr_data.deptId})"
39-
end
40-
4132
def email_type
4233
"work"
4334
end
4435

36+
def exclude_reason
37+
raise NotImplementedError
38+
end
39+
40+
def includable?
41+
!hr_data.nil?
42+
end
43+
4544
def umich_address_type
4645
"work"
4746
end
4847

48+
def job_description
49+
"#{hr_data.deptDescription} (#{hr_data.deptId})"
50+
end
51+
4952
def hr_attribute
5053
"umichhr"
5154
end

lib/patron/regional_student.rb

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,34 @@ class RegionalStudent < Patron::Student
1515
"PN" => "GR"
1616
}
1717

18-
def campus_code
18+
def ldap_campus
1919
raise NotImplementedError
2020
end
2121

22-
def ldap_campus
22+
def campus_code
2323
raise NotImplementedError
2424
end
2525

26-
def term(acad_period)
27-
# 5th caracter in academic period is the index-1 of the semester
28-
semester = ["F", "W", "SP", "SU"][acad_period[4].to_i - 1]
26+
def exclude_reason
27+
"not_registered" unless includable?
28+
end
2929

30-
# the 2 digit year year unless it's fall.
31-
year_ish = acad_period[2, 2].to_i
30+
def includable?
31+
current_term_status.any? do |term|
32+
term.registered == "Y" && @current_schedule.includable_term?(term(term.academicPeriod))
33+
end
34+
end
3235

33-
year = (semester == "F") ? year_ish - 1 : year_ish
36+
def job_description
37+
current_term_status.map do |term|
38+
term.programDesc
39+
end.compact.first
40+
end
3441

35-
"#{semester}#{year}"
42+
def statistic_category
43+
current_term_status.map do |term|
44+
CLASS_STANDING_STATISTIC_CATEGORY_MAP[term.classStanding]
45+
end.compact.first
3646
end
3747

3848
def user_group
@@ -44,50 +54,40 @@ def user_group
4454
end
4555
end
4656

47-
def statistic_category
48-
current_term_status.map do |term|
49-
CLASS_STANDING_STATISTIC_CATEGORY_MAP[term.classStanding]
50-
end.compact.first
51-
end
57+
def term(acad_period)
58+
# 5th caracter in academic period is the index-1 of the semester
59+
semester = ["F", "W", "SP", "SU"][acad_period[4].to_i - 1]
5260

53-
def current_term_status
54-
ldap_fields(@data["umich#{ldap_campus}currenttermstatus"] || [])
55-
end
61+
# the 2 digit year year unless it's fall.
62+
year_ish = acad_period[2, 2].to_i
5663

57-
def job_description
58-
current_term_status.map do |term|
59-
term.programDesc
60-
end.compact.first
61-
end
64+
year = (semester == "F") ? year_ish - 1 : year_ish
6265

63-
def includable?
64-
current_term_status.any? do |term|
65-
term.registered == "Y" && @current_schedule.includable_term?(term(term.academicPeriod))
66-
end
66+
"#{semester}#{year}"
6767
end
6868

69-
def exclude_reason
70-
"not_registered" unless includable?
69+
def current_term_status
70+
ldap_fields(@data["umich#{ldap_campus}currenttermstatus"] || [])
7171
end
7272
end
7373

7474
class DearbornStudent < Patron::RegionalStudent
75-
def campus_code
76-
"UMDB"
77-
end
78-
7975
def ldap_campus
8076
"dbrn"
8177
end
82-
end
8378

84-
class FlintStudent < Patron::RegionalStudent
8579
def campus_code
86-
"UMFL"
80+
"UMDB"
8781
end
82+
end
8883

84+
class FlintStudent < Patron::RegionalStudent
8985
def ldap_campus
9086
"flnt"
9187
end
88+
89+
def campus_code
90+
"UMFL"
91+
end
9292
end
9393
end

lib/patron/skipped.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ def includable?
1111
false
1212
end
1313

14-
def statistic_category
15-
end
16-
17-
def campus_code
18-
end
19-
20-
def user_group
21-
end
14+
[
15+
"campus_code",
16+
"email_type",
17+
"exclude_reason",
18+
"job_description",
19+
"statistic_category",
20+
"umich_address_type",
21+
"user_group"
22+
].each { |method| define_method(method) {} }
2223
end
2324
end

lib/patron/student.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
class Patron
22
class Student < Patron
3-
def campus_code
4-
raise NotImplementedError
3+
[
4+
"campus_code",
5+
"exclude_reason",
6+
"includable?",
7+
"job_description",
8+
"statistic_category",
9+
"user_group"
10+
].each do |method|
11+
define_method method do
12+
# all of these are NotImplementedError
13+
super
14+
end
515
end
616

717
def email_type

0 commit comments

Comments
 (0)