Sha256: 530950880e84bb42b2b3ed0db9851ee82a67340d529bf0bb4210270fec426f4f

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

%w[
  bundler
].each(&method(:require))

%w[
  build_bundler_definition
  errors
  config/fetcher
  config/file_finder
  config/validator
  commands
  handle_errors/messages
  handle_errors/build_exception_payload
  handle_errors/display_to_stdout
  handle_errors/report
  request
  voting
].each { |file| require "diffend/#{file}" }

%w[
  versions/local
  versions/remote
].each { |file| require "diffend/voting/#{file}" }

# Diffend main namespace
module Diffend
  # Current plugin version
  VERSION = '0.2.23'
  # Diffend homepage
  HOMEPAGE = 'https://diffend.io'

  class << self
    # Registers the plugin and add before install all hook
    def register
      Bundler::Plugin.add_hook('before-install-all') do |_|
        execute
      end
    end

    # Execute diffend plugin
    def execute
      config = fetch_config

      Diffend::Voting.call(
        command,
        Diffend::BuildBundlerDefinition.call(
          command,
          Bundler.default_gemfile,
          Bundler.default_lockfile
        )
      )
    rescue StandardError => e
      Diffend::HandleErrors::Report.call(
        exception: e,
        config: config,
        message: :unhandled_exception,
        report: true
      )
    end

    # Command that was run with bundle
    #
    # @return [String]
    def command
      ARGV.first || Bundler.feature_flag.default_cli_command.to_s
    end

    # Fetch diffend config file
    #
    # @return [OpenStruct, nil] configuration object
    #
    # @raise [Errors::MissingConfigurationFile] when no config file
    def fetch_config
      Config::Fetcher.call(
        File.expand_path('..', Bundler.bin_path)
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
diffend-0.2.23 lib/diffend.rb