Skip to content

Commit

Permalink
feat(has_j_send_result): expose result?
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Jan 8, 2024
1 parent a9bca88 commit f4d5f7f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/convenient_service/service/plugins/has_j_send_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,42 @@
require_relative "has_j_send_result/commands"
require_relative "has_j_send_result/entities"
require_relative "has_j_send_result/exceptions"

module ConvenientService
module Service
module Plugins
module HasJSendResult
class << self
##
# Checks whether an object is a result instance.
#
# @api public
#
# @param result [Object] Can be any type.
# @return [Boolean]
#
# @example Simple usage.
# class Service
# include ConvenientService::Standard::Config
#
# def result
# success
# end
# end
#
# result = Service.result
#
# ConvenientService::Plugins::Service::HasJSendResult.result?(result)
# # => true
#
# ConvenientService::Plugins::Service::HasJSendResult.result?(42)
# # => false
#
def result?(result)
Commands::IsResult[result: result]
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require "spec_helper"

require "convenient_service"

# rubocop:disable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers
RSpec.describe ConvenientService::Service::Plugins::HasJSendResult do
include ConvenientService::RSpec::Matchers::DelegateTo

example_group "class methods" do
describe ".result?" do
let(:service) do
Class.new do
include ConvenientService::Service::Configs::Minimal
end
end

let(:result) { service.success }

specify do
expect { described_class.result?(result) }
.to delegate_to(ConvenientService::Service::Plugins::HasJSendResult::Commands::IsResult, :call)
.with_arguments(result: result)
.and_return_its_value
end
end
end
end
# rubocop:enable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers

0 comments on commit f4d5f7f

Please sign in to comment.