Skip to content

Commit c15f228

Browse files
committed
add option to disable autoloading of root schedule
1 parent 6d49cc3 commit c15f228

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

lib/schked/config.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
module Schked
66
class Config
7-
attr_writer :logger
7+
attr_writer :logger,
8+
:do_not_load_root_schedule
89

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

22+
def do_not_load_root_schedule?
23+
!!@do_not_load_root_schedule
24+
end
25+
2126
def register_callback(name, &block)
2227
callbacks[name] << block
2328
end

lib/schked/railtie.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ module Schked
66
class Railtie < Rails::Railtie
77
class PathsConfig
88
def self.call(app)
9-
if (root_schedule = app.root.join("config", "schedule.rb")).exist?
9+
return if Schked.config.do_not_load_root_schedule?
10+
11+
root_schedule = app.root.join("config", "schedule.rb")
12+
if root_schedule.exist?
1013
path = root_schedule.to_s
1114
Schked.config.paths << path unless Schked.config.paths.include?(path)
1215
end

spec/rails/railtie_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
describe Schked::Railtie do
66
describe "schked.config" do
7-
subject(:config) { Schked.config }
7+
let(:config) { Schked::Config.new }
8+
9+
before do
10+
allow(Schked).to receive(:config).and_return(config)
11+
end
812

913
context "when by default root schedule doesn't exist" do
1014
it { expect(config.paths).to be_empty }
@@ -36,6 +40,14 @@
3640
expect(config.paths).to match_array([schedule_path])
3741
end
3842
end
43+
44+
context "when passed do_not_load_root_schedule config option" do
45+
before { config.do_not_load_root_schedule = true }
46+
47+
it "doesn't add root schedule to paths" do
48+
expect(config.paths).to be_empty
49+
end
50+
end
3951
end
4052
end
4153
end

0 commit comments

Comments
 (0)