Class: Complish::Project

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

Overview

The Complish Project class

Instance Attribute Summary collapse

Sequel::Model finder methods collapse

Validation Callbacks collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idFixnum

Returns the project id

Examples:

Return the Project id

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

Returns:

  • (Fixnum)

    the project id


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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/complish/models/project.rb', line 42

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

  many_to_one :user
  one_to_many :logs

  add_association_dependencies logs: :destroy

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

  # @!method first_by_pwd(pwd)
  #  Find a single project by pwd
  #  @version 1.0
  #  @see http://sequel.jeremyevans.net/rdoc/classes/Sequel/Model/ClassMethods.html#method-i-finder
  #  @example Find a single project by pwd
  #   Complish::Project.first_by_pwd('bar')
  #    #=> <#Complish::Project>
  #  @param [String] pwd the directory to query the dataset for
  #  @return [Complish::Project, nil] the project found by the query
  finder :by_pwd

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

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

  # Find Projects by name
  # @version 1.0
  # @example Find projects by name
  #   Complish::Project.by_name('foo')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Complish::Project.by_name('foo').all
  #    #=> [<#Complish::Project>]
  # @param [String] name the name to query the dataset for
  # @return [Sequel::SQLite::Dataset] the dataset of projects found by query
  def self.by_name(name)
    where(name: name)
  end

  # Find projects by pwd
  # @version 1.0
  # @example Find projects by pwd
  #   Complish::Project.by_pwd('foo/bar')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Complish::Project.by_pwd('foo/bar').all
  #    #=> [<#Complish::Project>]
  # @param [String] pwd the directory to query the dataset for
  # @return [Sequel::SQLite::Dataset] the dataset of projects found by query
  def self.by_pwd(pwd)
    where(pwd: pwd)
  end

  # Find projects by user and name
  # @version 1.0
  # @example Find projects by user and name
  #   user = Complish::User.first
  #    #=> <#Complish::User>
  #   Project.by_user_and_name(user, 'foo')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Project.by_user_and_name(user, 'foo').all
  #    #=> [<#Complish::Project>]
  # @param [Complish::User] user the user to query the dataset for
  # @param [String] name the name to query the dataset for
  # @return [Sequel::SQLite::Dataset] and dataset of projects by user and name
  def self.by_user_and_name(user, name)
    where(user: user, name: name)
  end

  # Finds or creates a project from ENV['PWD']
  # @version 1.1
  # @example Find or create a project usning ENV['PWD']
  #  user = Complish::User.first
  #   #=> <#Complish::User>
  #  Complish::Project.find_or_create_from_env(user)
  #   #=> <#Complish::Project>
  # @param [Complish::User] user the user that the project belongs to
  # @note if no user is provided user will default to Complish::User.find_or_create_from_env
  # @note the project name will default to the last path part of ENV['PWD']
  # @return [Complish::Project] the project found or created by method
  def self.find_or_create_from_env(user = nil)
    user ||= Complish::User.find_or_create_from_env
    find_or_create(user: user, pwd: ENV['PWD']) do |p|
      p.name = File.basename(ENV['PWD'])
    end
  end

  # @!group Sequel::Model ClassMethods
  # @!method new(opts)
  #  Create a new instance of Project
  #  @version 1.0
  #  @example Build a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   Complish::Project.new(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #  @param [Hash{Symbol=>Hash, String}] opts the options to create the Project with
  #  @option opts [Complish::User] user the user the Project belongs to
  #  @option opts [String] name the name of the project
  #  @option opts [String] pwd the working directory of the project
  #  @raise [Sequel::ValidationFailed] if user is not specified
  #  @raise [Sequel::ValidationFailed] if name is not specified
  #  @raise [Sequel::ValidationFailed] if pwd is not specified
  #  @raise [Sequel::ValidationFailed] if name is not unique to user
  #  @return [Complish::Project] the instance of Project
  #
  # @!method create(opts)
  #  Create a new Project and persist it in the database
  #  @version 1.0
  #  @example Create a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   Complish::Project.create(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #  @param [Hash{Symbol=>Hash, String}] opts the options to create the Project with
  #  @option opts [Complish::User] user the user the Project belongs to
  #  @option opts [String] name the name of the project
  #  @option opts [String] pwd the working directory of the project
  #  @raise [Sequel::ValidationFailed] if user is not specified
  #  @raise [Sequel::ValidationFailed] if name is not specified
  #  @raise [Sequel::ValidationFailed] if pwd is not specified
  #  @raise [Sequel::ValidationFailed] if name is not unique to user
  #  @return [Complish::Project] the created Project
  #
  # @!method save
  #  Save an instance of Project to the database
  #  @version 1.0
  #  @example Build a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   project = Complish::Project.new(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #   project.save
  #    #=> <#Complish::Project>
  #  @return [Complish::Project] the saved Project
  # @!endgroup
