Class: Complish::User

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/complish/models/user.rb

Overview

The Complish User Class

Instance Attribute Summary collapse

Sequel::Model finder methods collapse

Validation Callbacks collapse

Class Method Summary collapse

Instance Attribute Details

#homeString

Returns the user's home directory

Examples:

Return the User home

Complish::User.first.home
 #=> 'foo/bar'

Returns:

  • (String)

    the user's home directory


35
36
37
38
39
40
41
42
43
44
45
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
# File 'lib/complish/models/user.rb', line 35

class User < Sequel::Model
  plugin :validation_helpers
  plugin :association_dependencies

  one_to_many :projects
  one_to_many :logs

  add_association_dependencies projects: :destroy, logs: :destroy

  # @!group Sequel::Model finder methods
  # @!method first_by_name(name)
  #  @version 1.0
  #  Find a single user by name
  #  @see http://sequel.jeremyevans.net/rdoc/classes/Sequel/Model/ClassMethods.html#method-i-finder
  #  @example Find a single user by name
  #   User.first_by_name('foo')
  #    #=> <#Complish::User>
  #  @param [String] name of the user name to query the dataset for
  #  @return [Complish::User, nil] the user found by the query
  finder :by_name
  # @!endgroup

  # @!group Validation Callbacks
  # @version 1.2
  # @api private
  # @see http://sequel.jeremyevans.net/rdoc/files/doc/validations_rdoc.html
  # @raise [Sequel::ValidationFailed] if name is not specified
  # @raise [Sequel::ValidationFailed] if home is not specified
  # @raise [Sequel::ValidationFailed] if name is not unique
  # @note a valid user:
  #
  #  * name must be present.
  #  * home must be present.
  #  * name must be unique.
  # @return [nil]
  def validate
    validates_presence %i(name home)
    validates_unique(:name)
    super
  end
  # @!endgroup

  # Find users by name
  # @version 1.0
  # @param [String] name the name to query the dataset for
  # @example Find a users by name
  #  User.by_name('foo')
  #   #=> [<#Complish::User>]
  # @return [Array<Complish::User>] The users found by the query
  def self.by_name(name)
    where(name: name)
  end

  # Finds or creates a user from ENV['USER'] and ENV['HOME']
  # @version 1.0
  # @example Find or create user from ENV
  #  Complish::User.find_or_create_from_env
  #   #=> <#Complish::User>
  # @return [Complish::User] the user found or created by method
  def self.find_or_create_from_env
    find_or_create(name: ENV['USER']) { |u| u.home = ENV['HOME'] }
  end
end

#idFixnum

Returns the id of the user

Examples:

Return the User id

Complish::User.first.id
 #=> 1

Returns:

  • (Fixnum)

    the id of the user


35
36
37
38
39
40
41
42
43
44
45
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
# File 'lib/complish/models/user.rb', line 35

class User < Sequel::Model
  plugin :validation_helpers
  plugin :association_dependencies

  one_to_many :projects
  one_to_many :logs

  add_association_dependencies projects: :destroy, logs: :destroy

  # @!group Sequel::Model finder methods
  # @!method first_by_name(name)
  #  @version 1.0
  #  Find a single user by name
  #  @see http://sequel.jeremyevans.net/rdoc/classes/Sequel/Model/ClassMethods.html#method-i-finder
  #  @example Find a single user by name
  #   User.first_by_name('foo')
  #    #=> <#Complish::User>
  #  @param [String] name of the user name to query the dataset for
  #  @return [Complish::User, nil] the user found by the query
  finder :by_name
  # @!endgroup

  # @!group Validation Callbacks
  # @version 1.2
  # @api private
  # @see http://sequel.jeremyevans.net/rdoc/files/doc/validations_rdoc.html
  # @raise [Sequel::ValidationFailed] if name is not specified
  # @raise [Sequel::ValidationFailed] if home is not specified
  # @raise [Sequel::ValidationFailed] if name is not unique
  # @note a valid user:
  #
  #  * name must be present.
  #  * home must be present.
  #  * name must be unique.
  # @return [nil]
  def validate
    validates_presence %i(name home)
    validates_unique(:name)
    super
  end
  # @!endgroup

  # Find users by name
  # @version 1.0
  # @param [String] name the name to query the dataset for
  # @example Find a users by name
  #  User.by_name('foo')
  #   #=> [<#Complish::User>]
  # @return [Array<Complish::User>] The users found by the query
  def self.by_name(name)
    where(name: name)
  end

  # Finds or creates a user from ENV['USER'] and ENV['HOME']
  # @version 1.0
  # @example Find or create user from ENV
  #  Complish::User.find_or_create_from_env
  #   #=> <#Complish::User>
  # @return [Complish::User] the user found or created by method
  def self.find_or_create_from_env
    find_or_create(name: ENV['USER']) { |u| u.home = ENV['HOME'] }
  end
