Sha256: 09213c69e01af7a7188ae9f3c6fe47daed9798525ff6f62b9149d8f3a9e74250

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

require 'deprecation'
module Hydra::GenericUserAttributes
  extend Deprecation

  self.deprecation_horizon = 'hydra-head 5.x'

  USER_ATTRIBUTES = ['first_name','last_name','full_name','affiliation','photo']

  attr_writer :user_attributes

# Creates accessor methods for attributes defined in USER_ATTRIBUTES which return a string
  USER_ATTRIBUTES.each do |m|
    class_eval <<-EOM
      def #{m}
        get_user_attribute "#{m}"
      end
      deprecation_deprecate :#{m}
    EOM
  end

  
  # Retrieves the UserAttribute object for the user.  This defaults to the packaged ActiveRecord object, but can be overwritten with #user_attributes=
  # @return an object containing the user's attributes.  If providing a localized class, be sure to include the default attributes of first_name, last_name, full_name, affiliation and photo.
  def user_attributes
    @user_attributes ||= user_attribute
  end
  deprecation_deprecate :user_attributes

  private

  def user_attribute
   UserAttribute.find_by_user_id(self.id)
  end

  def get_user_attribute attr_name
    attr_name = attr_name.to_sym if attr_name.is_a? String
    user_attributes.nil? ? "" :  user_attributes.send(attr_name)
  end
 

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hydra-head-4.1.3 lib/hydra/generic_user_attributes.rb
hydra-head-4.1.2 lib/hydra/generic_user_attributes.rb
hydra-head-4.1.1 lib/hydra/generic_user_attributes.rb
hydra-head-4.1.0 lib/hydra/generic_user_attributes.rb
hydra-head-4.0.3 lib/hydra/generic_user_attributes.rb
hydra-head-4.0.2 lib/hydra/generic_user_attributes.rb