end

#logsArray<Complish::Log>

Returns the logs associated with the project

Examples:

Return the Project logs

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

Returns:

  • (Array<Complish::Log>)

    the logs associated with the project


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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/complish/models/project.rb', line 42

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

  many_to_one :user
  one_to_many :logs

  add_association_dependencies logs: :destroy

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

  # @!method first_by_pwd(pwd)
  #  Find a single project by pwd
  #  @version 1.0
  #  @see http://sequel.jeremyevans.net/rdoc/classes/Sequel/Model/ClassMethods.html#method-i-finder
  #  @example Find a single project by pwd
  #   Complish::Project.first_by_pwd('bar')
  #    #=> <#Complish::Project>
  #  @param [String] pwd the directory to query the dataset for
  #  @return [Complish::Project, nil] the project found by the query
  finder :by_pwd

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

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

  # Find Projects by name
  # @version 1.0
  # @example Find projects by name
  #   Complish::Project.by_name('foo')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Complish::Project.by_name('foo').all
  #    #=> [<#Complish::Project>]
  # @param [String] name the name to query the dataset for
  # @return [Sequel::SQLite::Dataset] the dataset of projects found by query
  def self.by_name(name)
    where(name: name)
  end

  # Find projects by pwd
  # @version 1.0
  # @example Find projects by pwd
  #   Complish::Project.by_pwd('foo/bar')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Complish::Project.by_pwd('foo/bar').all
  #    #=> [<#Complish::Project>]
  # @param [String] pwd the directory to query the dataset for
  # @return [Sequel::SQLite::Dataset] the dataset of projects found by query
  def self.by_pwd(pwd)
    where(pwd: pwd)
  end

  # Find projects by user and name
  # @version 1.0
  # @example Find projects by user and name
  #   user = Complish::User.first
  #    #=> <#Complish::User>
  #   Project.by_user_and_name(user, 'foo')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Project.by_user_and_name(user, 'foo').all
  #    #=> [<#Complish::Project>]
  # @param [Complish::User] user the user to query the dataset for
  # @param [String] name the name to query the dataset for
  # @return [Sequel::SQLite::Dataset] and dataset of projects by user and name
  def self.by_user_and_name(user, name)
    where(user: user, name: name)
  end

  # Finds or creates a project from ENV['PWD']
  # @version 1.1
  # @example Find or create a project usning ENV['PWD']
  #  user = Complish::User.first
  #   #=> <#Complish::User>
  #  Complish::Project.find_or_create_from_env(user)
  #   #=> <#Complish::Project>
  # @param [Complish::User] user the user that the project belongs to
  # @note if no user is provided user will default to Complish::User.find_or_create_from_env
  # @note the project name will default to the last path part of ENV['PWD']
  # @return [Complish::Project] the project found or created by method
  def self.find_or_create_from_env(user = nil)
    user ||= Complish::User.find_or_create_from_env
    find_or_create(user: user, pwd: ENV['PWD']) do |p|
      p.name = File.basename(ENV['PWD'])
    end
  end

  # @!group Sequel::Model ClassMethods
  # @!method new(opts)
  #  Create a new instance of Project
  #  @version 1.0
  #  @example Build a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   Complish::Project.new(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #  @param [Hash{Symbol=>Hash, String}] opts the options to create the Project with
  #  @option opts [Complish::User] user the user the Project belongs to
  #  @option opts [String] name the name of the project
  #  @option opts [String] pwd the working directory of the project
  #  @raise [Sequel::ValidationFailed] if user is not specified
  #  @raise [Sequel::ValidationFailed] if name is not specified
  #  @raise [Sequel::ValidationFailed] if pwd is not specified
  #  @raise [Sequel::ValidationFailed] if name is not unique to user
  #  @return [Complish::Project] the instance of Project
  #
  # @!method create(opts)
  #  Create a new Project and persist it in the database
  #  @version 1.0
  #  @example Create a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   Complish::Project.create(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #  @param [Hash{Symbol=>Hash, String}] opts the options to create the Project with
  #  @option opts [Complish::User] user the user the Project belongs to
  #  @option opts [String] name the name of the project
  #  @option opts [String] pwd the working directory of the project
  #  @raise [Sequel::ValidationFailed] if user is not specified
  #  @raise [Sequel::ValidationFailed] if name is not specified
  #  @raise [Sequel::ValidationFailed] if pwd is not specified
  #  @raise [Sequel::ValidationFailed] if name is not unique to user
  #  @return [Complish::Project] the created Project
  #
  # @!method save
  #  Save an instance of Project to the database
  #  @version 1.0
  #  @example Build a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   project = Complish::Project.new(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #   project.save
  #    #=> <#Complish::Project>
  #  @return [Complish::Project] the saved Project
  # @!endgroup
