Skip to content

Commit

Permalink
Update (and adapt code) for Ruby 3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandro-fazzi committed Jan 3, 2022
1 parent 11120be commit 9c1a4c8
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AllCops:
TargetRubyVersion: 2.7.1
TargetRubyVersion: 3.0.2
DisplayCopNames: true
DisplayStyleGuide: true
NewCops: enable
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.1
3.0.2
4 changes: 2 additions & 2 deletions lib/wordmove.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
require 'wordmove/actions/helpers'
require 'wordmove/actions/ssh/helpers'
require 'wordmove/actions/ftp/helpers'
Dir[File.join(__dir__, 'wordmove/actions/**/*.rb')].sort.each { |file| require file }
Dir[File.join(__dir__, 'wordmove/organizers/**/*.rb')].sort.each { |file| require file }
Dir[File.join(__dir__, 'wordmove/actions/**/*.rb')].each { |file| require file }
Dir[File.join(__dir__, 'wordmove/organizers/**/*.rb')].each { |file| require file }

module Wordmove
# Interactors' namespce. Interactors are called "Actions", following the LightService convention.
Expand Down
16 changes: 8 additions & 8 deletions lib/wordmove/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def movefile_from(**cli_options)
exit 1
end

def call_organizer_with(klass:, movefile:, **cli_options)
result = klass.call(cli_options: cli_options, movefile: movefile)
def call_organizer_with(klass:, movefile:, cli_options:)
result = klass.call(cli_options, movefile)

exit 0 if result.success?

Expand Down Expand Up @@ -114,19 +114,19 @@ def call(**cli_options)
private

def call_pull_organizer_with(**cli_options)
movefile = movefile_from(**cli_options)
movefile = movefile_from(cli_options)

if movefile.options.dig(movefile.environment, :ssh)
call_organizer_with(
klass: Wordmove::Organizers::Ssh::Pull,
movefile: movefile,
**cli_options
cli_options: cli_options
)
elsif movefile.options.dig(movefile.environment, :ftp)
call_organizer_with(
klass: Wordmove::Organizers::Ftp::Pull,
movefile: movefile,
**cli_options
cli_options: cli_options
)
else
raise NoAdapterFound, 'No valid adapter found.'
Expand All @@ -149,19 +149,19 @@ def call(**cli_options)
private

def call_push_organizer_with(**cli_options)
movefile = movefile_from(**cli_options)
movefile = movefile_from(cli_options)

if movefile.options.dig(movefile.environment, :ssh)
call_organizer_with(
klass: Wordmove::Organizers::Ssh::Push,
movefile: movefile,
**cli_options
cli_options: cli_options
)
elsif movefile.options.dig(movefile.environment, :ftp)
call_organizer_with(
klass: Wordmove::Organizers::Ftp::Push,
movefile: movefile,
**cli_options
cli_options: cli_options
)
else
raise NoAdapterFound, 'No valid adapter found.'
Expand Down
4 changes: 3 additions & 1 deletion lib/wordmove/organizers/ftp/pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class Pull
include Wordmove::Actions::Helpers
include Wordmove::Actions::Ftp::Helpers

def self.call(cli_options:, movefile:)
# Can't use keyword arguments since LightService still has some problems with modern
# ruby syntax: https://github.com/adomokos/light-service/pull/224
def self.call(cli_options, movefile)
logger = Logger.new($stdout, movefile.secrets).tap { |l| l.level = Logger::DEBUG }
remote_options = movefile.options[movefile.environment]
ftp_opts = ftp_options(remote_options: remote_options)
Expand Down
4 changes: 3 additions & 1 deletion lib/wordmove/organizers/ftp/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class Push
include Wordmove::Actions::Helpers
include Wordmove::Actions::Ftp::Helpers

def self.call(cli_options:, movefile:)
# Can't use keyword arguments since LightService still has some problems with modern
# ruby syntax: https://github.com/adomokos/light-service/pull/224
def self.call(cli_options, movefile)
logger = Logger.new($stdout, movefile.secrets).tap { |l| l.level = Logger::DEBUG }
remote_options = movefile.options[movefile.environment]
ftp_opts = ftp_options(remote_options: remote_options)
Expand Down
4 changes: 3 additions & 1 deletion lib/wordmove/organizers/ssh/pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class Pull
include Wordmove::Actions::Helpers
include Wordmove::Actions::Ssh::Helpers

def self.call(cli_options:, movefile:)
# Can't use keyword arguments since LightService still has some problems with modern
# ruby syntax: https://github.com/adomokos/light-service/pull/224
def self.call(cli_options, movefile)
logger = Logger.new($stdout, movefile.secrets).tap { |l| l.level = Logger::DEBUG }
remote_options = movefile.options[movefile.environment]
ssh_opts = ssh_options(remote_options: remote_options, simulate: cli_options[:simulate])
Expand Down
4 changes: 3 additions & 1 deletion lib/wordmove/organizers/ssh/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class Push
include Wordmove::Actions::Helpers
include Wordmove::Actions::Ssh::Helpers

def self.call(cli_options:, movefile:)
# Can't use keyword arguments since LightService still has some problems with modern
# ruby syntax: https://github.com/adomokos/light-service/pull/224
def self.call(cli_options, movefile)
logger = Logger.new($stdout, movefile.secrets).tap { |l| l.level = Logger::DEBUG }
remote_options = movefile.options[movefile.environment]
ssh_opts = ssh_options(remote_options: remote_options, simulate: cli_options[:simulate])
Expand Down
File renamed without changes.
38 changes: 19 additions & 19 deletions spec/hook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
end

