Skip to content

Commit

Permalink
Merge pull request #3681 from zendesk/grosser/zeitwerk
Browse files Browse the repository at this point in the history
make zeitwerk work by renaming plugin base class
  • Loading branch information
grosser committed Feb 3, 2020
2 parents 2314dc2 + 7938142 commit 925b687
Show file tree
Hide file tree
Showing 37 changed files with 49 additions and 50 deletions.
2 changes: 1 addition & 1 deletion app/models/job_execution.rb
Expand Up @@ -156,7 +156,7 @@ def execute(dir)

# ideally the plugin should handle this, but that was even hackier
def kubernetes?
defined?(SamsonKubernetes::Engine) && @stage&.kubernetes
defined?(SamsonKubernetes::SamsonPlugin) && @stage&.kubernetes
end

def setup(dir)
Expand Down
1 change: 0 additions & 1 deletion config/application.rb
Expand Up @@ -42,7 +42,6 @@ class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
config.load_defaults 6.0
config.autoloader = :classic # TODO: use :zeitwerk, but that clashes with app/decorators

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = (ENV["FORCE_SSL"] == "1")
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/plugin/templates/samson_plugin.rb.erb
@@ -1,5 +1,5 @@
module Samson<%= class_name %>
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/samson/hooks.rb
Expand Up @@ -113,7 +113,7 @@ def add_assets_to_precompile
end

def engine
@engine ||= Kernel.const_get("::Samson#{@name.camelize}::Engine")
@engine ||= Kernel.const_get("::Samson#{@name.camelize}::SamsonPlugin")
end

private
Expand All @@ -133,7 +133,7 @@ def decorator_class(path)
class << self
def plugins
@plugins ||= begin
Gem.find_files("*/samson_plugin.rb").
Gem.find_files("samson_*/samson_plugin.rb").
map { |path| Plugin.new(path) }.
select { |p| active_plugin?(p.name) }.
sort_by(&:name)
Expand Down
4 changes: 2 additions & 2 deletions plugins/airbrake/lib/samson_airbrake/samson_plugin.rb
Expand Up @@ -3,7 +3,7 @@
require 'airbrake'

module SamsonAirbrake
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
def self.exception_debug_info(notice)
return unless notice
return 'Airbrake did not return an error id' unless id = notice['id']
Expand All @@ -14,7 +14,7 @@ def self.exception_debug_info(notice)

Samson::Hooks.callback :error do |exception, sync: false, **options|
if sync
SamsonAirbrake::Engine.exception_debug_info(Airbrake.notify_sync(exception, options))
SamsonAirbrake::SamsonPlugin.exception_debug_info(Airbrake.notify_sync(exception, options))
else
Airbrake.notify(exception, options)
end
Expand Down
8 changes: 4 additions & 4 deletions plugins/airbrake/test/samson_airbrake/samson_plugin_test.rb
Expand Up @@ -8,15 +8,15 @@
describe '.exception_debug_info' do
it 'returns error debug info' do
notice = {'id' => '1'}
SamsonAirbrake::Engine.exception_debug_info(notice).must_equal 'Error https://airbrake.io/locate/1'
SamsonAirbrake::SamsonPlugin.exception_debug_info(notice).must_equal 'Error https://airbrake.io/locate/1'
end

it 'returns nil if airbrake fails' do
SamsonAirbrake::Engine.exception_debug_info(nil).must_be_nil
SamsonAirbrake::SamsonPlugin.exception_debug_info(nil).must_be_nil
end

it 'returns airbrake id error if there is no id' do
SamsonAirbrake::Engine.exception_debug_info({}).must_equal 'Airbrake did not return an error id'
SamsonAirbrake::SamsonPlugin.exception_debug_info({}).must_equal 'Airbrake did not return an error id'
end
end

Expand All @@ -25,7 +25,7 @@
mock_notice = mock
mock_exception = mock
Airbrake.expects(:notify_sync).with(mock_exception, foo: 'bar').once.returns(mock_notice)
SamsonAirbrake::Engine.expects(:exception_debug_info).with(mock_notice).once
SamsonAirbrake::SamsonPlugin.expects(:exception_debug_info).with(mock_notice).once

Samson::Hooks.only_callbacks_for_plugin('airbrake', :error) do
Samson::Hooks.fire(:error, mock_exception, foo: 'bar', sync: true)
Expand Down
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module SamsonAirbrakeHook
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end

class Notification
Expand Down
Expand Up @@ -3,7 +3,7 @@

SingleCov.covered!

describe SamsonAirbrakeHook::Engine do
describe SamsonAirbrakeHook::SamsonPlugin do
describe :after_deploy do
def notify
Samson::Hooks.fire :after_deploy, deploy, stub(output: nil)
Expand Down
2 changes: 1 addition & 1 deletion plugins/assertible/lib/samson_assertible/samson_plugin.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module SamsonAssertible
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end