end

#nameString

Returns the name of the project

Examples:

Return the Project name

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

Returns:

  • (String)

    the name of the project


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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/complish/models/project.rb', line 42

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

  many_to_one :user
  one_to_many :logs

  add_association_dependencies logs: :destroy

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

  # @!method first_by_pwd(pwd)
  #  Find a single project by pwd
  #  @version 1.0
  #  @see http://sequel.jeremyevans.net/rdoc/classes/Sequel/Model/ClassMethods.html#method-i-finder
  #  @example Find a single project by pwd
  #   Complish::Project.first_by_pwd('bar')
  #    #=> <#Complish::Project>
  #  @param [String] pwd the directory to query the dataset for
  #  @return [Complish::Project, nil] the project found by the query
  finder :by_pwd

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

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

  # Find Projects by name
  # @version 1.0
  # @example Find projects by name
  #   Complish::Project.by_name('foo')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Complish::Project.by_name('foo').all
  #    #=> [<#Complish::Project>]
  # @param [String] name the name to query the dataset for
  # @return [Sequel::SQLite::Dataset] the dataset of projects found by query
  def self.by_name(name)
    where(name: name)
  end

  # Find projects by pwd
  # @version 1.0
  # @example Find projects by pwd
  #   Complish::Project.by_pwd('foo/bar')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Complish::Project.by_pwd('foo/bar').all
  #    #=> [<#Complish::Project>]
  # @param [String] pwd the directory to query the dataset for
  # @return [Sequel::SQLite::Dataset] the dataset of projects found by query
  def self.by_pwd(pwd)
    where(pwd: pwd)
  end

  # Find projects by user and name
  # @version 1.0
  # @example Find projects by user and name
  #   user = Complish::User.first
  #    #=> <#Complish::User>
  #   Project.by_user_and_name(user, 'foo')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Project.by_user_and_name(user, 'foo').all
  #    #=> [<#Complish::Project>]
  # @param [Complish::User] user the user to query the dataset for
  # @param [String] name the name to query the dataset for
  # @return [Sequel::SQLite::Dataset] and dataset of projects by user and name
  def self.by_user_and_name(user, name)
    where(user: user, name: name)
  end

  # Finds or creates a project from ENV['PWD']
  # @version 1.1
  # @example Find or create a project usning ENV['PWD']
  #  user = Complish::User.first
  #   #=> <#Complish::User>
  #  Complish::Project.find_or_create_from_env(user)
  #   #=> <#Complish::Project>
  # @param [Complish::User] user the user that the project belongs to
  # @note if no user is provided user will default to Complish::User.find_or_create_from_env
  # @note the project name will default to the last path part of ENV['PWD']
  # @return [Complish::Project] the project found or created by method
  def self.find_or_create_from_env(user = nil)
    user ||= Complish::User.find_or_create_from_env
    find_or_create(user: user, pwd: ENV['PWD']) do |p|
      p.name = File.basename(ENV['PWD'])
    end
  end

  # @!group Sequel::Model ClassMethods
  # @!method new(opts)
  #  Create a new instance of Project
  #  @version 1.0
  #  @example Build a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   Complish::Project.new(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #  @param [Hash{Symbol=>Hash, String}] opts the options to create the Project with
  #  @option opts [Complish::User] user the user the Project belongs to
  #  @option opts [String] name the name of the project
  #  @option opts [String] pwd the working directory of the project
  #  @raise [Sequel::ValidationFailed] if user is not specified
  #  @raise [Sequel::ValidationFailed] if name is not specified
  #  @raise [Sequel::ValidationFailed] if pwd is not specified
  #  @raise [Sequel::ValidationFailed] if name is not unique to user
  #  @return [Complish::Project] the instance of Project
  #
  # @!method create(opts)
  #  Create a new Project and persist it in the database
  #  @version 1.0
  #  @example Create a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   Complish::Project.create(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #  @param [Hash{Symbol=>Hash, String}] opts the options to create the Project with
  #  @option opts [Complish::User] user the user the Project belongs to
  #  @option opts [String] name the name of the project
  #  @option opts [String] pwd the working directory of the project
  #  @raise [Sequel::ValidationFailed] if user is not specified
  #  @raise [Sequel::ValidationFailed] if name is not specified
  #  @raise [Sequel::ValidationFailed] if pwd is not specified
  #  @raise [Sequel::ValidationFailed] if name is not unique to user
  #  @return [Complish::Project] the created Project
  #
  # @!method save
  #  Save an instance of Project to the database
  #  @version 1.0
  #  @example Build a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   project = Complish::Project.new(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #   project.save
  #    #=> <#Complish::Project>
  #  @return [Complish::Project] the saved Project
  # @!endgroup
