Class: BundleSafeUpdate::Config

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

Constant Summary collapse

DEFAULT_COOLDOWN_DAYS =
14
CONFIG_FILENAME =
'.bundle-safe-update.yml'
DEFAULT_MAX_THREADS =
32
DEFAULT_RISK_SIGNALS =
{
  'low_downloads' => { 'mode' => 'warn', 'threshold' => 1000 },
  'stale_gem' => { 'mode' => 'warn', 'threshold_years' => 3 },
  'new_owner' => { 'mode' => 'warn', 'threshold_days' => 90 },
  'version_jump' => { 'mode' => 'warn' }
}.freeze
DEFAULTS =
{
  'cooldown_days' => DEFAULT_COOLDOWN_DAYS,
  'ignore_prefixes' => [],
  'ignore_gems' => [],
  'trusted_sources' => [],
  'trusted_owners' => [],
  'max_threads' => DEFAULT_MAX_THREADS,
  'audit' => true,
  'verbose' => false,
  'update' => false,
  'lock_only' => false,
  'warn_only' => false,
  'risk_signals' => DEFAULT_RISK_SIGNALS
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



37
38
39
40
41
# File 'lib/bundle_safe_update/config.rb', line 37

def initialize(options = {})
  config = merge_configs(options)
  assign_basic_options(config)
  assign_risk_options(config)
end

Instance Attribute Details

#auditObject (readonly)

Returns the value of attribute audit.



34
35
36
# File 'lib/bundle_safe_update/config.rb', line 34

def audit
  @audit
end

#cooldown_daysObject (readonly)

Returns the value of attribute cooldown_days.



34
35
36
# File 'lib/bundle_safe_update/config.rb', line 34

def cooldown_days
  @cooldown_days
end

#ignore_gemsObject (readonly)

Returns the value of attribute ignore_gems.



34
35
36
# File 'lib/bundle_safe_update/config.rb', line 34

def ignore_gems
  @ignore_gems
end

#ignore_prefixesObject (readonly)

Returns the value of attribute ignore_prefixes.



34
35
36
# File 'lib/bundle_safe_update/config.rb', line 34

def ignore_prefixes
  @ignore_prefixes
end

#lock_onlyObject (readonly)

Returns the value of attribute lock_only.



34
35
36
# File 'lib/bundle_safe_update/config.rb', line 34

def lock_only
  @lock_only
end

#max_threadsObject (readonly)

Returns the value of attribute max_threads.



34
35
36
# File 'lib/bundle_safe_update/config.rb', line 34

def max_threads
  @max_threads
end

#risk_signalsObject (readonly)

Returns the value of attribute risk_signals.



34
35
36
# File 'lib/bundle_safe_update/config.rb', line 34

def risk_signals
  @risk_signals
end

#trusted_ownersObject (readonly)

Returns the value of attribute trusted_owners.



34
35
36
# File 'lib/bundle_safe_update/config.rb', line 34

def trusted_owners
  @trusted_owners
end

#trusted_sourcesObject (readonly)

Returns the value of attribute trusted_sources.



34
35
36
# File 'lib/bundle_safe_update/config.rb', line 34

def trusted_sources
  @trusted_sources
end

#updateObject (readonly)

Returns the value of attribute update.



34
35
36
# File 'lib/bundle_safe_update/config.rb', line 34

def update
  @update
end

#verboseObject (readonly)

Returns the value of attribute verbose.



34
35
36
# File 'lib/bundle_safe_update/config.rb', line 34

def verbose
  @verbose
end

#warn_onlyObject (readonly)

Returns the value of attribute warn_only.



34
35
36
# File 'lib/bundle_safe_update/config.rb', line 34

def warn_only
  @warn_only
end

Instance Method Details

#ignored?(gem_name) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
# File 'lib/bundle_safe_update/config.rb', line 55

def ignored?(gem_name)
  return true if @ignore_gems.include?(gem_name)

  @ignore_prefixes.any? { |prefix| gem_name.start_with?(prefix) }
end

#risk_signal_enabled?(signal_name) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/bundle_safe_update/config.rb', line 47

def risk_signal_enabled?(signal_name)
  risk_signal_mode(signal_name) != 'off'
end

#risk_signal_mode(signal_name) ⇒ Object



43
44
45
# File 'lib/bundle_safe_update/config.rb', line 43

def risk_signal_mode(signal_name)
  @risk_signals.dig(signal_name.to_s, 'mode') || 'off'
end

#risk_signal_threshold(signal_name, key) ⇒ Object



51
52
53
# File 'lib/bundle_safe_update/config.rb', line 51

def risk_signal_threshold(signal_name, key)
  @risk_signals.dig(signal_name.to_s, key.to_s)
end

#trusted_source?(source_url) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
# File 'lib/bundle_safe_update/config.rb', line 61

def trusted_source?(source_url)
  return false if source_url.nil? || @trusted_sources.empty?

  @trusted_sources.any? { |pattern| source_url.include?(pattern) }
end