Skip to content

Commit

Permalink
Merge pull request #42 from thoughtbot/mr/introduce-distributors
Browse files Browse the repository at this point in the history
Introduce Gold Miner distributors
  • Loading branch information
MatheusRich authored Oct 20, 2023
2 parents 784be5b + b76f0cc commit fd30c36
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion exe/gold_miner
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ GoldMiner
.fmap { |gold_container|
debug "Found #{gold_container.gold_nuggets.size} messages in #{Time.now - t0} seconds."

puts GoldMiner.smith_blog_post(gold_container)
blog_post = GoldMiner.smith_blog_post(gold_container)
GoldMiner.distribute(blog_post)
}
.or { |error| abort "[ERROR] #{error}" }

Expand Down
4 changes: 4 additions & 0 deletions lib/gold_miner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def smith_blog_post(gold_container, ...)
BlogPostSmith.new(...).smith(gold_container)
end

def distribute(blog_post)
TerminalDistributor.new.distribute(blog_post)
end

private

def prepare(slack_client)
Expand Down
7 changes: 7 additions & 0 deletions lib/gold_miner/terminal_distributor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module GoldMiner
class TerminalDistributor
def distribute(blog_post)
puts blog_post
end
end
end
15 changes: 15 additions & 0 deletions spec/gold_miner/terminal_distributor_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "spec_helper"

RSpec.describe GoldMiner::TerminalDistributor do
it_behaves_like "distributor"

describe "#distribute" do
it "prints the blog post to STDOUT" do
blog_post = double("blog_post", to_s: "A blog post")

expect { subject.distribute(blog_post) }.to output("A blog post\n").to_stdout
end
end
end
3 changes: 3 additions & 0 deletions spec/support/behaves_like_distributor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RSpec.shared_examples "distributor" do
it { is_expected.to respond_to(:distribute) }
end

0 comments on commit fd30c36

Please sign in to comment.