Skip to content

Commit

Permalink
Zeitwerk eager-loading doesn't like gretel
Browse files Browse the repository at this point in the history
Apparently Gretel uses `instance_eval` to load it's breadcrumbs up;
which is why `crumb` is available on `Object`.

This is kinda a hacky-way to deal with that; but it may make sense for
us to exclude the breadcrumb paths from autoloading somehow?
  • Loading branch information
zspencer committed Oct 24, 2022
1 parent 6458df9 commit 3880216
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
29 changes: 18 additions & 11 deletions app/furniture/journal/breadcrumbs.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# frozen_string_literal: true

# @see https://github.com/kzkn/gretel
crumb :journal_entry do |entry|
parent :room, entry.room
link entry.headline, [entry.space, entry.room, entry]
end

crumb :new_journal_entry do |entry|
parent :room, entry.room
link 'Add a Journal Entry', [:new, entry.space, entry.room]
end
begin
crumb :journal_entry do |entry|
parent :room, entry.room
link entry.headline, [entry.space, entry.room, entry]
end

crumb :edit_journal_entry do |entry|
parent :journal_entry, entry
link "Edit", [:edit, entry.space, entry.room, entry]
crumb :new_journal_entry do |entry|
parent :room, entry.room
link 'Add a Journal Entry', [:new, entry.space, entry.room]
end

crumb :edit_journal_entry do |entry|
parent :journal_entry, entry
link 'Edit', [:edit, entry.space, entry.room, entry]
end
rescue NoMethodError => e
throw e unless e.message.start_with?("undefined method `crumb'")
end
module Journal::Breadcrumbs
end
6 changes: 4 additions & 2 deletions config/initializers/gretel.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Gretel.breadcrumb_paths << Rails.root.join('app', 'furniture', '**', 'breadcrumbs.rb')
Gretel.breadcrumb_paths << Rails.root.join('app', 'furniture', '**', 'breadcrumbs', '*.rb')
Rails.application.config.to_prepare do
Gretel.breadcrumb_paths << Rails.root.join('app', 'furniture', '**', 'breadcrumbs.rb')
Gretel.breadcrumb_paths << Rails.root.join('app', 'furniture', '**', 'breadcrumbs', '*.rb')
end

0 comments on commit 3880216

Please sign in to comment.