it 'checks the order' do
Wordmove::Organizers::Ssh::Push.call(context)
Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile])

expect(Wordmove::Hook::Local).to(
have_received(:run).with(
Expand Down Expand Up @@ -107,31 +107,31 @@
let(:options) { common_options.merge(environment: 'ssh_with_hooks') }

it 'runs registered before local hooks' do
expect { Wordmove::Organizers::Ssh::Push.call(context) }
expect { Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) }
.to output(/Calling hook push before local/)
.to_stdout
end

it 'runs registered before local hooks in the wordpress folder' do
expect { Wordmove::Organizers::Ssh::Push.call(context) }
expect { Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) }
.to output(/#{Dir.tmpdir}/)
.to_stdout
end

it 'runs registered before remote hooks' do
expect { Wordmove::Organizers::Ssh::Push.call(context) }
expect { Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) }
.to output(/Calling hook push before remote/)
.to_stdout
end

it 'runs registered after local hooks' do
expect { Wordmove::Organizers::Ssh::Push.call(context) }
expect { Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) }
.to output(/Calling hook push after local/)
.to_stdout
end

it 'runs registered after remote hooks' do
expect { Wordmove::Organizers::Ssh::Push.call(context) }
expect { Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) }
.to output(/Calling hook push after remote/)
.to_stdout
end
Expand All @@ -142,7 +142,7 @@
end

it 'does not really run any commands' do
expect { Wordmove::Organizers::Ssh::Push.call(context) }
expect { Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) }
.not_to output(/Output:/)
.to_stdout
end
Expand All @@ -154,7 +154,7 @@
it 'logs an error and raises a LocalHookException' do
expect do
expect do
Wordmove::Organizers::Ssh::Push.call(context)
Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile])
end.to raise_exception(Wordmove::LocalHookException)
end.to output(/Error code: 127/).to_stdout
end
Expand All @@ -167,7 +167,7 @@
it 'logs an error without raising an exeption' do
expect do
expect do
Wordmove::Organizers::Ssh::Push.call(context)
Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile])
end.to_not raise_exception
end.to output(/Error code: 127/)
.to_stdout
Expand All @@ -187,31 +187,31 @@
let(:options) { common_options.merge(environment: 'ssh_with_hooks') }

it 'runs registered before local hooks' do
expect { Wordmove::Organizers::Ssh::Pull.call(context) }
expect { Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile]) }
.to output(/Calling hook pull before local/)
.to_stdout
end

it 'runs registered before remote hooks' do
expect { Wordmove::Organizers::Ssh::Pull.call(context) }
expect { Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile]) }
.to output(/Calling hook pull before remote/)
.to_stdout
end

it 'runs registered after local hooks' do
expect { Wordmove::Organizers::Ssh::Pull.call(context) }
expect { Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile]) }
.to output(/Calling hook pull after local/)
.to_stdout
end

it 'runs registered after remote hooks' do
expect { Wordmove::Organizers::Ssh::Pull.call(context) }
expect { Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile]) }
.to output(/Calling hook pull after remote/)
.to_stdout
end

it 'return remote stdout' do
expect { Wordmove::Organizers::Ssh::Pull.call(context) }
expect { Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile]) }
.to output(/Stubbed remote stdout/)
.to_stdout
end
Expand All @@ -227,7 +227,7 @@
it 'returns remote stdout and raise an exception' do
expect do
expect do
Wordmove::Organizers::Ssh::Pull.call(context)
Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile])
end.to raise_exception(Wordmove::RemoteHookException)
end.to output(/Stubbed remote stderr/)
.to_stdout
Expand All @@ -236,7 +236,7 @@
it 'raises a RemoteHookException' do
expect do
silence_stream($stdout) do
Wordmove::Organizers::Ssh::Pull.call(context)
Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile])
end
end.to raise_exception(Wordmove::RemoteHookException)
end
Expand All @@ -251,7 +251,7 @@
expect(Wordmove::Hook::Remote)
.to_not receive(:run)

expect { Wordmove::Organizers::Ftp::Push.call(**context) }
expect { Wordmove::Organizers::Ftp::Push.call(context[:cli_options], context[:movefile]) }
.to output(
/You have configured remote hooks to run over an FTP connection, but this is not possible/ # rubocop:disable Layout/LineLength
).to_stdout
Expand All @@ -269,12 +269,12 @@
.to_not receive(:run)

silence_stream($stdout) do
Wordmove::Organizers::Ssh::Push.call(context)
Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile])
end
end

it "works silently ignoring 'before' step is not present" do
expect { Wordmove::Organizers::Ssh::Pull.call(context) }
expect { Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile]) }
.to output(/I've partially configured my hooks/)
.to_stdout
end
Expand Down
5 changes: 1 addition & 4 deletions spec/support/action_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ def self.make_for(action, wordmove_action, cli_options: {})
LightService::Testing::ContextFactory
.make_from("Wordmove::Organizers::Ssh::#{wordmove_action.to_s.camelize}".constantize)
.for(action)
.with(
cli_options: cli_options,
movefile: movefile
)
.with(cli_options, movefile)
end
end

Expand Down
2 changes: 1 addition & 1 deletion wordmove.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'dry-cli', '~> 0.7.0'
spec.add_runtime_dependency 'dry-files', '~> 0.1.0'

spec.required_ruby_version = '>= 2.6.0' # rubocop:disable Gemspec/RequiredRubyVersion
spec.required_ruby_version = '>= 3.0.2'

spec.add_development_dependency 'bundler', '~> 2.3.3'
spec.add_development_dependency 'pry-byebug', '~> 3.1'
Expand Down

0 comments on commit 9c1a4c8

Please sign in to comment.