Module: RemindMe::Utils::Versions

Included in:
Reminder::GemVersionReminder, Reminder::MissingGemReminder, Reminder::RubyVersionReminder, Runner
Defined in:
lib/remind_me/utils/versions.rb

Constant Summary collapse

INSTALLED_GEMS =
Gem::Specification.map { |a| [a.name, a.version] }.to_h

Instance Method Summary collapse

Instance Method Details

#compare_version_numbers(target_version, current_version, comparator) ⇒ Object



9
10
11
# File 'lib/remind_me/utils/versions.rb', line 9

def compare_version_numbers(target_version, current_version, comparator)
  current_version.__send__(condition_comparators[comparator.to_sym], target_version)
end

#condition_comparatorsObject



25
26
27
# File 'lib/remind_me/utils/versions.rb', line 25

def condition_comparators
  %i[lt lte gt gte eq].zip(%i[< <= > >= ==]).to_h
end

#gem_installed?(gem) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/remind_me/utils/versions.rb', line 17

def gem_installed?(gem)
  INSTALLED_GEMS.key?(gem.to_s)
end

#gem_version(gem_name) ⇒ Object



13
14
15
# File 'lib/remind_me/utils/versions.rb', line 13

def gem_version(gem_name)
  INSTALLED_GEMS[gem_name]
end

#invalid_condition_message(source_location, condition) ⇒ Object



36
37
38
39
# File 'lib/remind_me/utils/versions.rb', line 36

def invalid_condition_message(source_location, condition)
  "REMIND_ME comment on #{source_location} has invalid condition: #{condition}, only "\
  'lt, lte, gt, gte, eq are possible, or you can omit it entirely (it will default to eq)'
end

#valid_condition?(condition) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/remind_me/utils/versions.rb', line 21

def valid_condition?(condition)
  condition_comparators.keys.flat_map { |x| [x, x.to_s] }.include?(condition)
end

#valid_version_string?(version_string) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/remind_me/utils/versions.rb', line 29

def valid_version_string?(version_string)
  Gem::Version.new(version_string)
  true
rescue ArgumentError => _e
  false
end