Skip to content

Commit

Permalink
refactor: Introduce Configuration and Session abstractions
Browse files Browse the repository at this point in the history
This commit introduces two key abstractions to improve code organization:

* Add PodcastBuddy::Configuration for global settings
* Add PodcastBuddy::Session to encapsulate recording sessions
* Rename show_notes_log to show_notes_path for clarity
* Update README with configuration examples
* Fix test directory structure and stability

The changes maintain backward compatibility while providing a cleaner API
for configuration and session management.
  • Loading branch information
codenamev committed Dec 6, 2024
1 parent b8c6b28 commit e82648c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## [Unreleased]

* Renamed `show_notes_log` to `show_notes_path` for clarity and consistency
* Introduced `PodcastBuddy::Session` abstraction
* Added `PodcastBuddy::Configuration` for global settings
* Fixed test directory structure and improved test stability

## [0.2.1] - 2024-08-13

* Fixes typo in command-line help banner to reference proper podcast_buddy command
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ Once you're done, simply `ctrl-c` to wrap things up.
**custom whisper model**: `podcast_buddy --whisper base.en` – use any of [these available models](https://github.com/ggerganov/whisper.cpp/blob/master/models/download-ggml-model.sh#L28-L49).
**custom session**: `podcast_buddy --name "Ruby Rogues 08-15-2024"` – saves files to a new `tmp/Ruby Rogues 08-15-2024/` directory.

### Configuration

Configure PodcastBuddy globally:

```ruby
PodcastBuddy.configure do |config|
config.whisper_model = "base.en" # Choose whisper model
config.root = "path/to/files" # Set root directory for files
config.logger = Logger.new($stdout, level: Logger::DEBUG)
end
```

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/tmp/session/transcript.log
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Existing transcript
Existing transcripttest transcription
10 changes: 7 additions & 3 deletions spec/podcast_buddy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
require "podcast_buddy"

def reset_session!
File.write(File.join("spec", "fixtures", "session", "summary.log"), "Existing summary")
File.write(File.join("spec", "fixtures", "session", "transcript.log"), "Existing transcript")
File.write(File.join("spec", "fixtures", "session", "topics.log"), "Existing topics")
session_path = File.join("spec", "fixtures", "tmp", "session")
FileUtils.mkdir_p(session_path)
File.write(File.join(session_path, "summary.log"), "Existing summary")
File.write(File.join(session_path, "transcript.log"), "Existing transcript")
File.write(File.join(session_path, "topics.log"), "Existing topics")
PodcastBuddy.logger = nil
PodcastBuddy.configure do |config|
config.root = File.join("spec", "fixtures")
Expand Down Expand Up @@ -122,13 +124,15 @@ def reset_session!

describe ".whisper_logger=" do
it "creates a new logger with the given file path" do
PodcastBuddy.instance_variable_set(:@whisper_logger, nil)
expect(Logger).to receive(:new).with("whisper.log", "daily", level: Logger::DEBUG)
PodcastBuddy.whisper_logger = "whisper.log"
end
end

describe ".whisper_logger" do
it "creates a new logger with the session whisper log" do
PodcastBuddy.instance_variable_set(:@whisper_logger, nil)
expect(Logger).to receive(:new).with(session.whisper_log, "daily", level: Logger::DEBUG)
PodcastBuddy.whisper_logger
end
Expand Down
4 changes: 2 additions & 2 deletions spec/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
end
end

describe "#show_notes_log" do
describe "#show_notes_path" do
it "returns the correct file path" do
expected_path = File.join(session.base_path, "show-notes.md")
expect(session.show_notes_log).to eq(expected_path)
expect(session.show_notes_path).to eq(expected_path)
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# frozen_string_literal: true

require "podcast_buddy"
require "fileutils"

RSpec.configure do |config|
config.before(:each) do
# Ensure test directories exist
FileUtils.mkdir_p(File.join("spec", "fixtures", "tmp", "session"))
end
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"

Expand Down

0 comments on commit e82648c

Please sign in to comment.