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
- #compare_version_numbers(target_version, current_version, comparator) ⇒ Object
- #condition_comparators ⇒ Object
- #gem_installed?(gem) ⇒ Boolean
- #gem_version(gem_name) ⇒ Object
- #invalid_condition_message(source_location, condition) ⇒ Object
- #valid_condition?(condition) ⇒ Boolean
- #valid_version_string?(version_string) ⇒ Boolean
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_comparators ⇒ Object
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
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 (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
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
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 |