class Notification
Expand Down
6 changes: 3 additions & 3 deletions plugins/aws_ecr/lib/samson_aws_ecr/samson_plugin.rb
Expand Up @@ -2,7 +2,7 @@
require 'aws-sdk-ecr'

module SamsonAwsEcr
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
AMAZON_REGISTRY = /\A.*\.dkr.ecr.([\w\-]+).amazonaws.com\z/.freeze

class << self
Expand Down Expand Up @@ -64,6 +64,6 @@ def ecr_client(registry)
# need credentials to pull (via Dockerfile FROM) and push images
# ATM this only authenticates the default docker registry and not any extra registries
Samson::Hooks.callback :before_docker_repository_usage do |build|
SamsonAwsEcr::Engine.ensure_repositories(build)
SamsonAwsEcr::Engine.refresh_credentials
SamsonAwsEcr::SamsonPlugin.ensure_repositories(build)
SamsonAwsEcr::SamsonPlugin.refresh_credentials
end
12 changes: 6 additions & 6 deletions plugins/aws_ecr/test/samson_aws_ecr/samson_plugin_test.rb
Expand Up @@ -3,9 +3,9 @@

SingleCov.covered! uncovered: 2

describe SamsonAwsEcr::Engine do
describe SamsonAwsEcr::SamsonPlugin do
def clear_client
SamsonAwsEcr::Engine.instance_variable_set(:@ecr_clients, nil)
SamsonAwsEcr::SamsonPlugin.instance_variable_set(:@ecr_clients, nil)
end

let(:stage) { stages(:test_staging) }
Expand Down Expand Up @@ -42,7 +42,7 @@ def fire

run_inside_of_temp_directory

before { SamsonAwsEcr::Engine.stubs(:ecr_client).returns(ecr_client) }
before { SamsonAwsEcr::SamsonPlugin.stubs(:ecr_client).returns(ecr_client) }

describe '.refresh_credentials' do
it "changes the username and password" do
Expand Down Expand Up @@ -138,7 +138,7 @@ def fire
it 'is caches' do
assert_request(:get, %r{/latest/meta-data/iam/security-credentials/}, times: 3) do
Array.new(2).map do
SamsonAwsEcr::Engine.send(:ecr_client, DockerRegistry.first).object_id
SamsonAwsEcr::SamsonPlugin.send(:ecr_client, DockerRegistry.first).object_id
end.uniq.size.must_equal 1
end
end
Expand All @@ -147,12 +147,12 @@ def fire
describe '.active?' do
it "is inactive when not on ecr" do
DockerRegistry.first.instance_variable_get(:@uri).host = 'xyz.com'
refute SamsonAwsEcr::Engine.active?
refute SamsonAwsEcr::SamsonPlugin.active?
end

it "is active when on ecr" do
assert_request(:get, "http://169.254.169.254/latest/meta-data/iam/security-credentials/", times: 3) do
assert SamsonAwsEcr::Engine.active?
assert SamsonAwsEcr::SamsonPlugin.active?
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/aws_sts/lib/samson_aws_sts/samson_plugin.rb
Expand Up @@ -5,7 +5,7 @@ module SamsonAwsSts
SESSION_DURATION_MIN = 900 # 15 minutes
SESSION_DURATION_MAX = [SESSION_DURATION_MIN, Rails.application.config.samson.deploy_timeout].max

class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end

def self.sts_client
Expand Down
2 changes: 1 addition & 1 deletion plugins/datadog/lib/samson_datadog/samson_plugin.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module SamsonDatadog
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end

class << self
Expand Down
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module SamsonDatadogTracer
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end

class << self
Expand Down
2 changes: 1 addition & 1 deletion plugins/env/lib/samson_env/samson_plugin.rb
Expand Up @@ -9,7 +9,7 @@ module SamsonEnv
</ul>
TEXT

class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end

class << self
Expand Down
2 changes: 1 addition & 1 deletion plugins/flowdock/lib/samson_flowdock/samson_plugin.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module SamsonFlowdock
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end
end

Expand Down
2 changes: 1 addition & 1 deletion plugins/gcloud/lib/samson_gcloud/samson_plugin.rb
Expand Up @@ -7,7 +7,7 @@ module SamsonGcloud
SCAN_WAIT_PERIOD = 10.minutes
SCAN_SLEEP_PERIOD = 5.seconds

class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end

class << self
Expand Down
2 changes: 1 addition & 1 deletion plugins/github/lib/samson_github/samson_plugin.rb
Expand Up @@ -5,7 +5,7 @@ module SamsonGithub
# however 'https://www.githubstatus.com' also works
STATUS_URL = ENV["GITHUB_STATUS_URL"] || 'https://www.githubstatus.com'

