Module: Diffend

Defined in:
lib/diffend.rb,
lib/diffend/track.rb,
lib/diffend/errors.rb,
lib/diffend/voting.rb,
lib/diffend/request.rb,
lib/diffend/commands.rb,
lib/diffend/config/fetcher.rb,
lib/diffend/request_object.rb,
lib/diffend/config/validator.rb,
lib/diffend/config/file_finder.rb,
lib/diffend/handle_errors/report.rb,
lib/diffend/voting/versions/local.rb,
lib/diffend/handle_errors/messages.rb,
lib/diffend/voting/versions/remote.rb,
lib/diffend/build_bundler_definition.rb,
lib/diffend/handle_errors/display_to_stdout.rb,
lib/diffend/handle_errors/build_exception_payload.rb

Overview

Diffend main namespace

Defined Under Namespace

Modules: BuildBundlerDefinition, Commands, Config, Errors, HandleErrors, Request, Voting Classes: RequestObject, Track

Constant Summary collapse

VERSION =

Current plugin version

'0.2.28'
HOMEPAGE =

Diffend homepage

'https://diffend.io'

Class Method Summary collapse

Class Method Details

.build_outdated_version_message(version) ⇒ String

Parameters:

  • version (Hash)

    installed version

Returns:

  • (String)


117
118
119
120
121
122
# File 'lib/diffend.rb', line 117

def build_outdated_version_message(version)
  "    \\nYou are running an outdated version (\#{version}) of the plugin, which will lead to issues.\n    \\nPlease upgrade to the latest one (\#{VERSION}) by executing \"rm -rf .bundle/plugin\".\\n\n  MSG\nend\n"

.commandString

Command that was run with bundle

Returns:

  • (String)


127
128
129
# File 'lib/diffend.rb', line 127

def command
  ARGV.first || Bundler.feature_flag.default_cli_command.to_s
end

.enabled?Boolean

Checks if plugin is enabled

Returns:

  • (Boolean)

    true if enabled, false otherwise



103
104
105
106
107
108
109
110
111
112
# File 'lib/diffend.rb', line 103

def enabled?
  Bundler
    .default_gemfile
    .read
    .split("\n")
    .reject(&:empty?)
    .map(&:strip)
    .select { |line| line.start_with?('plugin') }
    .any? { |line| line.include?('diffend') }
end

.executeObject

Execute diffend plugin



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/diffend.rb', line 45

def execute
  return unless enabled?

  verify_version

  config = fetch_config

  Diffend::Voting.call(
    command,
    config,
    Diffend::BuildBundlerDefinition.call(
      command,
      Bundler.default_gemfile,
      Bundler.default_lockfile
    )
  )
rescue Diffend::Errors::HandledException
  return if ENV['DIFFEND_IGNORE_ERRORS'] == 'true'

  exit 255
rescue StandardError => e
  Diffend::HandleErrors::Report.call(
    exception: e,
    config: config,
    message: :unhandled_exception,
    report: true,
    raise_exception: false
  )

  return if ENV['DIFFEND_IGNORE_ERRORS'] == 'true'

  exit 255
end

.fetch_configOpenStruct?

Fetch diffend config file

Returns:

  • (OpenStruct, nil)

    configuration object

Raises:



136
137
138
139
140
# File 'lib/diffend.rb', line 136

def fetch_config
  Config::Fetcher.call(
    File.expand_path('..', Bundler.bin_path)
  )
end

.installed_versionString

Returns installed plugin version.

Returns:

  • (String)

    installed plugin version



90
91
92
93
94
95
96
97
98
# File 'lib/diffend.rb', line 90

def installed_version
  Bundler::Plugin
    .index
    .plugin_path('diffend')
    .basename
    .to_s
    .split('-')
    .last
end

.registerObject

Registers the plugin and add before install all hook



38
39
40
41
42
# File 'lib/diffend.rb', line 38

def register
  Bundler::Plugin.add_hook('before-install-all') do |_|
    execute
  end
end

.verify_versionObject



79
80
81
82
83
84
85
86
87
# File 'lib/diffend.rb', line 79

def verify_version
  return if ENV['DIFFEND_DEVELOPMENT'] == 'true'
  return if installed_version == VERSION

  build_outdated_version_message(installed_version)
    .tap(&Bundler.ui.method(:error))

  exit 2
end