end

#pwdString

Returns the working directory of the project

Examples:

Return the Project pwd

Complish::Project.first.pwd
 #=> 'foo/bar'

Returns:

  • (String)

    the working directory of the project


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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/complish/models/project.rb', line 42

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

  many_to_one :user
  one_to_many :logs

  add_association_dependencies logs: :destroy

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

  # @!method first_by_pwd(pwd)
  #  Find a single project by pwd
  #  @version 1.0
  #  @see http://sequel.jeremyevans.net/rdoc/classes/Sequel/Model/ClassMethods.html#method-i-finder
  #  @example Find a single project by pwd
  #   Complish::Project.first_by_pwd('bar')
  #    #=> <#Complish::Project>
  #  @param [String] pwd the directory to query the dataset for
  #  @return [Complish::Project, nil] the project found by the query
  finder :by_pwd

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

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

  # Find Projects by name
  # @version 1.0
  # @example Find projects by name
  #   Complish::Project.by_name('foo')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Complish::Project.by_name('foo').all
  #    #=> [<#Complish::Project>]
  # @param [String] name the name to query the dataset for
  # @return [Sequel::SQLite::Dataset] the dataset of projects found by query
  def self.by_name(name)
    where(name: name)
  end

  # Find projects by pwd
  # @version 1.0
  # @example Find projects by pwd
  #   Complish::Project.by_pwd('foo/bar')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Complish::Project.by_pwd('foo/bar').all
  #    #=> [<#Complish::Project>]
  # @param [String] pwd the directory to query the dataset for
  # @return [Sequel::SQLite::Dataset] the dataset of projects found by query
  def self.by_pwd(pwd)
    where(pwd: pwd)
  end

  # Find projects by user and name
  # @version 1.0
  # @example Find projects by user and name
  #   user = Complish::User.first
  #    #=> <#Complish::User>
  #   Project.by_user_and_name(user, 'foo')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Project.by_user_and_name(user, 'foo').all
  #    #=> [<#Complish::Project>]
  # @param [Complish::User] user the user to query the dataset for
  # @param [String] name the name to query the dataset for
  # @return [Sequel::SQLite::Dataset] and dataset of projects by user and name
  def self.by_user_and_name(user, name)
    where(user: user, name: name)
  end

  # Finds or creates a project from ENV['PWD']
  # @version 1.1
  # @example Find or create a project usning ENV['PWD']
  #  user = Complish::User.first
  #   #=> <#Complish::User>
  #  Complish::Project.find_or_create_from_env(user)
  #   #=> <#Complish::Project>
  # @param [Complish::User] user the user that the project belongs to
  # @note if no user is provided user will default to Complish::User.find_or_create_from_env
  # @note the project name will default to the last path part of ENV['PWD']
  # @return [Complish::Project] the project found or created by method
  def self.find_or_create_from_env(user = nil)
    user ||= Complish::User.find_or_create_from_env
    find_or_create(user: user, pwd: ENV['PWD']) do |p|
      p.name = File.basename(ENV['PWD'])
    end
  end

  # @!group Sequel::Model ClassMethods
  # @!method new(opts)
  #  Create a new instance of Project
  #  @version 1.0
  #  @example Build a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   Complish::Project.new(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #  @param [Hash{Symbol=>Hash, String}] opts the options to create the Project with
  #  @option opts [Complish::User] user the user the Project belongs to
  #  @option opts [String] name the name of the project
  #  @option opts [String] pwd the working directory of the project
  #  @raise [Sequel::ValidationFailed] if user is not specified
  #  @raise [Sequel::ValidationFailed] if name is not specified
  #  @raise [Sequel::ValidationFailed] if pwd is not specified
  #  @raise [Sequel::ValidationFailed] if name is not unique to user
  #  @return [Complish::Project] the instance of Project
  #
  # @!method create(opts)
  #  Create a new Project and persist it in the database
  #  @version 1.0
  #  @example Create a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   Complish::Project.create(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #  @param [Hash{Symbol=>Hash, String}] opts the options to create the Project with
  #  @option opts [Complish::User] user the user the Project belongs to
  #  @option opts [String] name the name of the project
  #  @option opts [String] pwd the working directory of the project
  #  @raise [Sequel::ValidationFailed] if user is not specified
  #  @raise [Sequel::ValidationFailed] if name is not specified
  #  @raise [Sequel::ValidationFailed] if pwd is not specified
  #  @raise [Sequel::ValidationFailed] if name is not unique to user
  #  @return [Complish::Project] the created Project
  #
  # @!method save
  #  Save an instance of Project to the database
  #  @version 1.0
  #  @example Build a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   project = Complish::Project.new(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #   project.save
  #    #=> <#Complish::Project>
  #  @return [Complish::Project] the saved Project
  # @!endgroup