end

#logsArray<Complish::Log>

Returns logs associated with user

Examples:

Return the User logs

Complish::User.first.logs
 #=> [<#Complish::Log>]

Returns:


35
36
37
38
39
40
41
42
43
44
45
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
# File 'lib/complish/models/user.rb', line 35

class User < Sequel::Model
  plugin :validation_helpers
  plugin :association_dependencies

  one_to_many :projects
  one_to_many :logs

  add_association_dependencies projects: :destroy, logs: :destroy

  # @!group Sequel::Model finder methods
  # @!method first_by_name(name)
  #  @version 1.0
  #  Find a single user by name
  #  @see http://sequel.jeremyevans.net/rdoc/classes/Sequel/Model/ClassMethods.html#method-i-finder
  #  @example Find a single user by name
  #   User.first_by_name('foo')
  #    #=> <#Complish::User>
  #  @param [String] name of the user name to query the dataset for
  #  @return [Complish::User, nil] the user found by the query
  finder :by_name
  # @!endgroup

  # @!group Validation Callbacks
  # @version 1.2
  # @api private
  # @see http://sequel.jeremyevans.net/rdoc/files/doc/validations_rdoc.html
  # @raise [Sequel::ValidationFailed] if name is not specified
  # @raise [Sequel::ValidationFailed] if home is not specified
  # @raise [Sequel::ValidationFailed] if name is not unique
  # @note a valid user:
  #
  #  * name must be present.
  #  * home must be present.
  #  * name must be unique.
  # @return [nil]
  def validate
    validates_presence %i(name home)
    validates_unique(:name)
    super
  end
  # @!endgroup

  # Find users by name
  # @version 1.0
  # @param [String] name the name to query the dataset for
  # @example Find a users by name
  #  User.by_name('foo')
  #   #=> [<#Complish::User>]
  # @return [Array<Complish::User>] The users found by the query
  def self.by_name(name)
    where(name: name)
  end

  # Finds or creates a user from ENV['USER'] and ENV['HOME']
  # @version 1.0
  # @example Find or create user from ENV
  #  Complish::User.find_or_create_from_env
  #   #=> <#Complish::User>
  # @return [Complish::User] the user found or created by method
  def self.find_or_create_from_env
    find_or_create(name: ENV['USER']) { |u| u.home = ENV['HOME'] }
  end
end

#nameString

Returns the user's username

Examples:

Return the User name

Complish::User.first.name
 #=> 'foo'

Returns:

  • (String)

    the user's username


35
36
37
38
39
40
41
42
43
44
45
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
# File 'lib/complish/models/user.rb', line 35

class User < Sequel::Model
  plugin :validation_helpers
  plugin :association_dependencies

  one_to_many :projects
  one_to_many :logs

  add_association_dependencies projects: :destroy, logs: :destroy

  # @!group Sequel::Model finder methods
  # @!method first_by_name(name)
  #  @version 1.0
  #  Find a single user by name
  #  @see http://sequel.jeremyevans.net/rdoc/classes/Sequel/Model/ClassMethods.html#method-i-finder
  #  @example Find a single user by name
  #   User.first_by_name('foo')
  #    #=> <#Complish::User>
  #  @param [String] name of the user name to query the dataset for
  #  @return [Complish::User, nil] the user found by the query
  finder :by_name
  # @!endgroup

  # @!group Validation Callbacks
  # @version 1.2
  # @api private
  # @see http://sequel.jeremyevans.net/rdoc/files/doc/validations_rdoc.html
  # @raise [Sequel::ValidationFailed] if name is not specified
  # @raise [Sequel::ValidationFailed] if home is not specified
  # @raise [Sequel::ValidationFailed] if name is not unique
  # @note a valid user:
  #
  #  * name must be present.
  #  * home must be present.
  #  * name must be unique.
  # @return [nil]
  def validate
    validates_presence %i(name home)
    validates_unique(:name)
    super
  end
  # @!endgroup

  # Find users by name
  # @version 1.0
  # @param [String] name the name to query the dataset for
  # @example Find a users by name
  #  User.by_name('foo')
  #   #=> [<#Complish::User>]
  # @return [Array<Complish::User>] The users found by the query
  def self.by_name(name)
    where(name: name)
  end

  # Finds or creates a user from ENV['USER'] and ENV['HOME']
  # @version 1.0
  # @example Find or create user from ENV
  #  Complish::User.find_or_create_from_env
  #   #=> <#Complish::User>
  # @return [Complish::User] the user found or created by method
  def self.find_or_create_from_env
    find_or_create(name: ENV['USER']) { |u| u.home = ENV['HOME'] }
  end
