Sha256: 0a370538d1bcd1d7fbbf1fc7aee80b77dc636512d80678844dde0c6efdb3da8d

Contents?: true

Size: 1.75 KB

Versions: 9

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

require_relative "status/class_methods"

module ConvenientService
  module Service
    module Plugins
      module HasResult
        module Entities
          class Result
            module Plugins
              module HasJsendStatusAndAttributes
                module Entities
                  class Status
                    include Support::Castable

                    extend ClassMethods

                    attr_reader :value

                    def initialize(value:)
                      @value = value
                    end

                    def ==(other)
                      casted = cast(other)

                      return unless casted

                      value == casted.value
                    end

                    def success?
                      value == :success
                    end

                    def failure?
                      value == :failure
                    end

                    def error?
                      value == :error
                    end

                    def not_success?
                      !success?
                    end

                    def not_failure?
                      !failure?
                    end

                    def not_error?
                      !error?
                    end

                    def in?(statuses)
                      statuses.any? { |status| self == status }
                    end

                    def to_s
                      @to_s ||= value.to_s
                    end

                    def to_sym
                      @to_sym ||= value.to_sym
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
convenient_service-0.11.0 lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb
convenient_service-0.10.1 lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb
convenient_service-0.10.0 lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb
convenient_service-0.9.0 lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb
convenient_service-0.8.0 lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb
convenient_service-0.7.0 lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb
convenient_service-0.6.0 lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb
convenient_service-0.5.0 lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb
convenient_service-0.4.0 lib/convenient_service/service/plugins/has_result/entities/result/plugins/has_jsend_status_and_attributes/entities/status.rb