Skip to content

Commit

Permalink
FIX: Revert Demon::DemonBase back to Demon::Base (discourse#8132)
Browse files Browse the repository at this point in the history
I introduced DemonBase because I had got some conflict between `demon/base.rb` and `jobs/base.rb`, however, to not rename base class, it is possible to use regex on absolute path in Zeitwerk custom inflector.
  • Loading branch information
lis2 authored and SamSaffron committed Oct 2, 2019
1 parent 55ee9ab commit 35b1185
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/demon/demon_base.rb → lib/demon/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Demon; end

# intelligent fork based demonizer
class Demon::DemonBase
class Demon::Base

def self.demons
@demons
Expand Down Expand Up @@ -57,7 +57,7 @@ def pid_file
def alive?(pid = nil)
pid ||= @pid
if pid
Demon::DemonBase.alive?(pid)
Demon::Base.alive?(pid)
else
false
end
Expand Down Expand Up @@ -143,7 +143,7 @@ def run
def already_running?
if File.exists? pid_file
pid = File.read(pid_file).to_i
if Demon::DemonBase.alive?(pid)
if Demon::Base.alive?(pid)
return pid
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/demon/rails_autospec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require "demon/demon_base"
require "demon/base"

class Demon::RailsAutospec < Demon::DemonBase
class Demon::RailsAutospec < Demon::Base

def self.prefix
"rails-autospec"
Expand Down
4 changes: 2 additions & 2 deletions lib/demon/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require "demon/demon_base"
require "demon/base"

class Demon::Sidekiq < ::Demon::DemonBase
class Demon::Sidekiq < ::Demon::Base

def self.prefix
"sidekiq"
Expand Down
6 changes: 3 additions & 3 deletions lib/freedom_patches/zeitwerk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
CUSTOM_PATHS = {
'base' => 'Jobs',
'canonical_url' => 'CanonicalURL',
'clean_up_unmatched_ips' => 'CleanUpUnmatchedIPs',
'homepage_constraint' => 'HomePageConstraint',
Expand All @@ -18,8 +17,9 @@ module ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector
'version' => 'Discourse',
}

def self.camelize(basename, _abspath)
return basename.camelize if _abspath =~ /onceoff\.rb$/
def self.camelize(basename, abspath)
return basename.camelize if abspath =~ /onceoff\.rb$/
return 'Jobs' if abspath =~ /jobs\/base\.rb$/
CUSTOM_PATHS.fetch(basename, basename.camelize)
end
end
2 changes: 1 addition & 1 deletion script/demon_test/parent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

puts "Parent is now loaded"

class ForkExecDemon < Demon::DemonBase
class ForkExecDemon < Demon::Base
def self.prefix
"fork-exec-child"
end
Expand Down

0 comments on commit 35b1185

Please sign in to comment.