Class: OffGithub::GemInvestigator

Inherits:
Object
  • Object
show all
Defined in:
lib/off_github.rb

Instance Method Summary collapse

Constructor Details

#initialize(local = GemList.new, other = GemList.new(GEMCUTTER_URL), github = GemList.new(GITHUB_URL)) ⇒ GemInvestigator

Returns a new instance of GemInvestigator.



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/off_github.rb', line 68

def initialize( local = GemList.new, 
                other = GemList.new(GEMCUTTER_URL),
                github = GemList.new(GITHUB_URL))
  @github = github.list
  @github_gems = github.gems
  @github_url = github.source
  @other = other.list
  @other_gems = other.gems
  @other_url = other.source
  @local = local.list
  @local_gems = local.gems
end

Instance Method Details

#found_matchesObject



85
86
87
# File 'lib/off_github.rb', line 85

def found_matches
  @found_matches ||= github_suspects.map{|name| find_match(name)}
end

#github_suspectsObject



81
82
83
# File 'lib/off_github.rb', line 81

def github_suspects
  @github_suspects ||= @local.select{|name| looks_like_github_gem?(name)}
end

#relationsObject



89
90
91
# File 'lib/off_github.rb', line 89

def relations
  @relations ||= Hash[*github_suspects.map.zip(found_matches).flatten]
end

#statsObject Also known as: to_s



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/off_github.rb', line 129

def stats
  "\nGitHub gems found on \#{GEMCUTTER_URL} (will be reinstalled):\n\#{Hirb::Helpers::AutoTable.render will_be_migrated_with_versions, :headers => [GITHUB_URL, GEMCUTTER_URL, \"action\"]}\n\nreinstall = Everything ok. Gemcutter has same/newer version, which will replace installed github version.\nskip = Gemcutter doesn't yet have a version that you need, only older. Not touching anything. Run this again later.\nuninstall = The non-github version is already installed. Only removing github version.\n\nGitHub gems not found on \#{GEMCUTTER_URL} (won't be touched):\n\n\#{will_not_be_migrated.join(\"\\n\")}\n\n  STATS\nend\n"

#will_be_migratedObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/off_github.rb', line 93

def will_be_migrated
  return @will_be_migrated if @will_be_migrated
  
  targets = relations.select{|k, v| v}
  @will_be_migrated = targets.map do |names|
    gh_name, gc_name = names
    local_gh_versions = @local_gems[gh_name]
    local_gc_versions = @local_gems[gc_name]
    gh_versions = @github_gems[gh_name]
    gc_versions = @other_gems[gc_name]
    
    action = if @local.include?(gc_name) && !newer_version?(local_gh_versions.first, gc_versions.first)
      "uninstall"
    elsif !newer_version?(gc_versions.first, local_gh_versions.first)
      "skip"
    else
      "reinstall"
    end
    
    [gh_name, gc_name, action]
  end.sort{|a,b| a[2] <=> b[2]}
end

#will_be_migrated_with_versionsObject



116
117
118
119
120
121
122
123
# File 'lib/off_github.rb', line 116

def will_be_migrated_with_versions
  @will_be_migrated_with_versions ||= will_be_migrated.map do |rows|
    gh_name, gc_name, action = rows
    [gh_name + " (#{@local_gems[gh_name].join(', ')})", 
     gc_name + " (#{@other_gems[gc_name].join(', ')})",
     action]
  end
end

#will_not_be_migratedObject



125
126
127
# File 'lib/off_github.rb', line 125

def will_not_be_migrated
  @will_not_be_migrated ||= Hash[*relations.select{|k, v| !v}.flatten].keys
end