class Diffend::Config

Diffend config object

Constants

FILENAME

Name of the diffend config file

Attributes

build_path[R]
command[R]
env[R]
errors[R]
project_id[R]
shareable_id[R]
shareable_key[R]

Public Class Methods

new(command: nil, severity: nil, build_path: nil) click to toggle source

Build diffend config object

@param command [String] command executed via bundler @param severity [Integer] logging severity threshold @param build_path [String] path of the current build

@return [Diffend::Config]

# File lib/diffend/config.rb, line 18
def initialize(command: nil, severity: nil, build_path: nil)
  @log_level = severity
  @errors = []
  build(command, build_path)
  Diffend::Configs::Validator.call(self)
end

Public Instance Methods

commands_url() click to toggle source

Provides diffend commands endpoint url

@return [String]

# File lib/diffend/config.rb, line 61
def commands_url
  return ENV['DIFFEND_COMMANDS_URL'] if ENV.key?('DIFFEND_COMMANDS_URL')

  "https://my.diffend.io/api/projects/#{project_id}/bundle/#{command}"
end
deployment?() click to toggle source

@return [Boolean] true if we are in deployment mode, false otherwise

# File lib/diffend/config.rb, line 54
def deployment?
  !%w[development test].include?(env)
end
development?() click to toggle source

@return [Boolean] true if we are in development mode, false otherwise

# File lib/diffend/config.rb, line 41
def development?
  @development
end
errors_url() click to toggle source

Provides diffend errors endpoint url

@return [String]

# File lib/diffend/config.rb, line 70
def errors_url
  return ENV['DIFFEND_ERRORS_URL'] if ENV.key?('DIFFEND_ERRORS_URL')

  "https://my.diffend.io/api/projects/#{project_id}/errors"
end
execute?() click to toggle source

This method is provided just in case something would go wrong with Diffend but there would be a need to run Bundler anyhow. Please don't use unless aware of the downsides.

@return [Boolean] should we run Diffend or skip it and continue without it.

# File lib/diffend/config.rb, line 49
def execute?
  @execute
end
ignore_errors?() click to toggle source

@return [Boolean] true if we want to ignore errors, false otherwise

# File lib/diffend/config.rb, line 36
def ignore_errors?
  @ignore_errors
end
logger() click to toggle source

Initialize logger

# File lib/diffend/config.rb, line 26
def logger
  @logger ||= Diffend::Logger.new(@log_level)
end
print_errors() click to toggle source

Print config errors

track_url(request_id) click to toggle source

@param request_id [String]

@return [String]

# File lib/diffend/config.rb, line 79
def track_url(request_id)
  "https://my.diffend.io/api/projects/#{project_id}/bundle/#{request_id}/track"
end
valid?() click to toggle source

@return [Boolean] true if config is valid, false otherwise

# File lib/diffend/config.rb, line 31
def valid?
  @errors.empty?
end

Private Instance Methods

build(command, build_path) click to toggle source

@param command [String] command executed via bundler @param build_path [String] path of the current build

# File lib/diffend/config.rb, line 92
def build(command, build_path)
  build_path ||= File.expand_path('..', ::Bundler.bin_path)
  hash = Diffend::Configs::Fetcher.call(plugin_path, build_path)
  hash['build_path'] = build_path
  hash['command'] = command || build_command

  hash.each { |key, value| instance_variable_set(:"@#{key}", value) }
rescue Errors::MalformedConfigurationFile
  @errors << Diffend::Configs::ErrorMessages.malformed_file
end
build_command() click to toggle source

Command that was run with bundle

@return [String]

# File lib/diffend/config.rb, line 106
def build_command
  default = ::Bundler.feature_flag.default_cli_command.to_s

  return default unless ARGV.first
  # There is a case where no command may be provided and the first argument is the first option
  # In a case like this we fallback to default command
  return default if ARGV.first.start_with?('-')

  ARGV.first
end
plugin_path() click to toggle source

@return [String] path to the plugin

# File lib/diffend/config.rb, line 118
def plugin_path
  Pathname.new(File.expand_path('../..', __dir__))
end