Skip to content

Commit

Permalink
satisfy rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
markburns committed Mar 8, 2024
1 parent 13ae12c commit dd0c384
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 98 deletions.
2 changes: 0 additions & 2 deletions lib/interactify/dependency_inference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,3 @@ def sidekiq?
rescue LoadError
Interactify.railties_missing!
end


130 changes: 58 additions & 72 deletions spec/fixtures/integration_app/app/interactors/all_the_things.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# when the code is in one place.
#
# Typically this will allow us to move closer towards a one organizer per interaction model.
# E.g. one Rails action == one organizer.
# E.g. one Rails action == one organizer.
# Even the background job firing can be handled by the organizer via YourClass::Async.
#
# An improvement we aim for is automatic diagram generation from the organizers, utilizing
Expand All @@ -32,13 +32,13 @@
# sense. They are evaluated when defining the organizer, leading to the creation of discrete
# classes that handle the respective logic.

require_relative './organizing/organized1'
require_relative './organizing/organized2'
require_relative './if/a'
require_relative './if/b'
require_relative './if/c'
require_relative './if/d'
require_relative './if/organizer'
require_relative "./organizing/organized1"
require_relative "./organizing/organized2"
require_relative "./if/a"
require_relative "./if/b"
require_relative "./if/c"
require_relative "./if/d"
require_relative "./if/organizer"

class AllTheThings
include Interactify
Expand All @@ -49,17 +49,16 @@ class AllTheThings

organize \
self.if(
:things,
then: [If::A, If::B],
:things,
then: [If::A, If::B],
else: [If::C, If::D]
),

# test nested promises
chain(
:nested_promises,
:nested_promises,
Organizing::Organized1.promising(
:organized1_called
),
),
Organizing::Organized2.organizing(
Organizing::DeeplyNestedInteractor,
Organizing::DeeplyNestedPromisingInteractor.promising(
Expand All @@ -68,90 +67,77 @@ class AllTheThings
Organizing::Organized2::Organized2Called
)
),

# test each with lambda
self.if(
-> (c) { c.things },
self.each(
:things,
If::A,
If::B,
-> (c) { c.lambda_set = true }
),
->(c) { c.things },
each(
:things,
If::A,
If::B,
->(c) { c.lambda_set = true }
)
),

# test alternative if syntax
self.if(
-> (c) { c.a && c.b } ,
then: -> (c) { c.both_a_and_b = true },
else: -> (c) { c.both_a_and_b = false}
->(c) { c.a && c.b },
then: ->(c) { c.both_a_and_b = true },
else: ->(c) { c.both_a_and_b = false }
),

# test setting a value to use later in the chain
-> (c) { c.more_things = [1, 2, 3, 4] },

->(c) { c.more_things = [1, 2, 3, 4] },
# test lambdas inside each
self.each(
:more_things,
-> (c) {
if c.more_thing_index.zero?
c.first_more_thing = true
end
each(
:more_things,
lambda { |c|
c.first_more_thing = true if c.more_thing_index.zero?
},
-> (c) {
if c.more_thing_index == 1
c.next_more_thing = true
end
lambda { |c|
c.next_more_thing = true if c.more_thing_index == 1
},
# test nested if inside each
{if: :not_set_thing, then: -> (c) { c.not_set_thing = true } },

{ if: :not_set_thing, then: ->(c) { c.not_set_thing = true } },
# test setting a value after an else
-> (c) { c.more_thing = true }
->(c) { c.more_thing = true }
),

self.if(
:optional_thing,
:optional_thing,
then: [
-> (c) { c.optional_thing_was_set = true },
-> (c) { c.and_then_another_thing = true },
-> (c) { c.and_one_more_thing = true },
->(c) { c.optional_thing_was_set = true },
->(c) { c.and_then_another_thing = true },
->(c) { c.and_one_more_thing = true },
# test nested each inside if
self.each(:more_things,
-> (c) { c.more_things[c.more_thing_index] = c.more_thing + 5 },
-> (c) { c.more_things[c.more_thing_index] = c.more_thing + 5 }
)
each(:more_things,
->(c) { c.more_things[c.more_thing_index] = c.more_thing + 5 },
->(c) { c.more_things[c.more_thing_index] = c.more_thing + 5 })
],
else: -> (c) { c.optional_thing_was_set = false }
else: ->(c) { c.optional_thing_was_set = false }
),

# if -> each -> if -> each
self.if(:condition, then: [-> {}], else: [
self.each(
:things,
self.if(
:thing,
then: self.each(
:more_things,
-> (c) {
c.counter ||= 0
c.counter += 1
}
)
)
)
]),

each(
:things,
self.if(
:thing,
then: each(
:more_things,
lambda { |c|
c.counter ||= 0
c.counter += 1
}
)
)
)
]),
# each -> each -> each
self.each(
each(
:more_things,
self.each(
each(
:more_things,
self.each(
each(
:more_things,
self.each(
each(
:more_things,
-> (c) {
lambda { |c|
c.heavily_nested_counter ||= 0
c.heavily_nested_counter += 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class HashSyntaxOrganizer
expect :blah, filled: false

organize(
{if: :blah, then: [A, B], else: [C, D]},
{ if: :blah, then: [A, B], else: [C, D] },
Anyways
)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative 'deeply_nested_interactor'
require_relative 'deeply_nested_promising_interactor'
require_relative "deeply_nested_interactor"
require_relative "deeply_nested_promising_interactor"

module Organizing
class Organized2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative './organizing/organized1'
require_relative './organizing/organized2'
require_relative "./organizing/organized1"
require_relative "./organizing/organized2"

class UnfulfilledPromises
include Interactify
Expand All @@ -10,18 +10,17 @@ class UnfulfilledPromises
promise :another_thing

organize each(
:things,
:things,
{
if: :dont_fulfill,
if: :dont_fulfill,
then: chain(
:nested_promises,
:nested_promises,
each(
:things,
:things,
Organizing::Organized1.promising(
:organized1_called
),
),
SetAnothingThing = Interactify { _1.another_thing = true },

Organizing::Organized2.organizing(
Organizing::DeeplyNestedInteractor,
Organizing::DeeplyNestedPromisingInteractor.promising(
Expand Down
14 changes: 7 additions & 7 deletions spec/lib/interactify/wiring_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,24 @@ def f(path)
]
end

describe '#validate_app' do
context 'with a valid app' do
describe "#validate_app" do
context "with a valid app" do
let(:root) do
Pathname.new("./spec/fixtures/dummy_app/app/")
end

it 'validates the app' do
expect(subject.validate_app).to eq ''
it "validates the app" do
expect(subject.validate_app).to eq ""
end
end

context 'with an invalid app' do
context "with an invalid app" do
let(:root) do
Pathname.new("./spec/fixtures/integration_app/app/")
end

it 'returns the errors' do
expect(subject.validate_app).to eq ''
it "returns the errors" do
expect(subject.validate_app).to eq ""
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/support/coverage.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# frozen_string_literal: true

require 'simplecov'
require 'simplecov-json'
require "simplecov"
require "simplecov-json"

SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::JSONFormatter
])
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::JSONFormatter
])

SimpleCov.start do
add_filter "/spec/"
add_filter %r{_spec\.rb$} # This line excludes all files ending with _spec.rb
add_filter(/_spec\.rb$/) # This line excludes all files ending with _spec.rb

add_group "Sidekiq jobs" do |src_file|
src_file.project_filename =~ %r{lib/interactify/async} && src_file.filename !~ /_spec\.rb/
Expand Down

0 comments on commit dd0c384

Please sign in to comment.