class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end
end

Expand Down
2 changes: 1 addition & 1 deletion plugins/gitlab/lib/samson_gitlab/samson_plugin.rb
Expand Up @@ -3,7 +3,7 @@
require 'git_diff_parser'

module SamsonGitlab
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
Gitlab.configure do |config|
config.endpoint = "#{Rails.application.config.samson.gitlab.web_url}/api/v4"
config.private_token = ENV['GITLAB_TOKEN']
Expand Down
2 changes: 1 addition & 1 deletion plugins/jenkins/lib/samson_jenkins/samson_plugin.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module SamsonJenkins
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end
end

Expand Down
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module SamsonJenkinsStatusChecker
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end
end

Expand Down
2 changes: 1 addition & 1 deletion plugins/jira/lib/samson_jira/samson_plugin.rb
Expand Up @@ -3,7 +3,7 @@
require 'base64'

module SamsonJira
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end

def self.jira_base_url
Expand Down
Expand Up @@ -21,7 +21,7 @@ def index
end

def seed_ecr
SamsonAwsEcr::Engine.refresh_credentials
SamsonAwsEcr::SamsonPlugin.refresh_credentials
@kubernetes_cluster.namespaces.each do |namespace|
update_secret namespace
end
Expand Down
Expand Up @@ -39,7 +39,7 @@
</div>

<%= form.actions delete: true do %>
<% if Samson::Hooks.active_plugin?('aws_ecr') && SamsonAwsEcr::Engine.active? && @kubernetes_cluster.persisted? %>
<% if Samson::Hooks.active_plugin?('aws_ecr') && SamsonAwsEcr::SamsonPlugin.active? && @kubernetes_cluster.persisted? %>
<%= link_to "Seed ECR", seed_ecr_kubernetes_cluster_path(@kubernetes_cluster), class: "btn btn-default", data: {method: :post} %>
<% end %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion plugins/kubernetes/lib/samson_kubernetes/samson_plugin.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module SamsonKubernetes
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
initializer "refinery.assets.precompile" do |app|
app.config.assets.precompile.append %w[kubernetes/icon.png]
end
Expand Down
Expand Up @@ -65,7 +65,7 @@ def self.use_example_config
let(:secrets_url) { "http://foobar.server/api/v1/namespaces/foobar/secrets" }

before do
SamsonAwsEcr::Engine.expects(:refresh_credentials)
SamsonAwsEcr::SamsonPlugin.expects(:refresh_credentials)
DockerRegistry.first.username = 'user'
DockerRegistry.first.password = 'pass'
end
Expand Down Expand Up @@ -99,7 +99,7 @@ def self.use_example_config
end

it "renders when ECR plugin is active" do
SamsonAwsEcr::Engine.expects(:active?).returns(true)
SamsonAwsEcr::SamsonPlugin.expects(:active?).returns(true)
get :new
assert_template :new
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/ledger/lib/samson_ledger/samson_plugin.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module SamsonLedger
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end
end

Expand Down
2 changes: 1 addition & 1 deletion plugins/new_relic/lib/samson_new_relic/samson_plugin.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module SamsonNewRelic
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end

def self.find_api_key
Expand Down
2 changes: 1 addition & 1 deletion plugins/pipelines/lib/samson_pipelines/samson_plugin.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module SamsonPipelines
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end

class << self
Expand Down
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module SamsonPrerequisiteStages
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end

def self.validate_deployed_to_all_prerequisite_stages(stage, reference, commit)
Expand Down
Expand Up @@ -17,7 +17,7 @@
deploy.project.stubs(:repo_commit_from_ref).with(stage2.deploys.first.reference).returns(production_commit)
end

describe SamsonPrerequisiteStages::Engine do
describe SamsonPrerequisiteStages::SamsonPlugin do
describe '.validate_deployed_to_all_prerequisite_stages' do
it 'shows unmet prerequisite stages' do
stage1.expects(:undeployed_prerequisite_stages).with(staging_commit).returns([stage2])
Expand Down
2 changes: 1 addition & 1 deletion plugins/rollbar/lib/samson_rollbar/samson_plugin.rb
Expand Up @@ -4,7 +4,7 @@
require 'rollbar/user_informer'

module SamsonRollbar
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end
end

Expand Down
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module SamsonRollbarDashboards
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
config.assets.precompile.append ['rollbar_dashboards/icon.png', 'rollbar_dashboards/deploy_dashboard.js']
end

Expand Down
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module SamsonRollbarHook
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end
end

Expand Down
2 changes: 1 addition & 1 deletion plugins/slack_app/lib/samson_slack_app/samson_plugin.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
module SamsonSlackApp
class Engine < Rails::Engine
class SamsonPlugin < Rails::Engine
end
end

Expand Down

0 comments on commit 925b687

Please sign in to comment.