Class: User

Inherits:
ActiveRecord::Base show all
Defined in:
app/models/user.rb

Overview

Representation of a user in the database

RLetters keeps track of users so that it can send e-mails regarding background jobs and keep a set of customizable user options.

Defined Under Namespace

Classes: ParameterSanitizer

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from ActiveRecord::Base

logger

Instance Attribute Details

- (Integer) csl_style_id



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

- (Array<Dataset>) datasets

Returns All datasets created by the user (has_many)

Raises:

  • (RecordInvalid)

    if any of the datasets are invalid (validates_associated)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

- (String) email



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

- (String) language

Returns Locale code of user's preferred language

Raises:

  • (RecordInvalid)

    if the language is missing (validates :presence)

  • (RecordInvalid)

    if the language is not a valid language code (validates :format)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

- (Array<Library>) libraries

Returns All library links added by the user (has_many)

Raises:

  • (RecordInvalid)

    if any of the libraries are invalid (validates_associated)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

- (String) name

Returns Full name

Raises:

  • (RecordInvalid)

    if the name is missing (validates :presence)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

- (String) password



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

- (String) password_confirmation



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

- (Integer) per_page

Returns Number of search results to display per page

Raises:

  • (RecordInvalid)

    if per_page is missing (validates :presence)

  • (RecordInvalid)

    if per_page is not an integer (validates :numericality)

  • (RecordInvalid)

    if per_page is negative (validates :inclusion)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

- (Boolean) remember_me



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

- (String) timezone

Returns User's timezone, in Rails' format

Raises:

  • (RecordInvalid)

    if the timezone is missing (validates :presence)



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/user.rb', line 46

class User < ActiveRecord::Base
  devise :async, :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  validates :name, presence: true
  validates :per_page, presence: true
  validates :per_page, numericality: { only_integer: true }
  validates :per_page, inclusion: { in: 1..999_999_999 }
  validates :language, presence: true
  validates :language, format: { with: /\A[a-z]{2,3}(-[A-Z]{2})?\Z/ }
  validates :timezone, presence: true

  has_many :datasets, dependent: :delete_all
  has_many :libraries, dependent: :delete_all

  validates_associated :datasets
  validates_associated :libraries

  # Convert the +csl_style_id+ to a CslStyle (or nil)
  #
  # @api public
  # @return [CslStyle] the user's CSL style (or nil)
  # @example Format a document with a user's CSL style
  #   @document.to_csl_entry(@user.csl_style)
  #   # Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!
  def csl_style
    CslStyle.find(csl_style_id) rescue nil
  end

  # Parameter sanitizer class for regular users
  #
  # Attributes that can be edited by the user (in the user options form)
  # should be whitelisted here.  This should be kept in sync with the views
  # in users/registrations/{edit,new}.html.
  #
  # This class is not tested, as it's only ever called from within the
  # internals of Devise.
  #
  # @see ApplicationController::devise_parameter_sanitizer
  # :nocov:
  class ParameterSanitizer < Devise::ParameterSanitizer
    # Permit the parameters used in the sign up form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :language, :timezone)
    end

    # Permit the parameters used in the user edit form
    # @return [ActionController::Parameters] permitted parameters
    def 
      default_params.permit(:name, :email, :password, :password_confirmation,
                            :current_password, :language, :timezone, :per_page,
                            :csl_style_id)
    end
  end
  # :nocov:
end

Instance Method Details

- (CslStyle) csl_style

Convert the csl_style_id to a CslStyle (or nil)

Examples:

Format a document with a user's CSL style

@document.to_csl_entry(@user.csl_style)
# Note: Do *not* call to_csl_entry with @user.csl_style_id, it will fail!


71
72
73
# File 'app/models/user.rb', line 71

def csl_style
  CslStyle.find(csl_style_id) rescue nil
end