Sha256: 0876ef4708a7fac2a5e6c2b9c32906ec121fb93b3776af4686b719ccddabdacc

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 KB

Contents

module Authpds
  module ActsAsAuthentic
    module InstitutionAttributes
      require 'institutions'

      def primary_institution
        all_institutions[user_attributes[:primary_institution]] unless user_attributes.nil?
      end

      def primary_institution=(new_primary_institution)
        new_primary_institution = new_primary_institution.code if new_primary_institution.is_a?(Institutions::Institution)
        self.user_attributes=({:primary_institution => new_primary_institution.to_sym})
      end

      def institutions
        user_attributes[:institutions].collect { |institution| all_institutions[institution] } unless user_attributes.nil?
      end

      def institutions=(new_institutions)
        raise ArgumentError.new("Institutions input should be an array.") unless new_institutions.is_a?(Array)
        new_institutions.collect! { |institution| institution.to_sym }
        new_institutions = new_institutions.select { |institution|
          all_institutions[ new_institutions.is_a?(Institutions::Institution) ? institution.code : institution.to_sym]
        }
        self.user_attributes=({:institutions => new_institutions}) unless new_institutions.empty?
      end

      def all_institutions
        @all_institutions ||= Institutions.institutions
      end
      private :all_institutions
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
authpds-0.2.4 lib/authpds/acts_as_authentic/institutions_attributes.rb
authpds-0.2.3 lib/authpds/acts_as_authentic/institutions_attributes.rb
authpds-0.2.2 lib/authpds/acts_as_authentic/institutions_attributes.rb
authpds-0.2.1 lib/authpds/acts_as_authentic/institutions_attributes.rb