Class: GemEnforcer::Setup::Helper::VersionEnforcer
- Inherits:
-
Object
- Object
- GemEnforcer::Setup::Helper::VersionEnforcer
- Defined in:
- lib/gem_enforcer/setup/helper/version_enforcer.rb
Constant Summary collapse
- ALLOWED_VERSION_INSYNC =
:insync
- ALLOWED_VERSION_REALEASE =
:releases
- ALLOWED_VERSION_SEMVER =
[MAJOR = :major, MINOR = :minor, PATCH = :patch]
Instance Attribute Summary collapse
-
#error_validation_message ⇒ Object
readonly
Returns the value of attribute error_validation_message.
-
#gem_name ⇒ Object
readonly
Returns the value of attribute gem_name.
-
#version_enforce ⇒ Object
readonly
Returns the value of attribute version_enforce.
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(gem_name:, version_enforce:) ⇒ VersionEnforcer
constructor
A new instance of VersionEnforcer.
- #valid_config? ⇒ Boolean
- #valid_gem_versions?(version_list:, version:) ⇒ Boolean
- #versions_behind(version_list:, version:) ⇒ Object
Constructor Details
#initialize(gem_name:, version_enforce:) ⇒ VersionEnforcer
Returns a new instance of VersionEnforcer.
13 14 15 16 |
# File 'lib/gem_enforcer/setup/helper/version_enforcer.rb', line 13 def initialize(gem_name:, version_enforce:) @gem_name = gem_name @version_enforce = version_enforce.transform_keys(&:to_sym) rescue nil end |
Instance Attribute Details
#error_validation_message ⇒ Object (readonly)
Returns the value of attribute error_validation_message.
7 8 9 |
# File 'lib/gem_enforcer/setup/helper/version_enforcer.rb', line 7 def @error_validation_message end |
#gem_name ⇒ Object (readonly)
Returns the value of attribute gem_name.
7 8 9 |
# File 'lib/gem_enforcer/setup/helper/version_enforcer.rb', line 7 def gem_name @gem_name end |
#version_enforce ⇒ Object (readonly)
Returns the value of attribute version_enforce.
7 8 9 |
# File 'lib/gem_enforcer/setup/helper/version_enforcer.rb', line 7 def version_enforce @version_enforce end |
Instance Method Details
#errors ⇒ Object
40 41 42 |
# File 'lib/gem_enforcer/setup/helper/version_enforcer.rb', line 40 def errors @errors ||= [] end |
#valid_config? ⇒ Boolean
18 19 20 |
# File 'lib/gem_enforcer/setup/helper/version_enforcer.rb', line 18 def valid_config? @valid_config ||= validate_config end |
#valid_gem_versions?(version_list:, version:) ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gem_enforcer/setup/helper/version_enforcer.rb', line 22 def valid_gem_versions?(version_list:, version:) unless valid_config? raise ConfigError, "Attempted to run validations with invalid Version Configurations" end return true if version.nil? min_to_max_version_sorted_list = version_list.sort case @version_type when :insync __validation_insync(version_list: min_to_max_version_sorted_list, version:) when :releases __validation_releases(version_list: min_to_max_version_sorted_list, version:) when :semver __validation_semver(version_list: min_to_max_version_sorted_list, version:) end end |
#versions_behind(version_list:, version:) ⇒ Object
44 45 46 |
# File 'lib/gem_enforcer/setup/helper/version_enforcer.rb', line 44 def versions_behind(version_list:, version:) version_list.sort.reverse.find_index(version) end |