Skip to content

Commit

Permalink
Make GoldMiner a class
Browse files Browse the repository at this point in the history
This will help on a future refactor/reorganization
  • Loading branch information
MatheusRich committed Oct 21, 2023
1 parent fd30c36 commit d9cf295
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 46 deletions.
56 changes: 28 additions & 28 deletions lib/gold_miner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@

Zeitwerk::Loader.for_gem.setup

module GoldMiner
extend self

def mine_in(slack_channel, slack_client: GoldMiner::Slack::Client, env_file: ".env")
Dotenv.load!(env_file)

prepare(slack_client)
.fmap { |client| explore(slack_channel, client) }
end

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)
slack_client.build(api_token: ENV["SLACK_API_TOKEN"])
end

def explore(slack_channel, slack_client)
SlackExplorer
.new(slack_client, AuthorConfig.default)
.explore(slack_channel, start_on: Helpers::Time.last_friday)
class GoldMiner
class << self
def mine_in(slack_channel, slack_client: GoldMiner::Slack::Client, env_file: ".env")
Dotenv.load!(env_file)

prepare(slack_client)
.fmap { |client| explore(slack_channel, client) }
end

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)
slack_client.build(api_token: ENV["SLACK_API_TOKEN"])
end

def explore(slack_channel, slack_client)
SlackExplorer
.new(slack_client, AuthorConfig.default)
.explore(slack_channel, start_on: Helpers::Time.last_friday)
end
end
end
2 changes: 1 addition & 1 deletion lib/gold_miner/author.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module GoldMiner
class GoldMiner
Author = Data.define(:id, :name, :link) do
alias_method :to_s, :name

Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/author_config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module GoldMiner
class GoldMiner
class AuthorConfig
DEFAULT_AUTHOR_LINK = "#to-do"
DEFAULT_CONFIG_PATH = "lib/config/author_config.yml"
Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/blog_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "async"

module GoldMiner
class GoldMiner
class BlogPost
def initialize(slack_channel:, gold_nuggets:, since:, writer: SimpleWriter.new)
@slack_channel = slack_channel
Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/blog_post/open_ai_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "json"

module GoldMiner
class GoldMiner
class BlogPost
class OpenAiWriter
def initialize(open_ai_api_token:, fallback_writer:, open_ai_client: OpenAI::Client)
Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/blog_post/simple_writer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module GoldMiner
class GoldMiner
class BlogPost
class SimpleWriter
def initialize(topic_extractor: TopicExtractor)
Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/blog_post/simple_writer/topic_extractor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module GoldMiner
class GoldMiner
class BlogPost
class SimpleWriter
module TopicExtractor
Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/blog_post/writer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module GoldMiner
class GoldMiner
class BlogPost
module Writer
def self.from_env
Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/blog_post_smith.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module GoldMiner
class GoldMiner
class BlogPostSmith
def initialize(blog_post_class: BlogPost, blog_post_writer: BlogPost::Writer.from_env)
@blog_post_class = blog_post_class
Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/gold_container.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module GoldMiner
class GoldMiner
GoldContainer = Data.define(:gold_nuggets, :origin, :packing_date)
end
2 changes: 1 addition & 1 deletion lib/gold_miner/gold_nugget.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module GoldMiner
class GoldMiner
GoldNugget = Data.define(:content, :author, :source) do
def as_conversation
<<~MARKDOWN
Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module GoldMiner
class GoldMiner
module Helpers
module Time
def self.pretty_date(date)
Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/slack/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "dry/monads"
require "slack-ruby-client"

module GoldMiner
class GoldMiner
class Slack::Client
extend Dry::Monads[:result]

Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/slack/message.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module GoldMiner
class GoldMiner
module Slack
Message = Data.define(:id, :text, :user, :permalink) do
alias_method :[], :public_send
Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/slack/messages_query.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module GoldMiner
class GoldMiner
module Slack
class MessagesQuery
attr_reader :channel, :start_date, :topic, :reaction
Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/slack/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module GoldMiner
class GoldMiner
module Slack
User = Data.define(:id, :name, :username)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/slack_explorer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "async"

module GoldMiner
class GoldMiner
class SlackExplorer
def initialize(slack_client, author_config)
@slack = slack_client
Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/terminal_distributor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module GoldMiner
class GoldMiner
class TerminalDistributor
def distribute(blog_post)
puts blog_post
Expand Down
2 changes: 1 addition & 1 deletion lib/gold_miner/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module GoldMiner
class GoldMiner
VERSION = "0.1.0"
end

0 comments on commit d9cf295

Please sign in to comment.