11class User
2+ include ActiveModel ::Model
3+ include ActiveModel ::Attributes
24 include ActiveModel ::Serialization
35 include BerkeleyLibrary ::Logging
46
@@ -18,27 +20,24 @@ class User
1820 # Accessors
1921
2022 # @return [String]
21- attr_reader :uid
23+ attribute :uid , :string
2224
2325 # @return [String]
24- attr_reader :display_name
26+ attribute :display_name , :string
2527
2628 # @return [String] The user's email address.
27- attr_reader :email
29+ attribute :email , :string
2830
2931 # @return [Boolean] True if the user is a GALC administrator, false otherwise.
30- attr_reader :galc_admin
32+ attribute :galc_admin , :boolean
3133
3234 alias galc_admin? galc_admin
3335
3436 # ------------------------------------------------------------
3537 # Initializer
3638
3739 def initialize ( uid : nil , display_name : nil , email : nil , galc_admin : false )
38- @uid = uid
39- @display_name = display_name
40- @email = email
41- @galc_admin = galc_admin
40+ super
4241 end
4342
4443 # ------------------------------------------------------------
@@ -67,11 +66,6 @@ def from_session(session)
6766 def galc_admin? ( cal_groups )
6867 cal_groups && cal_groups . include? ( GALC_ADMIN_GROUP )
6968 end
70-
71- def attribute_names
72- # Hack to leverage ActiveModel::Serialization#attribute_names
73- @attribute_names ||= User . new . attribute_names
74- end
7569 end
7670
7771 # ------------------------------------------------------------
@@ -81,15 +75,4 @@ def attribute_names
8175 def authenticated?
8276 !uid . nil?
8377 end
84-
85- # ------------------------------
86- # ActiveModel::Serialization
87-
88- # Default attribute hash. Used by ActiveModel::Serialization to
89- # implement `#attribute_names` and `#serializable_hash`.
90- #
91- # @return [Hash<String, Object>] a hash of default attribute values
92- def attributes
93- SERIALIZED_ATTRS . stringify_keys
94- end
9578end
0 commit comments