end

#userComplish::User

Returns the user the project belongs to

Examples:

Return the Project user

Complish::Project.first.user
 #=> <#Complish::User>

Returns:


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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/complish/models/project.rb', line 42

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

  many_to_one :user
  one_to_many :logs

  add_association_dependencies logs: :destroy

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

  # @!method first_by_pwd(pwd)
  #  Find a single project by pwd
  #  @version 1.0
  #  @see http://sequel.jeremyevans.net/rdoc/classes/Sequel/Model/ClassMethods.html#method-i-finder
  #  @example Find a single project by pwd
  #   Complish::Project.first_by_pwd('bar')
  #    #=> <#Complish::Project>
  #  @param [String] pwd the directory to query the dataset for
  #  @return [Complish::Project, nil] the project found by the query
  finder :by_pwd

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

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

  # Find Projects by name
  # @version 1.0
  # @example Find projects by name
  #   Complish::Project.by_name('foo')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Complish::Project.by_name('foo').all
  #    #=> [<#Complish::Project>]
  # @param [String] name the name to query the dataset for
  # @return [Sequel::SQLite::Dataset] the dataset of projects found by query
  def self.by_name(name)
    where(name: name)
  end

  # Find projects by pwd
  # @version 1.0
  # @example Find projects by pwd
  #   Complish::Project.by_pwd('foo/bar')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Complish::Project.by_pwd('foo/bar').all
  #    #=> [<#Complish::Project>]
  # @param [String] pwd the directory to query the dataset for
  # @return [Sequel::SQLite::Dataset] the dataset of projects found by query
  def self.by_pwd(pwd)
    where(pwd: pwd)
  end

  # Find projects by user and name
  # @version 1.0
  # @example Find projects by user and name
  #   user = Complish::User.first
  #    #=> <#Complish::User>
  #   Project.by_user_and_name(user, 'foo')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Project.by_user_and_name(user, 'foo').all
  #    #=> [<#Complish::Project>]
  # @param [Complish::User] user the user to query the dataset for
  # @param [String] name the name to query the dataset for
  # @return [Sequel::SQLite::Dataset] and dataset of projects by user and name
  def self.by_user_and_name(user, name)
    where(user: user, name: name)
  end

  # Finds or creates a project from ENV['PWD']
  # @version 1.1
  # @example Find or create a project usning ENV['PWD']
  #  user = Complish::User.first
  #   #=> <#Complish::User>
  #  Complish::Project.find_or_create_from_env(user)
  #   #=> <#Complish::Project>
  # @param [Complish::User] user the user that the project belongs to
  # @note if no user is provided user will default to Complish::User.find_or_create_from_env
  # @note the project name will default to the last path part of ENV['PWD']
  # @return [Complish::Project] the project found or created by method
  def self.find_or_create_from_env(user = nil)
    user ||= Complish::User.find_or_create_from_env
    find_or_create(user: user, pwd: ENV['PWD']) do |p|
      p.name = File.basename(ENV['PWD'])
    end
  end

  # @!group Sequel::Model ClassMethods
  # @!method new(opts)
  #  Create a new instance of Project
  #  @version 1.0
  #  @example Build a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   Complish::Project.new(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #  @param [Hash{Symbol=>Hash, String}] opts the options to create the Project with
  #  @option opts [Complish::User] user the user the Project belongs to
  #  @option opts [String] name the name of the project
  #  @option opts [String] pwd the working directory of the project
  #  @raise [Sequel::ValidationFailed] if user is not specified
  #  @raise [Sequel::ValidationFailed] if name is not specified
  #  @raise [Sequel::ValidationFailed] if pwd is not specified
  #  @raise [Sequel::ValidationFailed] if name is not unique to user
  #  @return [Complish::Project] the instance of Project
  #
  # @!method create(opts)
  #  Create a new Project and persist it in the database
  #  @version 1.0
  #  @example Create a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   Complish::Project.create(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #  @param [Hash{Symbol=>Hash, String}] opts the options to create the Project with
  #  @option opts [Complish::User] user the user the Project belongs to
  #  @option opts [String] name the name of the project
  #  @option opts [String] pwd the working directory of the project
  #  @raise [Sequel::ValidationFailed] if user is not specified
  #  @raise [Sequel::ValidationFailed] if name is not specified
  #  @raise [Sequel::ValidationFailed] if pwd is not specified
  #  @raise [Sequel::ValidationFailed] if name is not unique to user
  #  @return [Complish::Project] the created Project
  #
  # @!method save
  #  Save an instance of Project to the database
  #  @version 1.0
  #  @example Build a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   project = Complish::Project.new(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #   project.save
  #    #=> <#Complish::Project>
  #  @return [Complish::Project] the saved Project
  # @!endgroup
