Class: CommandProposal::Task

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/command_proposal/task.rb

Overview

has_many :iterations text :name text :friendly_id text :description integer :session_type datetime :last_executed_at

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#skip_approvalObject

Returns the value of attribute skip_approval.



10
11
12
# File 'app/models/command_proposal/task.rb', line 10

def skip_approval
  @skip_approval
end

#userObject

Returns the value of attribute user.



10
11
12
# File 'app/models/command_proposal/task.rb', line 10

def user
  @user
end

Instance Method Details

#approved?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/models/command_proposal/task.rb', line 61

def approved?
  primary_iteration&.approved_at?
end

#code=(new_code) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/command_proposal/task.rb', line 93

def code=(new_code)
  if skip_approval
    iterations.create(
      code: new_code,
      requester: user,
      status: :approved,
      approver: user,
      approved_at: Time.current
    )
  else
    iterations.create(code: new_code, requester: user)
  end
end

#completed_atObject



89
90
91
# File 'app/models/command_proposal/task.rb', line 89

def completed_at
  iterations.maximum(:completed_at)
end

#current_iterationObject



69
70
71
# File 'app/models/command_proposal/task.rb', line 69

def current_iteration
  ordered_iterations.first
end

#current_iteration_atObject



77
78
79
# File 'app/models/command_proposal/task.rb', line 77

def current_iteration_at
  current_iteration&.completed_at
end

#current_iteration_byObject



81
82
83
# File 'app/models/command_proposal/task.rb', line 81

def current_iteration_by
  current_iteration&.requester_name
end

#first_iterationObject



65
66
67
# File 'app/models/command_proposal/task.rb', line 65

def first_iteration
  ordered_iterations.last
end

#linesObject



53
54
55
# File 'app/models/command_proposal/task.rb', line 53

def lines
  iterations.order(created_at: :asc).where.not(id: first_iteration.id)
end

#primary_iterationObject



73
74
75
# File 'app/models/command_proposal/task.rb', line 73

def primary_iteration
  console? ? first_iteration : current_iteration
end

#started_atObject



85
86
87
# File 'app/models/command_proposal/task.rb', line 85

def started_at
  iterations.minimum(:started_at)
end

#to_paramObject



57
58
59
# File 'app/models/command_proposal/task.rb', line 57

def to_param
  friendly_id || generate_friendly_id
end