Skip to content

Commit

Permalink
refactor(inspect): add has_inspect placeholder for code
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed May 2, 2023
1 parent 61dbcc7 commit 027af71
Show file tree
Hide file tree
Showing 18 changed files with 280 additions and 24 deletions.
15 changes: 6 additions & 9 deletions lib/convenient_service/configs/awesome_print_inspect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

module ConvenientService
module Configs
##
# TODO: Complete.
#
module AwesomePrintInspect
include Support::Concern

Expand Down Expand Up @@ -36,12 +33,12 @@ class self::Message
end
end

# class self::Code
# concerns do
# replace HasInspect::Concern, HasAwesomePrintInspect::Concern
# end
# end
#
class self::Code
concerns do
replace Plugins::Code::HasInspect::Concern, Plugins::Code::HasAwesomePrintInspect::Concern
end
end

class self::Status
concerns do
replace Plugins::Status::HasInspect::Concern, Plugins::Status::HasAwesomePrintInspect::Concern
Expand Down
4 changes: 4 additions & 0 deletions lib/convenient_service/configs/minimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ class self::Message

class self::Code
include Core

concerns do
use Plugins::Code::HasInspect::Concern
end
end

class self::Status
Expand Down
1 change: 1 addition & 0 deletions lib/convenient_service/dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def require_awesome_print_inspect
require_relative "service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/data/plugins/has_awesome_print_inspect"
require_relative "service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/message/plugins/has_awesome_print_inspect"
require_relative "service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/status/plugins/has_awesome_print_inspect"
require_relative "service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/plugins/has_awesome_print_inspect"
require_relative "service/plugins/can_have_steps/entities/step/plugins/has_awesome_print_inspect"
require_relative "configs/awesome_print_inspect"
require_relative "configs/awesome_print_inspect/aliases"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative "code/commands"
require_relative "code/concern"
require_relative "code/plugins"

module ConvenientService
module Service
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

require_relative "plugins/has_inspect"

require_relative "plugins/aliases"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module ConvenientService
module Plugins
Code = ::ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code::Plugins
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require_relative "has_awesome_print_inspect/concern"
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

module ConvenientService
module Service
module Plugins
module HasResult
module Entities
class Result
module Plugins
module HasJSendStatusAndAttributes
module Entities
class Code
module Plugins
module HasAwesomePrintInspect
module Concern
include Support::Concern

instance_methods do
##
# @return [String]
#
def inspect
metadata = {
ConvenientService: {
entity: "Code",
result: result.class.name,
value: to_sym
}
}

metadata.ai
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require_relative "has_inspect/concern"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

module ConvenientService
module Service
module Plugins
module HasResult
module Entities
class Result
module Plugins
module HasJSendStatusAndAttributes
module Entities
class Code
module Plugins
module HasInspect
module Concern
include Support::Concern

instance_methods do
##
# @return [String]
#
def inspect
"<#{self.class} value: :#{value}>"
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
22 changes: 11 additions & 11 deletions spec/lib/convenient_service/configs/awesome_print_inspect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@
end
end

# example_group "service result code" do
# example_group "concerns" do
# it "removes `HasInspect::Concern` from service concerns" do
# expect(service_class.::Result::Code.concerns.to_a).not_to include(HasInspect::Concern)
# end
#
# it "adds `HasAwesomeInspect::Concern` from service concerns" do
# expect(service_class.::Result::Code.concerns.to_a).to include(HasAwesomeInspect::Concern)
# end
# end
# end
example_group "service result code" do
example_group "concerns" do
it "removes `ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code::Plugins::HasInspect::Concern` from service concerns" do
expect(service_class::Result::Code.concerns.to_a).not_to include(ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code::Plugins::HasInspect::Concern)
end

it "adds `ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code::Plugins::HasAwesomePrintInspect::Concern` from service concerns" do
expect(service_class::Result::Code.concerns.to_a).to include(ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code::Plugins::HasAwesomePrintInspect::Concern)
end
end
end

example_group "service result status" do
example_group "concerns" do
Expand Down
6 changes: 5 additions & 1 deletion spec/lib/convenient_service/configs/minimal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@