end

#user_idrw

Returns the id of the project user

Examples:

Return the Project user_id

Complish::Project.first.user_id
 #=> 1

Returns:

  • (rw)

    the id of the project user


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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/complish/models/project.rb', line 42

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

  many_to_one :user
  one_to_many :logs

  add_association_dependencies logs: :destroy

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

  # @!method first_by_pwd(pwd)
  #  Find a single project by pwd
  #  @version 1.0
  #  @see http://sequel.jeremyevans.net/rdoc/classes/Sequel/Model/ClassMethods.html#method-i-finder
  #  @example Find a single project by pwd
  #   Complish::Project.first_by_pwd('bar')
  #    #=> <#Complish::Project>
  #  @param [String] pwd the directory to query the dataset for
  #  @return [Complish::Project, nil] the project found by the query
  finder :by_pwd

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

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

  # Find Projects by name
  # @version 1.0
  # @example Find projects by name
  #   Complish::Project.by_name('foo')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Complish::Project.by_name('foo').all
  #    #=> [<#Complish::Project>]
  # @param [String] name the name to query the dataset for
  # @return [Sequel::SQLite::Dataset] the dataset of projects found by query
  def self.by_name(name)
    where(name: name)
  end

  # Find projects by pwd
  # @version 1.0
  # @example Find projects by pwd
  #   Complish::Project.by_pwd('foo/bar')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Complish::Project.by_pwd('foo/bar').all
  #    #=> [<#Complish::Project>]
  # @param [String] pwd the directory to query the dataset for
  # @return [Sequel::SQLite::Dataset] the dataset of projects found by query
  def self.by_pwd(pwd)
    where(pwd: pwd)
  end

  # Find projects by user and name
  # @version 1.0
  # @example Find projects by user and name
  #   user = Complish::User.first
  #    #=> <#Complish::User>
  #   Project.by_user_and_name(user, 'foo')
  #    #=> <#Sequel::SQLite::Dataset>
  #   Project.by_user_and_name(user, 'foo').all
  #    #=> [<#Complish::Project>]
  # @param [Complish::User] user the user to query the dataset for
  # @param [String] name the name to query the dataset for
  # @return [Sequel::SQLite::Dataset] and dataset of projects by user and name
  def self.by_user_and_name(user, name)
    where(user: user, name: name)
  end

  # Finds or creates a project from ENV['PWD']
  # @version 1.1
  # @example Find or create a project usning ENV['PWD']
  #  user = Complish::User.first
  #   #=> <#Complish::User>
  #  Complish::Project.find_or_create_from_env(user)
  #   #=> <#Complish::Project>
  # @param [Complish::User] user the user that the project belongs to
  # @note if no user is provided user will default to Complish::User.find_or_create_from_env
  # @note the project name will default to the last path part of ENV['PWD']
  # @return [Complish::Project] the project found or created by method
  def self.find_or_create_from_env(user = nil)
    user ||= Complish::User.find_or_create_from_env
    find_or_create(user: user, pwd: ENV['PWD']) do |p|
      p.name = File.basename(ENV['PWD'])
    end
  end

  # @!group Sequel::Model ClassMethods
  # @!method new(opts)
  #  Create a new instance of Project
  #  @version 1.0
  #  @example Build a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   Complish::Project.new(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #  @param [Hash{Symbol=>Hash, String}] opts the options to create the Project with
  #  @option opts [Complish::User] user the user the Project belongs to
  #  @option opts [String] name the name of the project
  #  @option opts [String] pwd the working directory of the project
  #  @raise [Sequel::ValidationFailed] if user is not specified
  #  @raise [Sequel::ValidationFailed] if name is not specified
  #  @raise [Sequel::ValidationFailed] if pwd is not specified
  #  @raise [Sequel::ValidationFailed] if name is not unique to user
  #  @return [Complish::Project] the instance of Project
  #
  # @!method create(opts)
  #  Create a new Project and persist it in the database
  #  @version 1.0
  #  @example Create a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   Complish::Project.create(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #  @param [Hash{Symbol=>Hash, String}] opts the options to create the Project with
  #  @option opts [Complish::User] user the user the Project belongs to
  #  @option opts [String] name the name of the project
  #  @option opts [String] pwd the working directory of the project
  #  @raise [Sequel::ValidationFailed] if user is not specified
  #  @raise [Sequel::ValidationFailed] if name is not specified
  #  @raise [Sequel::ValidationFailed] if pwd is not specified
  #  @raise [Sequel::ValidationFailed] if name is not unique to user
  #  @return [Complish::Project] the created Project
  #
  # @!method save
  #  Save an instance of Project to the database
  #  @version 1.0
  #  @example Build a new project
  #   user = Complish::User.new
  #    #=> <#Complish::User>
  #   project = Complish::Project.new(user: user, name: 'foo', pwd: 'foo/bar')
  #    #=> <#Complish::Project>
  #   project.save
  #    #=> <#Complish::Project>
  #  @return [Complish::Project] the saved Project
  # @!endgroup
