Skip to content

Commit

Permalink
Merge pull request #30 from bibendi/root_schedule_loading
Browse files Browse the repository at this point in the history
Add option to disable autoloading of root schedule
  • Loading branch information
bibendi authored Aug 12, 2022
2 parents 2de31c7 + c15f228 commit 8ace840
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/schked/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

module Schked
class Config
attr_writer :logger
attr_writer :logger,
:do_not_load_root_schedule

def paths
@paths ||= []
Expand All @@ -18,6 +19,10 @@ def logger
@logger ||= Logger.new($stdout).tap { |l| l.level = Logger::INFO }
end

def do_not_load_root_schedule?
!!@do_not_load_root_schedule
end

def register_callback(name, &block)
callbacks[name] << block
end
Expand Down
5 changes: 4 additions & 1 deletion lib/schked/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ module Schked
class Railtie < Rails::Railtie
class PathsConfig
def self.call(app)
if (root_schedule = app.root.join("config", "schedule.rb")).exist?
return if Schked.config.do_not_load_root_schedule?

root_schedule = app.root.join("config", "schedule.rb")
if root_schedule.exist?
path = root_schedule.to_s
Schked.config.paths << path unless Schked.config.paths.include?(path)
end
Expand Down
14 changes: 13 additions & 1 deletion spec/rails/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

describe Schked::Railtie do
describe "schked.config" do
subject(:config) { Schked.config }
let(:config) { Schked::Config.new }

before do
allow(Schked).to receive(:config).and_return(config)
end

context "when by default root schedule doesn't exist" do
it { expect(config.paths).to be_empty }
Expand Down Expand Up @@ -36,6 +40,14 @@
expect(config.paths).to match_array([schedule_path])
end
end

context "when passed do_not_load_root_schedule config option" do
before { config.do_not_load_root_schedule = true }

it "doesn't add root schedule to paths" do
expect(config.paths).to be_empty
end
end
end
end
end

0 comments on commit 8ace840

Please sign in to comment.