Class: Rcr::GemSync
- Inherits:
-
Object
- Object
- Rcr::GemSync
- Defined in:
- lib/rcr/gem_sync.rb
Constant Summary collapse
- GITHUB =
"http://gems.github.com"- RCR_DEFAULT_GEM_LIST =
File.(File.join(File.dirname(__FILE__), *%w[.. runcoderun_gems.txt]))
- RCR_GITHUB_GEM_LIST =
"http://github.com/runcoderun/gem_sync/raw/master/lib/runcoderun_gems.txt"- RCR_GITHUB_GEM_BLACKLIST =
"http://github.com/runcoderun/gem_sync/raw/master/lib/gem_blacklist.txt"
Instance Attribute Summary collapse
-
#gem_list ⇒ Object
readonly
Returns the value of attribute gem_list.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
Instance Method Summary collapse
- #dry_run? ⇒ Boolean
- #gem_installed?(name) ⇒ Boolean
- #gem_version_installed?(version) ⇒ Boolean
-
#initialize(args = ["--github"]) ⇒ GemSync
constructor
A new instance of GemSync.
- #install!(rubygem) ⇒ Object
- #install_from_github(rubygem) ⇒ Object
- #install_from_rubyforge(rubygem) ⇒ Object
- #install_gems ⇒ Object
- #installed?(requested) ⇒ Boolean
- #installed_gems ⇒ Object
- #parse_gems ⇒ Object
- #platform_matches?(gem) ⇒ Boolean
- #read_gem_list ⇒ Object
- #run(cmd) ⇒ Object
- #sync ⇒ Object
- #verbose? ⇒ Boolean
- #verbose_gem? ⇒ Boolean
Constructor Details
#initialize(args = ["--github"]) ⇒ GemSync
Returns a new instance of GemSync.
14 15 16 17 18 19 |
# File 'lib/rcr/gem_sync.rb', line 14 def initialize(args = ["--github"]) = Rcr::OptionParsing.parse(args) @platform = [:platform] @gem_list = [:gem_list] system("gem env") if verbose? end |
Instance Attribute Details
#gem_list ⇒ Object (readonly)
Returns the value of attribute gem_list.
12 13 14 |
# File 'lib/rcr/gem_sync.rb', line 12 def gem_list @gem_list end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
12 13 14 |
# File 'lib/rcr/gem_sync.rb', line 12 def platform @platform end |
Instance Method Details
#dry_run? ⇒ Boolean
35 36 37 |
# File 'lib/rcr/gem_sync.rb', line 35 def dry_run? [:dry_run] end |
#gem_installed?(name) ⇒ Boolean
65 66 67 |
# File 'lib/rcr/gem_sync.rb', line 65 def gem_installed?(name) installed_gems.any? { |installed| installed.name == name } end |
#gem_version_installed?(version) ⇒ Boolean
69 70 71 72 |
# File 'lib/rcr/gem_sync.rb', line 69 def gem_version_installed?(version) return true if version.nil? installed_gems.any? { |installed| installed.version == version } end |
#install!(rubygem) ⇒ Object
59 60 61 62 63 |
# File 'lib/rcr/gem_sync.rb', line 59 def install!(rubygem) return unless platform_matches?(rubygem) return if installed?(rubygem) install_from_rubyforge(rubygem) || install_from_github(rubygem) end |
#install_from_github(rubygem) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/rcr/gem_sync.rb', line 89 def install_from_github(rubygem) return unless rubygem.name.include?("-") cmd = "gem install #{rubygem.name} --no-ri --no-rdoc" cmd << " --version #{rubygem.version}" if rubygem.version cmd << " --verbose" if verbose_gem? cmd << " --source #{GITHUB}" run(cmd) end |
#install_from_rubyforge(rubygem) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/rcr/gem_sync.rb', line 82 def install_from_rubyforge(rubygem) cmd = "gem install #{rubygem.name} --no-ri --no-rdoc" cmd << " --version #{rubygem.version}" if rubygem.version cmd << " --verbose" if verbose_gem? run(cmd) end |
#install_gems ⇒ Object
55 56 57 |
# File 'lib/rcr/gem_sync.rb', line 55 def install_gems @gems.each { |rubygem| install!(rubygem) } end |
#installed?(requested) ⇒ Boolean
74 75 76 |
# File 'lib/rcr/gem_sync.rb', line 74 def installed?(requested) gem_installed?(requested.name) && gem_version_installed?(requested.version) end |
#installed_gems ⇒ Object
78 79 80 |
# File 'lib/rcr/gem_sync.rb', line 78 def installed_gems @installed_gems ||= Rcr::GemParser.convert_gem_list(`gem list`) end |
#parse_gems ⇒ Object
51 52 53 |
# File 'lib/rcr/gem_sync.rb', line 51 def parse_gems @gems = Rcr::GemParser.convert_gem_list(gem_list) end |
#platform_matches?(gem) ⇒ Boolean
43 44 45 46 47 48 49 |
# File 'lib/rcr/gem_sync.rb', line 43 def platform_matches?(gem) if gem.platforms && platform gem.platforms.include?(platform) else true end end |
#read_gem_list ⇒ Object
39 40 41 |
# File 'lib/rcr/gem_sync.rb', line 39 def read_gem_list open(@gem_list).read end |
#run(cmd) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/rcr/gem_sync.rb', line 98 def run(cmd) if dry_run? puts cmd true else puts cmd if verbose? system(cmd) end end |
#sync ⇒ Object
21 22 23 24 25 |
# File 'lib/rcr/gem_sync.rb', line 21 def sync @gem_list = read_gem_list @gems = parse_gems install_gems end |
#verbose? ⇒ Boolean
27 28 29 |
# File 'lib/rcr/gem_sync.rb', line 27 def verbose? [:verbose] end |
#verbose_gem? ⇒ Boolean
31 32 33 |
# File 'lib/rcr/gem_sync.rb', line 31 def verbose_gem? [:verbose_gem] end |