Sha256: 291d056daebec36494e5030269ab908786e8374aa6f037f1d93708c99553a3f8
Contents?: true
Size: 1015 Bytes
Versions: 1
Compression:
Stored size: 1015 Bytes
Contents
# frozen_string_literal: true require 'forwardable' module DSN # The full status code class StatusCode extend Forwardable def self.from_string(code) new(Parser::String.new(code)) end def_delegators :class_subcode, :success?, :transient_failure?, :failed? def initialize(code) @code = code @class_subcode = Subcode::ClassSubcode.new(code) @subject_subcode = Subcode::SubjectSubcode.new(code) @detail_subcode = Subcode::DetailSubcode.new(code) end def valid? subcodes.all?(&:valid?) end # Returns the most detailed subcode that is valid def subcode raise InvalidStatusCode unless class_subcode.valid? subcodes.select(&:valid?).last end def to_s code.to_s end attr_reader :class_subcode attr_reader :subject_subcode attr_reader :detail_subcode protected attr_reader :code private def subcodes [class_subcode, subject_subcode, detail_subcode] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dsn-0.1.0 | lib/dsn/status_code.rb |