Class: Rails::Approvals::Request

Inherits:
ApplicationRecord show all
Defined in:
app/models/rails/approvals/request.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.request!Object



19
20
21
22
23
24
# File 'app/models/rails/approvals/request.rb', line 19

def self.request!
  create!(
    requester: ENV['USER'],
    command: [$PROGRAM_NAME, *ARGV].join(' '),
  )
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/rails/approvals/request.rb', line 26

def expired?
  return false unless requested?

  timeout_duration = Rails.application.config.rails.approvals.timeout_duration
  return false if !timeout_duration

  unless timeout_duration.is_a?(Numeric) || timeout_duration.is_a?(ActiveSupport::Duration)
    raise ArgumentError, "expected ActiveSupport::Duration or Numeric value"
  end

  expires_at = created_at + Rails.application.config.rails.approvals.timeout_duration
  expires_at <= Time.zone.now
end