end

#projectsArray<Complish::Project>

Returns projects associated with user

Examples:

Return the User projects

Complish::User.first.projects
 #=> [<#Complish::Project>]

Returns:


35
36
37
38
39
40
41
42
43
44
45
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
# File 'lib/complish/models/user.rb', line 35

class User < Sequel::Model
  plugin :validation_helpers
  plugin :association_dependencies

  one_to_many :projects
  one_to_many :logs

  add_association_dependencies projects: :destroy, logs: :destroy

  # @!group Sequel::Model finder methods
  # @!method first_by_name(name)
  #  @version 1.0
  #  Find a single user by name
  #  @see http://sequel.jeremyevans.net/rdoc/classes/Sequel/Model/ClassMethods.html#method-i-finder
  #  @example Find a single user by name
  #   User.first_by_name('foo')
  #    #=> <#Complish::User>
  #  @param [String] name of the user name to query the dataset for
  #  @return [Complish::User, nil] the user found by the query
  finder :by_name
  # @!endgroup

  # @!group Validation Callbacks
  # @version 1.2
  # @api private
  # @see http://sequel.jeremyevans.net/rdoc/files/doc/validations_rdoc.html
  # @raise [Sequel::ValidationFailed] if name is not specified
  # @raise [Sequel::ValidationFailed] if home is not specified
  # @raise [Sequel::ValidationFailed] if name is not unique
  # @note a valid user:
  #
  #  * name must be present.
  #  * home must be present.
  #  * name must be unique.
  # @return [nil]
  def validate
    validates_presence %i(name home)
    validates_unique(:name)
    super
  end
  # @!endgroup

  # Find users by name
  # @version 1.0
  # @param [String] name the name to query the dataset for
  # @example Find a users by name
  #  User.by_name('foo')
  #   #=> [<#Complish::User>]
  # @return [Array<Complish::User>] The users found by the query
  def self.by_name(name)
    where(name: name)
  end

  # Finds or creates a user from ENV['USER'] and ENV['HOME']
  # @version 1.0
  # @example Find or create user from ENV
  #  Complish::User.find_or_create_from_env
  #   #=> <#Complish::User>
  # @return [Complish::User] the user found or created by method
  def self.find_or_create_from_env
    find_or_create(name: ENV['USER']) { |u| u.home = ENV['HOME'] }
  end
end

Class Method Details

.by_name(name) ⇒ Array<Complish::User>

Find users by name

Examples:

Find a users by name

User.by_name('foo')
 #=> [<#Complish::User>]

Parameters:

  • name (String)

    the name to query the dataset for

Returns:

Since:

  • 0.1.0-alpha

Version:

  • 1.0


84
85
86
# File 'lib/complish/models/user.rb', line 84

def self.by_name(name)
  where(name: name)
end

.find_or_create_from_envComplish::User

Finds or creates a user from ENV['USER'] and ENV['HOME']

Examples:

Find or create user from ENV

Complish::User.find_or_create_from_env
 #=> <#Complish::User>

Returns:

Since:

  • 0.1.0-alpha

Version:

  • 1.0


94
95
96
# File 'lib/complish/models/user.rb', line 94

def self.find_or_create_from_env
  find_or_create(name: ENV['USER']) { |u| u.home = ENV['HOME'] }
end

Instance Method Details

#first_by_name(name) ⇒ Complish::User?

Find a single user by name

Examples:

Find a single user by name

User.first_by_name('foo')
 #=> <#Complish::User>

Parameters:

  • name (String)

    of the user name to query the dataset for

Returns:

See Also:

Version:

  • 1.0


54
# File 'lib/complish/models/user.rb', line 54

finder :by_name

#validatenil

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

a valid user:

  • name must be present.
  • home must be present.
  • name must be unique.

Returns:

  • (nil)

Raises:

  • (Sequel::ValidationFailed)

    if name is not specified

  • (Sequel::ValidationFailed)

    if home is not specified

  • (Sequel::ValidationFailed)

    if name is not unique

See Also:

Since:

  • 0.1.0-alpha

Version:

  • 1.2


70
71
72
73
74
# File 'lib/complish/models/user.rb', line 70

def validate
  validates_presence %i(name home)
  validates_unique(:name)
  super
end