end

Class Method Details

.by_name(name) ⇒ Sequel::SQLite::Dataset

Find Projects by name

Examples:

Find projects by name

Complish::Project.by_name('foo')
 #=> <#Sequel::SQLite::Dataset>
Complish::Project.by_name('foo').all
 #=> [<#Complish::Project>]

Parameters:

  • name (String)

    the name to query the dataset for

Returns:

  • (Sequel::SQLite::Dataset)

    the dataset of projects found by query

Since:

  • 0.1.0-alpha

Version:

  • 1.0


119
120
121
# File 'lib/complish/models/project.rb', line 119

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

.by_pwd(pwd) ⇒ Sequel::SQLite::Dataset

Find projects by pwd

Examples:

Find projects by pwd

Complish::Project.by_pwd('foo/bar')
 #=> <#Sequel::SQLite::Dataset>
Complish::Project.by_pwd('foo/bar').all
 #=> [<#Complish::Project>]

Parameters:

  • pwd (String)

    the directory to query the dataset for

Returns:

  • (Sequel::SQLite::Dataset)

    the dataset of projects found by query

Since:

  • 0.1.0-alpha

Version:

  • 1.0


132
133
134
# File 'lib/complish/models/project.rb', line 132

def self.by_pwd(pwd)
  where(pwd: pwd)
end

.by_user_and_name(user, name) ⇒ Sequel::SQLite::Dataset

Find projects by user and name

Examples:

Find projects by user and name

user = Complish::User.first
 #=> <#Complish::User>
Project.by_user_and_name(user, 'foo')
 #=> <#Sequel::SQLite::Dataset>
Project.by_user_and_name(user, 'foo').all
 #=> [<#Complish::Project>]

Parameters:

  • user (Complish::User)

    the user to query the dataset for

  • name (String)

    the name to query the dataset for

Returns:

  • (Sequel::SQLite::Dataset)

    and dataset of projects by user and name

Since:

  • 0.1.0-alpha

Version:

  • 1.0


148
149
150
# File 'lib/complish/models/project.rb', line 148

def self.by_user_and_name(user, name)
  where(user: user, name: name)
end

.find_or_create_from_env(user = nil) ⇒ Complish::Project

Note:

if no user is provided user will default to Complish::User.find_or_create_from_env

Note:

the project name will default to the last path part of ENV['PWD']

Finds or creates a project from ENV['PWD']

Examples:

Find or create a project usning ENV['PWD']

user = Complish::User.first
 #=> <#Complish::User>
Complish::Project.find_or_create_from_env(user)
 #=> <#Complish::Project>

Parameters:

  • user (Complish::User) (defaults to: nil)

    the user that the project belongs to

