Skip to content

Commit

Permalink
Update RuboCop and simplify its configuration (#100)
Browse files Browse the repository at this point in the history
* Update RuboCop and simplify its configuration
* Fix specs
  • Loading branch information
gael-ian committed Feb 26, 2023
1 parent 5d3ead6 commit fcea83b
Show file tree
Hide file tree
Showing 58 changed files with 142 additions and 117 deletions.
24 changes: 1 addition & 23 deletions .rubocop.yml
@@ -1,33 +1,11 @@
---
require:
- rubocop-performance
- rubocop-rake
- rubocop-rspec

AllCops:
DisplayCopNames: true
TargetRubyVersion: 2.7
NewCops: enable

Layout/LineLength:
Max: 150

Metrics/BlockLength:
Exclude:
- 'spec/**/*_spec.rb'

RSpec/FilePath:
Enabled: No

RSpec/MultipleExpectations:
Max: 2

Style/Documentation:
Enabled: No

Naming/FileName:
Enabled: No

# Rubocop does not interpolate version specifiers
# and report ~>2.4 as not compatible with 2.6.5...
Gemspec/RequiredRubyVersion:
Enabled: No
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs.rb
Expand Up @@ -6,7 +6,7 @@
raise 'The Vagrant bindfs plugin must be run within Vagrant'
end

module VagrantBindfs
module VagrantBindfs # :nodoc:
autoload :Vagrant, 'vagrant-bindfs/vagrant'
autoload :Bindfs, 'vagrant-bindfs/bindfs'
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/bindfs.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module VagrantBindfs
module Bindfs
module Bindfs # :nodoc:
SOURCE_VERSION = '1.17.2'
SOURCE_URLS = [
'https://bindfs.org/downloads/%<basename>s.tar.gz',
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/bindfs/command.rb
Expand Up @@ -2,7 +2,7 @@

module VagrantBindfs
module Bindfs
class Command
class Command # :nodoc:
attr_reader :folder

def initialize(folder)
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/bindfs/folder.rb
Expand Up @@ -4,7 +4,7 @@

module VagrantBindfs
module Bindfs
class Folder
class Folder # :nodoc:
attr_reader :source,
:destination,
:options,
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/bindfs/option_set.rb
Expand Up @@ -4,7 +4,7 @@

module VagrantBindfs
module Bindfs
class OptionSet
class OptionSet # :nodoc:
attr_reader :version,
:options,
:invalid_options,
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/bindfs/validators.rb
Expand Up @@ -2,7 +2,7 @@

module VagrantBindfs
module Bindfs
module Validators
module Validators # :nodoc:
autoload :Config, 'vagrant-bindfs/bindfs/validators/config'
autoload :Runtime, 'vagrant-bindfs/bindfs/validators/runtime'
end
Expand Down
20 changes: 14 additions & 6 deletions lib/vagrant-bindfs/bindfs/validators/config.rb
Expand Up @@ -5,7 +5,7 @@
module VagrantBindfs
module Bindfs
module Validators
class Config
class Config # :nodoc:
attr_reader :folder,
:errors

Expand All @@ -28,24 +28,32 @@ def valid?
protected

def validate_source!
@errors << I18n.t('vagrant-bindfs.validations.source_path_required') if source.empty?
@errors << I18n.t('vagrant-bindfs.validations.path_must_be_absolute', path: source) if relative_path?(source)
@errors << invalid('source_path_required') if source.empty?
@errors << invalid('path_must_be_absolute', path: source) if relative_path?(source)
end

def validate_destination!
@errors << I18n.t('vagrant-bindfs.validations.destination_path_required') if destination.empty?
@errors << I18n.t('vagrant-bindfs.validations.path_must_be_absolute', path: destination) if relative_path?(destination)
@errors << invalid('destination_path_required') if destination.empty?
@errors << invalid('path_must_be_absolute', path: destination) if relative_path?(destination)
end

def validate_options!
folder.options.invalid_options.each_key do |option_name|
@errors << I18n.t(option_name.tr('-', '_'), scope: 'vagrant-bindfs.deprecations')
@errors << deprecation(option_name.tr('-', '_'))
end
end

def relative_path?(path)
Pathname.new(path).relative?
end

def invalid(key, **options)
I18n.t(key, **options.merge(scope: 'vagrant-bindfs.validations'))
end

def deprecation(key)
I18n.t(key, scope: 'vagrant-bindfs.deprecations')
end
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/vagrant-bindfs/bindfs/validators/runtime.rb
Expand Up @@ -3,7 +3,7 @@
module VagrantBindfs
module Bindfs
module Validators
class Runtime < Config
class Runtime < Config # :nodoc:
attr_reader :machine

def initialize(folder, machine)
Expand All @@ -16,13 +16,13 @@ def initialize(folder, machine)
def validate_source!
super

@errors << I18n.t('vagrant-bindfs.validations.source_path_does_not_exist', path: source) unless directory_exists?(source)
@errors << invalid('source_path_does_not_exist', path: source) unless directory_exists?(source)
end

def validate_destination!
super

@errors << I18n.t('vagrant-bindfs.validations.destination_already_mounted', dest: destination) if mount_exists?(destination)
@errors << invalid('destination_already_mounted', dest: destination) if mount_exists?(destination)
end

def validate_options!
Expand All @@ -44,14 +44,14 @@ def validate_user
return if machine.config.bindfs.skip_validations.include?(:user)
return if machine.guest.capability(:bindfs_exists_user, options['force-user'])

@errors << I18n.t('vagrant-bindfs.validations.user_does_not_exist', user: options['force-user'])
@errors << invalid('user_does_not_exist', user: options['force-user'])
end

def validate_group
return if machine.config.bindfs.skip_validations.include?(:group)
return if machine.guest.capability(:bindfs_exists_group, options['force-group'])

@errors << I18n.t('vagrant-bindfs.validations.group_does_not_exist', group: options['force-group'])
@errors << invalid('group_does_not_exist', group: options['force-group'])
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/vagrant.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module VagrantBindfs
module Vagrant
module Vagrant # :nodoc:
autoload :Plugin, 'vagrant-bindfs/vagrant/plugin'
autoload :Config, 'vagrant-bindfs/vagrant/config'
autoload :Capabilities, 'vagrant-bindfs/vagrant/capabilities'
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/vagrant/actions.rb
Expand Up @@ -2,7 +2,7 @@

module VagrantBindfs
module Vagrant
module Actions
module Actions # :nodoc:
autoload :Installer, 'vagrant-bindfs/vagrant/actions/installer'
autoload :Mounter, 'vagrant-bindfs/vagrant/actions/mounter'

Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/vagrant/actions/concerns.rb
Expand Up @@ -3,7 +3,7 @@
module VagrantBindfs
module Vagrant
module Actions
module Concerns
module Concerns # :nodoc:
autoload :Log, 'vagrant-bindfs/vagrant/actions/concerns/log'
autoload :Machine, 'vagrant-bindfs/vagrant/actions/concerns/machine'
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/vagrant/actions/concerns/log.rb
Expand Up @@ -4,7 +4,7 @@ module VagrantBindfs
module Vagrant
module Actions
module Concerns
module Log
module Log # :nodoc:
def logger
env[:ui]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/vagrant/actions/concerns/machine.rb
Expand Up @@ -4,7 +4,7 @@ module VagrantBindfs
module Vagrant
module Actions
module Concerns
module Machine
module Machine # :nodoc:
def machine
env[:machine]
end
Expand Down
11 changes: 8 additions & 3 deletions lib/vagrant-bindfs/vagrant/actions/installer.rb
Expand Up @@ -3,7 +3,7 @@
module VagrantBindfs
module Vagrant
module Actions
class Installer
class Installer # :nodoc:
attr_reader :app,
:env

Expand Down Expand Up @@ -91,9 +91,14 @@ def install_bindfs_from_repositories!
end

def install_bindfs_from_source!
version = (config.bindfs_version == :latest ? VagrantBindfs::Bindfs::SOURCE_VERSION : config.bindfs_version.to_s)
guest.capability(:bindfs_bindfs_install_compilation_requirements)
guest.capability(:bindfs_bindfs_install_from_source, version)
guest.capability(:bindfs_bindfs_install_from_source, source_version)
end

def source_version
return VagrantBindfs::Bindfs::SOURCE_VERSION if config.bindfs_version == :latest

config.bindfs_version.to_s
end

def install_from_source?
Expand Down
7 changes: 5 additions & 2 deletions lib/vagrant-bindfs/vagrant/actions/mounter.rb
Expand Up @@ -3,7 +3,7 @@
module VagrantBindfs
module Vagrant
module Actions
class Mounter
class Mounter # :nodoc:
attr_reader :app,
:env,
:hook
Expand Down Expand Up @@ -87,7 +87,10 @@ def execute_bind_command!(comm, folder)
)

command = VagrantBindfs::Bindfs::Command.new(folder)
comm.sudo(command.to_s(bindfs_full_path), error_class: VagrantBindfs::Vagrant::Error, error_key: 'bindfs.mount_failed')
comm.sudo(command.to_s(bindfs_full_path),
error_class: VagrantBindfs::Vagrant::Error,
error_key: 'bindfs.mount_failed')

debug(command.to_s(bindfs_full_path))
end

Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/vagrant/capabilities.rb
Expand Up @@ -2,7 +2,7 @@

module VagrantBindfs
module Vagrant
module Capabilities
module Capabilities # :nodoc:
autoload :All, 'vagrant-bindfs/vagrant/capabilities/all'

autoload :Darwin, 'vagrant-bindfs/vagrant/capabilities/darwin'
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/vagrant/capabilities/all.rb
Expand Up @@ -3,7 +3,7 @@
module VagrantBindfs
module Vagrant
module Capabilities
module All
module All # :nodoc:
autoload :SystemChecks, 'vagrant-bindfs/vagrant/capabilities/all/system_checks'
autoload :PackageManager, 'vagrant-bindfs/vagrant/capabilities/all/package_manager'
autoload :Bindfs, 'vagrant-bindfs/vagrant/capabilities/all/bindfs'
Expand Down
13 changes: 11 additions & 2 deletions lib/vagrant-bindfs/vagrant/capabilities/all/bindfs.rb
Expand Up @@ -4,7 +4,7 @@ module VagrantBindfs
module Vagrant
module Capabilities
module All
module Bindfs
module Bindfs # :nodoc:
class << self
def bindfs_bindfs_full_path(machine)
machine.communicate.execute('bash -c "type -P bindfs || true"') do |_, output|
Expand All @@ -21,7 +21,7 @@ def bindfs_bindfs_installed(machine)

def bindfs_bindfs_version(machine)
bindfs_full_path = machine.guest.capability(:bindfs_bindfs_full_path)
[%(sudo #{bindfs_full_path} --version | cut -d" " -f2), %(sudo -i #{bindfs_full_path} --version | cut -d" " -f2)].each do |command|
bindfs_bindfs_version_detection_commands(bindfs_full_path).each do |command|
machine.communicate.execute(command) do |_, output|
version = output.strip
return Gem::Version.new(version) if !version.empty? && Gem::Version.correct?(version)
Expand Down Expand Up @@ -58,6 +58,15 @@ def bindfs_bindfs_install_from_source(machine, version)
make && \
sudo make install
SHELL

protected

def bindfs_bindfs_version_detection_commands(bindfs_full_path)
[
%(sudo #{bindfs_full_path} --version | cut -d" " -f2),
%(sudo -i #{bindfs_full_path} --version | cut -d" " -f2)
]
end
end
end
end
Expand Down
Expand Up @@ -4,7 +4,7 @@ module VagrantBindfs
module Vagrant
module Capabilities
module All
module PackageManager
module PackageManager # :nodoc:
class << self
def bindfs_package_manager_installed(machine)
package_manager_name = machine.guest.capability(:bindfs_package_manager_name)
Expand Down
Expand Up @@ -4,7 +4,7 @@ module VagrantBindfs
module Vagrant
module Capabilities
module All
module SystemChecks
module SystemChecks # :nodoc:
class << self
def bindfs_exists_directory(machine, directory)
machine.communicate.test("test -d #{directory.shellescape}")
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/vagrant/capabilities/darwin.rb
Expand Up @@ -3,7 +3,7 @@
module VagrantBindfs
module Vagrant
module Capabilities
module Darwin
module Darwin # :nodoc:
autoload :SystemChecks, 'vagrant-bindfs/vagrant/capabilities/darwin/system_checks'
autoload :PackageManager, 'vagrant-bindfs/vagrant/capabilities/darwin/package_manager'
autoload :Fuse, 'vagrant-bindfs/vagrant/capabilities/darwin/fuse'
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/vagrant/capabilities/darwin/bindfs.rb
Expand Up @@ -4,7 +4,7 @@ module VagrantBindfs
module Vagrant
module Capabilities
module Darwin
module Bindfs
module Bindfs # :nodoc:
class << self
# Homebrew only use its own github repositories
def bindfs_bindfs_search(_machine)
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/vagrant/capabilities/darwin/fuse.rb
Expand Up @@ -4,7 +4,7 @@ module VagrantBindfs
module Vagrant
module Capabilities
module Darwin
module Fuse
module Fuse # :nodoc:
class << self
def bindfs_fuse_installed(machine)
machine.communicate.test('test -d /Library/Frameworks/OSXFUSE.framework/')
Expand Down
Expand Up @@ -4,7 +4,7 @@ module VagrantBindfs
module Vagrant
module Capabilities
module Darwin
module PackageManager
module PackageManager # :nodoc:
class << self
def bindfs_package_manager_name(_machine)
'brew'
Expand Down
Expand Up @@ -4,7 +4,7 @@ module VagrantBindfs
module Vagrant
module Capabilities
module Darwin
module SystemChecks
module SystemChecks # :nodoc:
class << self
def bindfs_exists_user(machine, user)
(
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-bindfs/vagrant/capabilities/debian.rb
Expand Up @@ -3,7 +3,7 @@
module VagrantBindfs
module Vagrant
module Capabilities
module Debian
module Debian # :nodoc:
autoload :PackageManager, 'vagrant-bindfs/vagrant/capabilities/debian/package_manager'
autoload :Fuse, 'vagrant-bindfs/vagrant/capabilities/debian/fuse'
autoload :Bindfs, 'vagrant-bindfs/vagrant/capabilities/debian/bindfs'
Expand Down

0 comments on commit fcea83b

Please sign in to comment.