meibo 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f252ebdf57a419551a3b65f21656ea93a2d949c72dd4e957a69aa30a9ab978af
4
- data.tar.gz: 2b3d36b6b7eb8268046e06308d73531b9cec3f849cecc0e3750069435f40c04c
3
+ metadata.gz: 2fed6d292ab3d38301370ef4d6238d4ddc470d8ae380e1e8bdf8f6d88822aaf0
4
+ data.tar.gz: d364e20a7336ad702b4d3434efefe800bed8a971f0cc02177c817398fa79982d
5
5
  SHA512:
6
- metadata.gz: b18d0f8dddadb024f22df2832ad0133fbe1af864143eed2de56108a06e68e97eea28a60909f3eda192fa45c45b5165ef4c1b80805c969d99704bbecd66001618
7
- data.tar.gz: 0a1cf57f5dd8e08b362cc3cd107ae527c45683b7796ef02db788416a65958a99b3ff5605af8ea64b32b5b3ece0ca2236d60d0da12aad941fded971388e731dc5
6
+ metadata.gz: bb712c2090b7cc03708a4c8b302e187357db4f2bf260e62486f79072ba646371368c6968baaa022c472774b6a09c0aba3a7f1716b1b074e6fcb2ab6ab6e19935
7
+ data.tar.gz: dd2f31087c8b28e02b9e257dcb405cb1eec588d5a576c120cdcadcb0402743cb7a02f6e62262ca1c932f93c8f119839d95eb505ce44534a04a478883e0d966af
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- meibo (0.12.0)
4
+ meibo (0.13.0)
5
5
  rubyzip
6
6
  zeitwerk
7
7
 
@@ -60,5 +60,9 @@ module Meibo
60
60
  def term?
61
61
  type == TYPES[:term]
62
62
  end
63
+
64
+ def parent
65
+ Meibo.current_roster.academic_sessions.find(parent_sourced_id)
66
+ end
63
67
  end
64
68
  end
@@ -11,5 +11,21 @@ module Meibo
11
11
  find(academic_session.parent_sourced_id)
12
12
  end
13
13
  end
14
+
15
+ def grading_period
16
+ @cache[:grading_period] ||= new(select(&:grading_period?))
17
+ end
18
+
19
+ def semester
20
+ @cache[:semester] ||= new(select(&:semester?))
21
+ end
22
+
23
+ def school_year
24
+ @cache[:school_year] ||= new(select(&:school_year?))
25
+ end
26
+
27
+ def term
28
+ @cache[:term] ||= new(select(&:term?))
29
+ end
14
30
  end
15
31
  end
@@ -71,5 +71,17 @@ module Meibo
71
71
  def scheduled?
72
72
  class_type == TYPES[:scheduled]
73
73
  end
74
+
75
+ def course
76
+ Meibo.current_roster.courses.find(course_sourced_id)
77
+ end
78
+
79
+ def school
80
+ Meibo.current_roster.organizations.find(school_sourced_id)
81
+ end
82
+
83
+ def terms
84
+ term_sourced_ids.map {|term_sourced_id| Meibo.current_roster.academic_sessions.find(term_sourced_id) }
85
+ end
74
86
  end
75
87
  end
@@ -18,5 +18,13 @@ module Meibo
18
18
  end
19
19
  end
20
20
  end
21
+
22
+ def homeroom
23
+ @cache[:homeroom] ||= new(select(&:homeroom?))
24
+ end
25
+
26
+ def scheduled
27
+ @cache[:scheduled] ||= new(select(&:scheduled?))
28
+ end
21
29
  end
22
30
  end
data/lib/meibo/course.rb CHANGED
@@ -41,5 +41,13 @@ module Meibo
41
41
  @subject_codes = subject_codes
42
42
  @extension_fields = extension_fields
43
43
  end
44
+
45
+ def organization
46
+ Meibo.current_roster.organizations.find(org_sourced_id)
47
+ end
48
+
49
+ def school_year
50
+ Meibo.current_roster.academic_sessions.find(school_year_sourced_id)
51
+ end
44
52
  end
