Class: Diffend::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/diffend/config.rb

Overview

Diffend config object

Constant Summary collapse

FILENAME =

Name of the diffend config file

'.diffend.yml'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command: nil, severity: nil, build_path: nil) ⇒ Diffend::Config

Build diffend config object

Parameters:

  • command (String) (defaults to: nil)

    command executed via bundler

  • severity (Integer) (defaults to: nil)

    logging severity threshold

  • build_path (String) (defaults to: nil)

    path of the current build



18
19
20
21
22
23
# 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

Instance Attribute Details

#build_pathObject (readonly)

Returns the value of attribute build_path.



9
10
11
# File 'lib/diffend/config.rb', line 9

def build_path
  @build_path
end

#commandObject (readonly)

Returns the value of attribute command.



9
10
11
# File 'lib/diffend/config.rb', line 9

def command
  @command
end

#envObject (readonly)

Returns the value of attribute env.



9
10
11
# File 'lib/diffend/config.rb', line 9

def env
  @env
end

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/diffend/config.rb', line 9

def errors
  @errors
end

#project_idObject (readonly)

Returns the value of attribute project_id.



9
10
11
# File 'lib/diffend/config.rb', line 9

def project_id
  @project_id
end

#shareable_idObject (readonly)

Returns the value of attribute shareable_id.



9
10
11
# File 'lib/diffend/config.rb', line 9

def shareable_id
  @shareable_id
end

#shareable_keyObject (readonly)

Returns the value of attribute shareable_key.



9
10
11
# File 'lib/diffend/config.rb', line 9

def shareable_key
  @shareable_key
end

Instance Method Details

#commands_urlString

Provides diffend commands endpoint url

Returns:

  • (String)


61
62
63
64
65
# 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?Boolean

Returns true if we are in deployment mode, false otherwise.

Returns:

  • (Boolean)

    true if we are in deployment mode, false otherwise



54
55
56
# File 'lib/diffend/config.rb', line 54

def deployment?
  !%w[development test].include?(env)
end

#development?Boolean

Returns true if we are in development mode, false otherwise.

Returns:

  • (Boolean)

    true if we are in development mode, false otherwise



41
42
43
# File 'lib/diffend/config.rb', line 41

def development?
  @development
end

#errors_urlString

Provides diffend errors endpoint url

Returns:

  • (String)


70
71
72
73
74
# 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?Boolean

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.

Returns:

  • (Boolean)

    should we run Diffend or skip it and continue without it.



49
50
51
# File 'lib/diffend/config.rb', line 49

def execute?
  @execute
end

#ignore_errors?Boolean

Returns true if we want to ignore errors, false otherwise.

Returns:

  • (Boolean)

    true if we want to ignore errors, false otherwise



36
37
38
# File 'lib/diffend/config.rb', line 36

def ignore_errors?
  @ignore_errors
end

#loggerObject

Initialize logger



26
27
28
# File 'lib/diffend/config.rb', line 26

def logger
  @logger ||= Diffend::Logger.new(@log_level)
end

Print config errors



84
85
86
# File 'lib/diffend/config.rb', line 84

def print_errors
  @errors.each { |error| logger.fatal(error) }
end

#track_url(request_id) ⇒ String

Parameters:

  • request_id (String)

Returns:

  • (String)


79
80
81
# 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?Boolean

Returns true if config is valid, false otherwise.

Returns:

  • (Boolean)

    true if config is valid, false otherwise



31
32
33
# File 'lib/diffend/config.rb', line 31

def valid?
  @errors.empty?
end