example_group "service result code" do
example_group "concerns" do
let(:concerns) { [] }
let(:concerns) do
[
ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code::Plugins::HasInspect::Concern
]
end

it "sets service result code concerns" do
expect(service_class::Result::Code.concerns.to_a).to eq(concerns)
Expand Down
6 changes: 5 additions & 1 deletion spec/lib/convenient_service/configs/standard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,11 @@

example_group "service result code" do
example_group "concerns" do
let(:concerns) { [] }
let(:concerns) do
[
ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code::Plugins::HasInspect::Concern
]
end

it "sets service result code concerns" do
expect(service_class::Result::Code.concerns.to_a).to eq(concerns)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,11 @@

example_group "service result code" do
example_group "concerns" do
let(:concerns) { [] }
let(:concerns) do
[
ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code::Plugins::HasInspect::Concern
]
end

it "sets service result code concerns" do
expect(service_class::Result::Code.concerns.to_a).to eq(concerns)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,11 @@

example_group "service result code" do
example_group "concerns" do
let(:concerns) { [] }
let(:concerns) do
[
ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code::Plugins::HasInspect::Concern
]
end

it "sets service result code concerns" do
expect(service_class::Result::Code.concerns.to_a).to eq(concerns)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "spec_helper"

require "convenient_service"

# rubocop:disable RSpec/DescribeClass
RSpec.describe "convenient_service/service/plugins/has_result/entities/result/plugins/has_j_send_status_and_attributes/entities/code/plugins/aliases" do
specify { expect(ConvenientService::Plugins::Code).to eq(ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code::Plugins) }
end
# rubocop:enable RSpec/DescribeClass
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# frozen_string_literal: true

require "spec_helper"

require "convenient_service"

# rubocop:disable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers
RSpec.describe ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code::Plugins::HasAwesomePrintInspect::Concern do
include ConvenientService::RSpec::Matchers::DelegateTo

example_group "modules" do
include ConvenientService::RSpec::Matchers::IncludeModule

subject { described_class }

it { is_expected.to include_module(ConvenientService::Support::Concern) }

context "when included" do
subject { code_class }

let(:code_class) do
Class.new.tap do |klass|
klass.class_exec(described_class) do |mod|
include mod
end
end
end

it { is_expected.to include_module(described_class::InstanceMethods) }
end
end

example_group "instance methods" do
describe "#inspect" do
let(:service) do
Class.new do
include ConvenientService::Configs::Minimal

include ConvenientService::Configs::AwesomePrintInspect

def result
error(code: :foo)
end
end
end

let(:code) { service.result.code }

let(:keywords) { ["ConvenientService", "entity", "Code", "result", code.result.class.name, "value", ":foo"] }

before do
##
# TODO: Remove when Core implements auto committing from `inspect`.
#
code.class.commit_config!
end

it "returns `inspect` representation of code" do
expect(code.inspect).to include(*keywords)
end
end
end
end
# rubocop:enable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true

require "spec_helper"

require "convenient_service"

# rubocop:disable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers
RSpec.describe ConvenientService::Service::Plugins::HasResult::Entities::Result::Plugins::HasJSendStatusAndAttributes::Entities::Code::Plugins::HasInspect::Concern do
include ConvenientService::RSpec::Matchers::DelegateTo

example_group "modules" do
include ConvenientService::RSpec::Matchers::IncludeModule

subject { described_class }

it { is_expected.to include_module(ConvenientService::Support::Concern) }

context "when included" do
subject { code_class }

let(:code_class) do
Class.new.tap do |klass|
klass.class_exec(described_class) do |mod|
include mod
end
end
end

it { is_expected.to include_module(described_class::InstanceMethods) }
end
end

example_group "instance methods" do
describe "#inspect" do
let(:service) do
Class.new do
include ConvenientService::Configs::Minimal

def result
success
end
end
end

let(:code) { service.result.code }

before do
##
# TODO: Remove when Core implements auto committing from `inspect`.
#
code.class.commit_config!
end

it "returns `inspect` representation of code" do
expect(code.inspect).to eq("<#{code.class} value: :#{code}>")
end
end
end
end
# rubocop:enable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers

0 comments on commit 027af71

Please sign in to comment.