45
53
  end
@@ -6,24 +6,24 @@ module Meibo
6
6
 
7
7
  def initialize(data, roster:)
8
8
  @data = data
9
- @data_hash = data.to_h {|datum| [datum.sourced_id, datum] }
10
9
  @roster = roster
10
+ @cache = {}
11
11
  end
12
12
 
13
13
  def <<(new_data)
14
14
  raise DataNotFoundError, "sourcedIdがありません" unless new_data.sourced_id
15
- raise SourcedIdDuplicatedError, 'sourcedIdが重複しています' if @data_hash.key?(new_data.sourced_id)
15
+ raise SourcedIdDuplicatedError, 'sourcedIdが重複しています' if data_by_sourced_id.key?(new_data.sourced_id)
16
16
 
17
17
  @data << new_data
18
- @data_hash[new_data.sourced_id] = new_data
18
+ @cache.clear
19
19
  end
20
20
 
21
21
  def check_semantically_consistent
22
- unless @data.size == @data_hash.size
22
+ unless @data.size == data_by_sourced_id.size
23
23
  raise SourcedIdDuplicatedError, 'sourcedIdが重複しています'
24
24
  end
25
25
 
26
- unless @data_hash[nil].nil?
26
+ unless data_by_sourced_id[nil].nil?
27
27
  raise DataNotFoundError, "sourcedIdがありません"
28
28
  end
29
29
  end
@@ -37,9 +37,39 @@ module Meibo
37
37
  end
38
38
 
39
39
  def find(sourced_id)
40
- @data_hash.fetch(sourced_id)
40
+ data_by_sourced_id.fetch(sourced_id)
41
41
  rescue KeyError
42
42
  raise DataNotFoundError, "sourcedId: #{sourced_id} が見つかりません"
43
43
  end
44
+
45
+ def by_organization(org_sourced_id)
46
+ data_by_org_sourced_id[org_sourced_id]
47
+ end
48
+
49
+ def by_user(user_sourced_id)
50
+ data_by_user_sourced_id[user_sourced_id]
51
+ end
52
+
53
+ private
54
+
55
+ def data_by_org_sourced_id
56
+ @cache[:data_by_org_sourced_id] ||= @data.group_by(&:data_by_org_sourced_id).to_h do |org_sourced_id, data|
57
+ [org_sourced_id, new(data)]
58
+ end
59
+ end
60
+
61
+ def data_by_sourced_id
62
+ @cache[:data_by_sourced_id] ||= @data.to_h {|datum| [datum.sourced_id, datum] }
63
+ end
64
+
65
+ def data_by_user_sourced_id
66
+ @cache[:data_by_user_sourced_id] ||= @data.group_by(&:user_sourced_id).to_h do |user_sourced_id, data|
67
+ [user_sourced_id, new(data)]
68
+ end
69
+ end
70
+
71
+ def new(data)
72
+ self.class.new(data, roster: roster)
73
+ end
44
74
  end
45
75
  end
@@ -82,5 +82,9 @@ module Meibo
82
82
  def other?
83
83
  sex == SEX[:other]
84
84
  end
85
+
86
+ def user
87
+ Meibo.current_roster.users.find(sourced_id)
88
+ end
85
89
  end
86
90
  end
@@ -9,5 +9,21 @@ module Meibo
9
9
  roster.users.find(demographic.sourced_id)
10
10
  end
11
11
  end
12
+
13
+ def male
14
+ @cache[:male] ||= new(select(&:male?))
15
+ end
16
+
17
+ def female
18
+ @cache[:female] ||= new(select(&:female?))
19
+ end
20
+
21
+ def unspecified
22
+ @cache[:unspecified] ||= new(select(&:unspecified?))
23
+ end
24
+
25
+ def other
26
+ @cache[:other] ||= new(select(&:other?))
27
+ end
12
28
  end
13
29
  end
@@ -61,5 +61,17 @@ module Meibo
61
61
  def teacher?
62
62
  role == ROLES[:teacher]
63
63
  end