Returns:

Since:

  • 0.1.0-alpha

Version:

  • 1.1


163
164
165
166
167
168
# File 'lib/complish/models/project.rb', line 163

def self.find_or_create_from_env(user = nil)
  user ||= Complish::User.find_or_create_from_env
  find_or_create(user: user, pwd: ENV['PWD']) do |p|
    p.name = File.basename(ENV['PWD'])
  end
end

Instance Method Details

#create(opts) ⇒ Complish::Project

Create a new Project and persist it in the database

Examples:

Create a new project

user = Complish::User.new
 #=> <#Complish::User>
Complish::Project.create(user: user, name: 'foo', pwd: 'foo/bar')
 #=> <#Complish::Project>

Parameters:

  • opts (Hash{Symbol=>Hash, String})

    the options to create the Project with

Options Hash (opts):

  • user (Complish::User)

    the user the Project belongs to

  • name (String)

    the name of the project

  • pwd (String)

    the working directory of the project

Returns:

Raises:

  • (Sequel::ValidationFailed)

    if user is not specified

  • (Sequel::ValidationFailed)

    if name is not specified

  • (Sequel::ValidationFailed)

    if pwd is not specified

  • (Sequel::ValidationFailed)

    if name is not unique to user

Version:

  • 1.0


# File 'lib/complish/models/project.rb', line 170

#first_by_name(name) ⇒ Complish::Project?

Find a single project by name

Examples:

Find a single project by name

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

Parameters:

  • name (String)

    the project name to query the dataset for

Returns:

See Also:

Version:

  • 1.0


61
# File 'lib/complish/models/project.rb', line 61

finder :by_name

#first_by_pwd(pwd) ⇒ Complish::Project?

Find a single project by pwd

Examples:

Find a single project by pwd

Complish::Project.first_by_pwd('bar')
 #=> <#Complish::Project>

Parameters:

  • pwd (String)

    the directory to query the dataset for

Returns:

See Also:

Version:

  • 1.0


72
# File 'lib/complish/models/project.rb', line 72

finder :by_pwd

#first_by_user_and_name(user, name) ⇒ Complish::Project?

Find a single project by user and name

Examples:

Find a single project by user and name

Complish::Project.first_by_user_and_name(user, 'foo')
 #=> <#Complish::Project>

Parameters:

  • user (Complish::User)

    the user to query the dataset for

  • name (String)

    the name to query the dataset for

Returns:

See Also:

Version:

  • 1.0


84
# File 'lib/complish/models/project.rb', line 84

finder :by_user_and_name

#new(opts) ⇒ Complish::Project

Create a new instance of Project

Examples:

Build a new project

user = Complish::User.new
 #=> <#Complish::User>
Complish::Project.new(user: user, name: 'foo', pwd: 'foo/bar')
 #=> <#Complish::Project>

Parameters:

  • opts (Hash{Symbol=>Hash, String})

    the options to create the Project with

Options Hash (opts):

  • user (Complish::User)

    the user the Project belongs to

  • name (String)

    the name of the project

  • pwd (String)

    the working directory of the project

Returns:

Raises:

  • (Sequel::ValidationFailed)

    if user is not specified

  • (Sequel::ValidationFailed)

    if name is not specified

  • (Sequel::ValidationFailed)

    if pwd is not specified

  • (Sequel::ValidationFailed)

    if name is not unique to user

Version:

  • 1.0


# File 'lib/complish/models/project.rb', line 170

#saveComplish::Project

Save an instance of Project to the database

Examples:

Build a new project

user = Complish::User.new
 #=> <#Complish::User>
project = Complish::Project.new(user: user, name: 'foo', pwd: 'foo/bar')
 #=> <#Complish::Project>
project.save
 #=> <#Complish::Project>

Returns:

Version:

  • 1.0


# File 'lib/complish/models/project.rb', line 170

#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 project:

  • user must be present.
  • name must be present.
  • pwd must be present.
  • name must be unique scoped to user.

Returns:

  • (nil)

Raises:

  • (Sequel::ValidationFailed)

    if user is not specified

  • (Sequel::ValidationFailed)

    if name is not specified

  • (Sequel::ValidationFailed)

    if pwd is not specified

  • (Sequel::ValidationFailed)

    if name is not unique to user

See Also:

Since:

  • 0.1.0-alpha

Version:

  • 1.1


103
104
105
106
107
# File 'lib/complish/models/project.rb', line 103

def validate
  validates_presence %i(user name pwd)
  validates_unique %i(user name)
  super
end