summaryrefslogtreecommitdiff
path: root/app/services/service_response.rb
blob: 1de30e68d87c9595f0994b1122afc9646aaf523d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

class ServiceResponse
  def self.success(message: nil)
    new(status: :success, message: message)
  end

  def self.error(message:, http_status: nil)
    new(status: :error, message: message, http_status: http_status)
  end

  attr_reader :status, :message, :http_status

  def initialize(status:, message: nil, http_status: nil)
    self.status = status
    self.message = message
    self.http_status = http_status
  end

  def success?
    status == :success
  end

  def error?
    status == :error
  end

  private

  attr_writer :status, :message, :http_status
end