Class: Trackington::Project
- Inherits:
-
Object
- Object
- Trackington::Project
- Defined in:
- lib/trackington/app/projects.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#public ⇒ Object
readonly
Returns the value of attribute public.
-
#sprints ⇒ Object
readonly
Returns the value of attribute sprints.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #add_user(project_user, user_to_add, type = nil) ⇒ Object
- #backlog(project_user) ⇒ Object
- #complete_sprint(project_user) ⇒ Object
- #create_sprint(project_user, data) ⇒ Object
- #current_sprint(project_user) ⇒ Object
-
#initialize(id, title, description, public) ⇒ Project
constructor
A new instance of Project.
- #remove_user(project_user, user_to_remove) ⇒ Object
- #start_sprint(project_user) ⇒ Object
- #update(project_user, data) ⇒ Object
- #update_user(project_user, user, new_type) ⇒ Object
- #user_is?(user_id, type) ⇒ Boolean
- #users ⇒ Object
Constructor Details
#initialize(id, title, description, public) ⇒ Project
Returns a new instance of Project.
55 56 57 58 59 60 61 |
# File 'lib/trackington/app/projects.rb', line 55 def initialize(id, title, description, public) @id = id @title = title @description = description @public = public @sprints = SprintRepository.new(@id) end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
53 54 55 |
# File 'lib/trackington/app/projects.rb', line 53 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
53 54 55 |
# File 'lib/trackington/app/projects.rb', line 53 def id @id end |
#public ⇒ Object (readonly)
Returns the value of attribute public.
53 54 55 |
# File 'lib/trackington/app/projects.rb', line 53 def public @public end |
#sprints ⇒ Object (readonly)
Returns the value of attribute sprints.
53 54 55 |
# File 'lib/trackington/app/projects.rb', line 53 def sprints @sprints end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
53 54 55 |
# File 'lib/trackington/app/projects.rb', line 53 def title @title end |
Instance Method Details
#add_user(project_user, user_to_add, type = nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/trackington/app/projects.rb', line 63 def add_user(project_user, user_to_add, type = nil) check_user_role(project_user, 'owner') type ||= 'contributor' existing = Models::ProjectRole.where(user_id: user_to_add, project_id: @id).first return unless existing.nil? new_role = Models::ProjectRole.new(user_id: user_to_add, project_id: @id, role_type: type) new_role.save end |
#backlog(project_user) ⇒ Object
137 138 139 140 141 |
# File 'lib/trackington/app/projects.rb', line 137 def backlog(project_user) check_user_role project_user @sprints.backlog end |
#complete_sprint(project_user) ⇒ Object
131 132 133 134 135 |
# File 'lib/trackington/app/projects.rb', line 131 def complete_sprint(project_user) check_user_role(project_user, 'owner') @sprints.complete_sprint end |
#create_sprint(project_user, data) ⇒ Object
119 120 121 122 123 |
# File 'lib/trackington/app/projects.rb', line 119 def create_sprint(project_user, data) check_user_role(project_user, 'owner') @sprints.create(data) end |
#current_sprint(project_user) ⇒ Object
113 114 115 116 117 |
# File 'lib/trackington/app/projects.rb', line 113 def current_sprint(project_user) check_user_role project_user @sprints.current end |
#remove_user(project_user, user_to_remove) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/trackington/app/projects.rb', line 80 def remove_user(project_user, user_to_remove) check_user_role(project_user, 'owner') Models::ProjectRole.destroy_all(project_id: @id, user_id: user_to_remove) nil end |
#start_sprint(project_user) ⇒ Object
125 126 127 128 129 |
# File 'lib/trackington/app/projects.rb', line 125 def start_sprint(project_user) check_user_role(project_user, 'owner') @sprints.start_sprint end |
#update(project_user, data) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/trackington/app/projects.rb', line 99 def update(project_user, data) check_user_role(project_user, 'owner') @title = data[:title] @description = data[:description] @public = data[:public] db_project = Models::Project.find(@id) db_project.title = @title db_project.description = @description db_project.public = @public db_project.save end |
#update_user(project_user, user, new_type) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/trackington/app/projects.rb', line 89 def update_user(project_user, user, new_type) check_user_role(project_user, 'owner') role = Models::ProjectRole.where(project_id: @id, user_id: user).first role.role_type = new_type role.save end |
#user_is?(user_id, type) ⇒ Boolean
143 144 145 146 147 148 149 150 151 |
# File 'lib/trackington/app/projects.rb', line 143 def user_is?(user_id, type) role = Models::ProjectRole.where(project_id: @id, user_id: user_id).first return false if role.nil? return true if role.role_type == 'owner' role.role_type == type end |
#users ⇒ Object
153 154 155 156 157 |
# File 'lib/trackington/app/projects.rb', line 153 def users Models::Project.find(@id).project_roles.map do |role| ProjectRole.new(role) end end |