64
+
65
+ def classroom
66
+ Meibo.current_roster.classes.find(class_sourced_id)
67
+ end
68
+
69
+ def school
70
+ Meibo.current_roster.organizations.find(school_sourced_id)
71
+ end
72
+
73
+ def user
74
+ Meibo.current_roster.users.find(user_sourced_id)
75
+ end
64
76
  end
65
77
  end
@@ -11,5 +11,21 @@ module Meibo
11
11
  roster.users.find(enrollment.user_sourced_id)
12
12
  end
13
13
  end
14
+
15
+ def administrator
16
+ @cache[:administrator] ||= new(select(&:administrator?))
17
+ end
18
+
19
+ def proctor
20
+ @cache[:proctor] ||= new(select(&:proctor?))
21
+ end
22
+
23
+ def student
24
+ @cache[:student] ||= new(select(&:student?))
25
+ end
26
+
27
+ def teacher
28
+ @cache[:teacher] ||= new(select(&:teacher?))
29
+ end
14
30
  end
15
31
  end
@@ -22,6 +22,10 @@ module Meibo
22
22
  @kana_middle_name = kana_middle_name
23
23
  @home_class = home_class
24
24
  end
25
+
26
+ def home_classroom
27
+ home_class && Meibo.current_roster.classes.find(home_class)
28
+ end
25
29
  end
26
30
  end
27
31
  end
@@ -64,5 +64,9 @@ module Meibo
64
64
  def national?
65
65
  type == TYPES[:national]
66
66
  end
67
+
68
+ def parent
69
+ parent_sourced_id && Meibo.current_roster.organizations.find(parent_sourced_id)
70
+ end
67
71
  end
68
72
  end
@@ -11,5 +11,29 @@ module Meibo
11
11
  find(organization.parent_sourced_id)
12
12
  end
13
13
  end
14
+
15
+ def department
16
+ @cache[:department] ||= new(select(&:department?))
17
+ end
18
+
19
+ def school
20
+ @cache[:school] ||= new(select(&:school?))
21
+ end
22
+
23
+ def district
24
+ @cache[:district] ||= new(select(&:district?))
25
+ end
26
+
27
+ def local
28
+ @cache[:local] ||= new(select(&:local?))
29
+ end
30
+
31
+ def state
32
+ @cache[:state] ||= new(select(&:state?))
33
+ end
34
+
35
+ def national
36
+ @cache[:national] ||= new(select(&:national?))
37
+ end
14
38
  end
15
39
  end
data/lib/meibo/role.rb CHANGED
@@ -117,5 +117,17 @@ module Meibo
117
117
  def teacher?
118
118
  role == ROLES[:teacher]
119
119
  end
120
+
121
+ def organization
122
+ Meibo.current_roster.organizations.find(org_sourced_id)
123
+ end
124
+
125
+ def user
126
+ Meibo.current_roster.users.find(user_sourced_id)
127
+ end
128
+
129
+ def user_profile
130
+ user_profile_sourced_id && Meibo.current_roster.user_profiles.find(user_profile_sourced_id)
131
+ end
120
132
  end
121
133
  end
@@ -14,5 +14,61 @@ module Meibo
14
14
  end
15
15
  end
16
16
  end
