lib/rubygems/comparator/base.rb in gem-compare-0.0.2 vs lib/rubygems/comparator/base.rb in gem-compare-0.0.3

- old
+ new

@@ -1,69 +1,32 @@ require 'rainbow' +require 'rubygems/comparator/utils' +require 'rubygems/comparator/report' class Gem::Comparator - module Base - include Gem::UserInteraction + class Base + include Gem::Comparator::Utils + include Gem::Comparator::Report::Signs - class DiffCommandMissing < StandardError; end + attr_accessor :compares - SPACE = ' ' - DEFAULT_INDENT = SPACE*7 - OPERATORS = ['=', '!=', '>', '<', '>=', '<=', '~>'] - VERSION_REGEX = /\A(\d+\.){0,}\d+(\.[a-zA-Z]+\d{0,1}){0,1}\z/ - SHEBANG_REGEX = /\A#!.*/ - SPEC_PARAMS = %w[ author authors name platform require_paths rubygems_version summary - license licenses bindir cert_chain description email executables - extensions homepage metadata post_install_message rdoc_options - required_ruby_version required_rubygems_version requirements - signing_key has_rdoc date version ].sort - SPEC_FILES_PARAMS = %w[ files test_files extra_rdoc_files ] - DEPENDENCY_PARAMS = %w[ runtime_dependency development_dependency ] - GEMFILE_PARAMS = %w[ gemfiles ] + ## + # Compare Gem::Specification objects by default + # + # To override create your own initialize method and + # set expect(:packages) to expect Gem::Package objects. + def initialize + expect(:specs) + end + private - def param_exists?(param) - (SPEC_PARAMS.include? param) || - (SPEC_FILES_PARAMS.include? param) || - (DEPENDENCY_PARAMS.include? param) || - (GEMFILE_PARAMS.include? param) + def expect(what) + @compares = what end - def filter_params(params, param) - if param - if params.include? param - return [param] - else - return [] - end - end - - params - end - - def same - Rainbow('SAME').green.bright - end - - def different - Rainbow('DIFFERENT').red.bright - end - - def info(msg) - say msg if Gem.configuration.really_verbose - end - - def warn(msg) - say Rainbow("WARNING: #{msg}").red - end - - def error(msg) - say Rainbow("ERROR: #{msg}").red - exit 1 - end - def extract_gem(package, target_dir) gem_file = File.basename(package.spec.full_name, '.gem') gem_dir = File.join(target_dir, gem_file) if Dir.exist? gem_dir @@ -74,15 +37,7 @@ info "Unpacking gem '#{package.spec.full_name}' in " + gem_dir package.extract_files gem_dir gem_dir end - def check_diff_command_is_installed - begin - IO.popen('diff --version') - rescue Exception - raise DiffCommandMissing, \ - 'Calling `diff` command failed. Do you have it installed?' - end - end end end