Class: GemEnforcer::Setup::Behavior

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_enforcer/setup/behavior.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gem_name:, index:, **params) ⇒ Behavior

Returns a new instance of Behavior.



12
13
14
15
16
# File 'lib/gem_enforcer/setup/behavior.rb', line 12

def initialize(gem_name:, index:, **params)
  @gem_name = gem_name
  @index = index
  @params = params.transform_keys(&:to_sym)
end

Instance Attribute Details

#gem_nameObject (readonly)

Returns the value of attribute gem_name.



10
11
12
# File 'lib/gem_enforcer/setup/behavior.rb', line 10

def gem_name
  @gem_name
end

#indexObject (readonly)

Returns the value of attribute index.



10
11
12
# File 'lib/gem_enforcer/setup/behavior.rb', line 10

def index
  @index
end

#paramsObject (readonly)

Returns the value of attribute params.



10
11
12
# File 'lib/gem_enforcer/setup/behavior.rb', line 10

def params
  @params
end

Instance Method Details

#error_statusObject



33
34
35
36
37
# File 'lib/gem_enforcer/setup/behavior.rb', line 33

def error_status
  return nil if errors.empty?

  errors.map { "behaviors[#{index}].#{_1}" }
end

#on_failureObject



43
44
45
# File 'lib/gem_enforcer/setup/behavior.rb', line 43

def on_failure
  @on_failure ||= Helper::OnFailure.new(gem_name:, on_failure: params[:on_failure])
end

#run_behavior!(version_list:, version:) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/gem_enforcer/setup/behavior.rb', line 22

def run_behavior!(version_list:, version:)
  unless valid_config?
    raise ConfigError, "Attempted to run validations with invalid Version Configurations"
  end

  return true if version.nil?
  return true if version_enforcer.valid_gem_versions?(version_list:, version:)

  false
end

#run_failure!(message:, version:, version_list:) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/gem_enforcer/setup/behavior.rb', line 47

def run_failure!(message:, version:, version_list:)
  params = {
    version:,
    max_version: version_list.max,
    versions_behind: version_enforcer.versions_behind(version_list:, version:),
  }
  on_failure.run_on_failure!(message:, **params)
end

#valid_config?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/gem_enforcer/setup/behavior.rb', line 18

def valid_config?
  @valid_config ||= validate_config
end

#version_enforcerObject



39
40
41
# File 'lib/gem_enforcer/setup/behavior.rb', line 39

def version_enforcer
  @version_enforcer ||= Helper::VersionEnforcer.new(gem_name:, version_enforce: params[:version_enforce])
end