17
+
18
+ def primary
19
+ @cache[:primary] ||= new(select(&:primary?))
20
+ end
21
+
22
+ def secondary
23
+ @cache[:secondary] ||= new(select(&:secondary?))
24
+ end
25
+
26
+ def aide
27
+ @cache[:aide] ||= new(select(&:aide?))
28
+ end
29
+
30
+ def counselor
31
+ @cache[:counselor] ||= new(select(&:counselor?))
32
+ end
33
+
34
+ def district_administrator
35
+ @cache[:district_administrator] ||= new(select(&:district_administrator?))
36
+ end
37
+
38
+ def guardian
39
+ @cache[:guardian] ||= new(select(&:guardian?))
40
+ end
41
+
42
+ def parent
43
+ @cache[:parent] ||= new(select(&:parent?))
44
+ end
45
+
46
+ def principal
47
+ @cache[:principal] ||= new(select(&:principal?))
48
+ end
49
+
50
+ def proctor
51
+ @cache[:proctor] ||= new(select(&:proctor?))
52
+ end
53
+
54
+ def relative
55
+ @cache[:relative] ||= new(select(&:relative?))
56
+ end
57
+
58
+ def site_administrator
59
+ @cache[:site_administrator] ||= new(select(&:site_administrator?))
60
+ end
61
+
62
+ def student
63
+ @cache[:student] ||= new(select(&:student?))
64
+ end
65
+
66
+ def system_administrator
67
+ @cache[:system_administrator] ||= new(select(&:system_administrator?))
68
+ end
69
+
70
+ def teacher
71
+ @cache[:teacher] ||= new(select(&:teacher?))
72
+ end
17
73
  end
18
74
  end
data/lib/meibo/user.rb CHANGED
@@ -67,5 +67,37 @@ module Meibo
67
67
  @pronouns = pronouns
68
68
  @extension_fields = extension_fields
69
69
  end
70
+
71
+ def agents
72
+ agent_sourced_ids.map {|agent_sourced_id| Meibo.current_roster.users.find(agent_sourced_id) }
73
+ end
74
+
75
+ def demographic
76
+ Meibo.current_roster.demographics.find(sourced_id)
77
+ rescue DataNotFoundError
78
+ nil
79
+ end
80
+
81
+ def enrollments
82
+ Meibo.current_roster.enrollments.by_user(sourced_id)
83
+ end
84
+
85
+ def primary_organization
86
+ primary_org_sourced_id && Meibo.current_roster.organizations.find(primary_org_sourced_id)
87
+ end
88
+
89
+ def primary_role_in(org)
90
+ Meibo.current_roster.roles.by_user(sourced_id).detect do |role|
91
+ role.primary? && role.org_sourced_id == org.sourced_id
92
+ end
93
+ end
94
+
95
+ def roles
96
+ Meibo.current_roster.roles.by_user(sourced_id)
97
+ end
98
+
99
+ def user_profiles
100
+ Meibo.current_roster.user_profiles.by_user(sourced_id)
101
+ end
70
102
  end
71
103
  end
@@ -38,5 +38,9 @@ module Meibo
38
38
  @password = password
39
39
  @extension_fields = extension_fields
40
40
  end
41
+
42
+ def user
43
+ Meibo.current_roster.users.find(user_sourced_id)
44
+ end
41
45
  end
42
46
  end
data/lib/meibo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Meibo
4
- VERSION = "0.12.0"
4
+ VERSION = "0.13.0"
5
5
  end
data/lib/meibo.rb CHANGED
@@ -15,6 +15,24 @@ module Meibo
15
15
 
16
16
  class << self
17
17
  attr_accessor :default_profile
18
+
19
+ def current_roster
20
+ thread_local_data[:roster]
21
+ end
22
+
23
+ def with_roster(roster)
24
+ orig_roster = thread_local_data[:roster]
25
+ thread_local_data[:roster] = roster
26
+ yield
27
+ ensure
28
+ thread_local_data[:roster] = orig_roster
29
+ end
30
+
31
+ private
32
+
33
+ def thread_local_data
34
+ Thread.current[:__meibo] ||= {}
35
+ end
18
36
  end
19
37
  end
20
38
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meibo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seiei Miyagi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-14 00:00:00.000000000 Z
11
+ date: 2022-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -125,7 +125,7 @@ metadata:
125
125
  allowed_push_host: https://rubygems.org/
126
126
  homepage_uri: https://github.com/hanachin/meibo
127
127
  source_code_uri: https://github.com/hanachin/meibo
128
- changelog_uri: https://github.com/hanachin/meibo/blob/meibo/v0.12.0/CHANGELOG.md
128
+ changelog_uri: https://github.com/hanachin/meibo/blob/meibo/v0.13.0/CHANGELOG.md
129
129
  post_install_message:
130
130
  rdoc_options: []
131
131
  require_paths: