class RBT::Cookbooks::CheckForNewReleaseOnRubygems

Constants

RUBYGEMS_ORG_DOWNLOADS_URL
#

RUBYGEMS_ORG_DOWNLOADS_URL

#
USE_THIS_REGEX
#

USE_THIS_REGEX

This is the main regex that will be used.

See: rubular.com/r/QcooOoIXVU

#

Public Class Methods

new( remote_url, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/check_for_updates/check_for_new_release_on_rubygems.rb, line 44
def initialize(
    remote_url,
    run_already = true
  )
  reset
  set_remote_url(
    remote_url
  )
  case remote_url
  when :dont_run_yet
    run_already = false
  end
  run if run_already
end

Public Instance Methods

apply_the_main_regex_onto_the_dataset() click to toggle source
#

apply_the_main_regex_onto_the_dataset

#
# File lib/rbt/check_for_updates/check_for_new_release_on_rubygems.rb, line 171
def apply_the_main_regex_onto_the_dataset
  @dataset =~ USE_THIS_REGEX
  @remote_program_version = $1.to_s.dup
end
check_this_remote_url(remote_url) click to toggle source
#

check_this_remote_url

#
# File lib/rbt/check_for_updates/check_for_new_release_on_rubygems.rb, line 195
def check_this_remote_url(remote_url)
  set_remote_url(remote_url)
  run
end
colourize_this_local_version(i) click to toggle source
#

colourize_this_local_version

#
# File lib/rbt/check_for_updates/check_for_new_release_on_rubygems.rb, line 121
def colourize_this_local_version(i)
  springgreen(i)
end
compare_the_remote_program_version_with_the_local_program_version() click to toggle source
#

compare_the_remote_program_version_with_the_local_program_version

#
# File lib/rbt/check_for_updates/check_for_new_release_on_rubygems.rb, line 128
def compare_the_remote_program_version_with_the_local_program_version
  reset_main_array
  program_name = File.basename(@homepage)
  local_version = action(:SanitizeCookbook, program_name) { :fast }.program_version?
  remote_program_version = ProgramInformation.new(@remote_program_version).version?
  if remote_program_version == local_version
    opne "The local program #{sfancy(program_name)} is "\
         "#{turquoise('up to date')}"\
         "! (At version: #{colourize_this_local_version(local_version)})"
  else
    # ===================================================================== #
    # We must build up the remote download-URL next.
    # ===================================================================== #
    remote_download_url =
      "#{RUBYGEMS_ORG_DOWNLOADS_URL}#{@remote_program_version}.gem"
    opne "Now updating to a new program version "\
         "at `#{sfancy(remote_download_url)}`."
    # ===================================================================== #
    # Delegate towards class UpdateEntry next.
    # ===================================================================== #
    update_entry(remote_download_url)
    @array_we_did_update_these_programs << remote_download_url
  end
  unless @array_we_did_update_these_programs.empty?
    opne "#{rev}The following "\
         "#{simp(@array_we_did_update_these_programs.size.to_s)}"\
         " #{rev}programs were updated:"
    @array_we_did_update_these_programs.each {|remote_url|
      e sfancy("  #{remote_url}")
    }
    # ===================================================================== #
    # Also store this result in a module-level instance variable next.
    # That way we can query the state of programs that were compiled.
    # ===================================================================== #
    RBT.set_array_these_ruby_gems_were_updated(
      @array_we_did_update_these_programs
    )
  end
end
identify_homepage() click to toggle source
#

identify_homepage

This method will determine the homepage of the given .gem file at hand. Keep in mind that a homepage on rubygems.org may have ‘-’ characters.

#
# File lib/rbt/check_for_updates/check_for_new_release_on_rubygems.rb, line 93
def identify_homepage
  _ = remote_url?
  if _.nil?
    opne 'An URL must be provided to this class.'
    exit
  elsif _.end_with? '.gem'
    basename = File.basename(_)
    basename = ProgramInformation.new(basename).program_name?
    basename << '/' unless basename.end_with? '/'
    @homepage = 'https://rubygems.org/gems/'+basename
    opne "Next checking for any #{crimson('updates')}"\
         " on the remote URL #{sfancy(@homepage)}"
    obtain_dataset
    apply_the_main_regex_onto_the_dataset
    compare_the_remote_program_version_with_the_local_program_version
  end
end
obtain_dataset( use_this_url = @homepage ) click to toggle source
#

obtain_dataset

The first URL to this method should be the remote homepage of the given .gem at hand.

#
# File lib/rbt/check_for_updates/check_for_new_release_on_rubygems.rb, line 182
def obtain_dataset(
    use_this_url = @homepage
  )
  begin
    @dataset = URI.open(use_this_url).read
  rescue OpenURI::HTTPError
    opne 'OpenURI::HTTPError error for `'+sfancy(use_this_url)+'`.'
  end
end
remote_url?() click to toggle source
#

remote_url?

#
# File lib/rbt/check_for_updates/check_for_new_release_on_rubygems.rb, line 82
def remote_url?
  @remote_url
end
reset() click to toggle source
#

reset

#
# File lib/rbt/check_for_updates/check_for_new_release_on_rubygems.rb, line 62
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @array_we_did_update_these_programs
  # ======================================================================= #
  @array_we_did_update_these_programs = []
end
reset_main_array() click to toggle source
#

reset_main_array

#
# File lib/rbt/check_for_updates/check_for_new_release_on_rubygems.rb, line 114
def reset_main_array
  @array_we_did_update_these_programs = []
end
run() click to toggle source
#

run

#
# File lib/rbt/check_for_updates/check_for_new_release_on_rubygems.rb, line 203
def run
  identify_homepage
end
set_remote_url(i) click to toggle source
#

set_remote_url

#
# File lib/rbt/check_for_updates/check_for_new_release_on_rubygems.rb, line 74
def set_remote_url(i)
  i = i.first if i.is_a? Array
  @remote_url = i
end