Sha256: 05ae20d774231756de7818b01b89763112631932a97dc70fe9b8a3f43c745b0f

Contents?: true

Size: 1.35 KB

Versions: 9

Compression:

Stored size: 1.35 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}) unless new_primary_institution.nil?
      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

9 entries across 9 versions & 1 rubygems

Version Path
authpds-1.1.2 lib/authpds/acts_as_authentic/institutions_attributes.rb
authpds-1.1.1 lib/authpds/acts_as_authentic/institutions_attributes.rb
authpds-1.1.0 lib/authpds/acts_as_authentic/institutions_attributes.rb
authpds-1.0.0 lib/authpds/acts_as_authentic/institutions_attributes.rb
authpds-0.2.9 lib/authpds/acts_as_authentic/institutions_attributes.rb
authpds-0.2.8 lib/authpds/acts_as_authentic/institutions_attributes.rb
authpds-0.2.7 lib/authpds/acts_as_authentic/institutions_attributes.rb
authpds-0.2.6 lib/authpds/acts_as_authentic/institutions_attributes.rb
authpds-0.2.5 lib/authpds/acts_as_authentic/institutions_attributes.rb