Module: Authpds::ActsAsAuthentic::InstitutionAttributes
- Defined in:
- lib/authpds/acts_as_authentic/institutions_attributes.rb
Instance Method Summary collapse
- #institutions ⇒ Object
- #institutions=(new_institutions) ⇒ Object
- #primary_institution ⇒ Object
- #primary_institution=(new_primary_institution) ⇒ Object
Instance Method Details
#institutions ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/authpds/acts_as_authentic/institutions_attributes.rb', line 22 def institutions if user_attributes.present? user_attributes[:institutions].collect do |institution| all_institutions[institution] end end end |
#institutions=(new_institutions) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/authpds/acts_as_authentic/institutions_attributes.rb', line 30 def institutions=(new_institutions) unless new_institutions.is_a?(Array) raise ArgumentError.new("Institutions input should be an array.") end # Collect the codes as symbols new_institutions.collect! do |institution| if institution.is_a?(Institutions::Institution) institution.code else institution.to_sym end end # Whitelist the institutions new_institutions = new_institutions.select do |institution| all_institutions[institution].present? end # Add them to the user attributes if new_institutions.present? self.user_attributes = { institutions: new_institutions } end end |
#primary_institution ⇒ Object
6 7 8 9 10 |
# File 'lib/authpds/acts_as_authentic/institutions_attributes.rb', line 6 def primary_institution unless user_attributes.blank? all_institutions[user_attributes[:primary_institution]] end end |
#primary_institution=(new_primary_institution) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/authpds/acts_as_authentic/institutions_attributes.rb', line 12 def primary_institution=(new_primary_institution) if new_primary_institution.is_a?(Institutions::Institution) new_primary_institution = new_primary_institution.code end if new_primary_institution.present? self.user_attributes = { primary_institution: new_primary_institution.to_sym } end end |