Class: CommandProposal::Iteration

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Service::ExternalBelong
Defined in:
app/models/command_proposal/iteration.rb

Constant Summary collapse

TRUNCATE_COUNT =
2000

Instance Method Summary collapse

Instance Method Details

#approved?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'app/models/command_proposal/iteration.rb', line 68

def approved?
  super || (session_type == "function" && approved_at?)
end

#bringsObject



57
58
59
60
61
62
# File 'app/models/command_proposal/iteration.rb', line 57

def brings
  bring_str = code.scan(/bring.*?\n/).flatten.first
  return [] unless bring_str.present?

  ::CommandProposal::Task.module.where(friendly_id: bring_str.scan(/\s+\:(\w+),?/).flatten)
end

#complete?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/models/command_proposal/iteration.rb', line 72

def complete?
  success? || failed? || cancelled? || terminated?
end

#durationObject



84
85
86
87
88
# File 'app/models/command_proposal/iteration.rb', line 84

def duration
  return unless started_at?

  (completed_at || stopped_at || Time.current) - started_at
end

#end_timeObject



90
91
92
# File 'app/models/command_proposal/iteration.rb', line 90

def end_time
  completed_at || stopped_at || Time.current
end

#force_resetObject



94
95
96
97
# File 'app/models/command_proposal/iteration.rb', line 94

def force_reset
  # Debugging method. Should never actually be called.
  update(status: :approved, result: nil, completed_at: nil, stopped_at: nil, started_at: nil)
end

#line_countObject



99
100
101
102
103
# File 'app/models/command_proposal/iteration.rb', line 99

def line_count
  return 0 if code.blank?

  code.count("\n")
end

#paramsObject



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

def params
  code.scan(/params\[[:\"\'](.*?)[\'\"]?\]/).flatten.uniq
end

#pending?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'app/models/command_proposal/iteration.rb', line 76

def pending?
  created?
end

#primary_iteration?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'app/models/command_proposal/iteration.rb', line 64

def primary_iteration?
  task.primary_iteration == self
end

#running?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'app/models/command_proposal/iteration.rb', line 80

def running?
  started? || cancelling?
end