Class: Twenty::Project

Inherits:
Sequel::Model
  • Object
show all
Includes:
Mixin::Colorable, Model
Defined in:
lib/twenty/server/model/project.rb

Constant Summary

Constants included from Mixin::Colorable

Mixin::Colorable::COLORS

Instance Method Summary collapse

Methods included from Mixin::Colorable

#before_validation, #random_color

Methods included from Model

included

Instance Method Details

#open_task_countInteger

Returns the number of open tasks a project has

Returns:

  • (Integer)

    Returns the number of open tasks a project has



37
38
39
40
41
42
# File 'lib/twenty/server/model/project.rb', line 37

def open_task_count
  @open_task_count ||= Twenty::Task
                         .where(project_id: id)
                         .where(Sequel.lit("status IN (0,1,2)"))
                         .count
end

#pathString

Returns The path to a project.

Returns:

  • (String)

    The path to a project



23
24
25
# File 'lib/twenty/server/model/project.rb', line 23

def path
  super&.sub(Dir.home, "~")
end

#path_exist?Boolean

Returns true when #path exists on disk

Returns:

  • (Boolean)

    Returns true when #path exists on disk



30
31
32
# File 'lib/twenty/server/model/project.rb', line 30

def path_exist?
  File.exist? File.expand_path(path)
end

#validateObject

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.



14
15
16
17
18
# File 'lib/twenty/server/model/project.rb', line 14

def validate
  super
  errors.add(:path, "does not exist on disk") if !path_exist?
  errors.add(:path, "is not absolute") if !File.absolute_path?(self[:path])
end