class Diffend::Config
Diffend
config object
Constants
- FILENAME
Name of the diffend config file
Attributes
Public Class Methods
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
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
@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
@return [Boolean] true if we are in development mode, false otherwise
# File lib/diffend/config.rb, line 41 def development? @development end
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
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
@return [Boolean] true if we want to ignore errors, false otherwise
# File lib/diffend/config.rb, line 36 def ignore_errors? @ignore_errors end
Initialize logger
# File lib/diffend/config.rb, line 26 def logger @logger ||= Diffend::Logger.new(@log_level) end
Print config errors
# File lib/diffend/config.rb, line 84 def print_errors @errors.each { |error| logger.fatal(error) } end
@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
@return [Boolean] true if config is valid, false otherwise
# File lib/diffend/config.rb, line 31 def valid? @errors.empty? end
Private Instance Methods
@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
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
@return [String] path to the plugin
# File lib/diffend/config.rb, line 118 def plugin_path Pathname.new(File.expand_path('../..', __dir__)) end