Module: FreezerMode
- Included in:
- Freezer
- Defined in:
- lib/merb-freezer/freezer_mode.rb
Instance Method Summary collapse
- #create_freezer_dir(path) ⇒ Object
- #gitmodules ⇒ Object
-
#install_rubygem(gem, version = nil) ⇒ Object
Install a gem - looks remotely and locally won’t process rdoc or ri options.
-
#rubygems_freeze ⇒ Object
Uses rubygems to freeze the components locally.
-
#submodules_freeze ⇒ Object
Uses the Git submodules to freeze a component.
- #sudo ⇒ Object
- #windows? ⇒ Boolean
Instance Method Details
#create_freezer_dir(path) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/merb-freezer/freezer_mode.rb', line 94 def create_freezer_dir(path) unless File.directory?(path) puts "Creating freezer directory ..." FileUtils.mkdir_p(path) end end |
#gitmodules ⇒ Object
16 17 18 |
# File 'lib/merb-freezer/freezer_mode.rb', line 16 def gitmodules File.join(Dir.pwd, ".gitmodules") end |
#install_rubygem(gem, version = nil) ⇒ Object
Install a gem - looks remotely and locally won’t process rdoc or ri options.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/merb-freezer/freezer_mode.rb', line 69 def install_rubygem(gem, version = nil) Gem.configuration.update_sources = false Gem.clear_paths installer = Gem::DependencyInstaller.new(:install_dir => freezer_dir) exception = nil begin installer.install gem, version rescue Gem::InstallError => e exception = e rescue Gem::GemNotFoundException => e puts "Locating #{gem} in local gem path cache..." spec = version ? Gem.cache.find_name(gem, "= #{version}").first : Gem.cache.find_name(gem).sort_by { |g| g.version }.last if spec && File.exists?(gem_file = spec.installation_path / 'cache' / "#{spec.full_name}.gem") installer.install gem_file end exception = e end if installer.installed_gems.empty? && e puts "Failed to install gem '#{gem}' (#{e.message})" end installer.installed_gems.each do |spec| puts "Successfully installed #{spec.full_name}" end end |
#rubygems_freeze ⇒ Object
Uses rubygems to freeze the components locally
58 59 60 61 62 63 64 65 |
# File 'lib/merb-freezer/freezer_mode.rb', line 58 def rubygems_freeze create_freezer_dir(freezer_dir) puts "Install #{@component} and dependencies from rubygems" if File.exist?(freezer_dir) && !File.writable?("#{freezer_dir}/cache") puts "you might want to CHOWN the gems folder so it's not owned by root: sudo chown -R #{`whoami`} #{freezer_dir}" end install_rubygem @component end |
#submodules_freeze ⇒ Object
Uses the Git submodules to freeze a component
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/merb-freezer/freezer_mode.rb', line 22 def submodules_freeze # Ensure that required git commands are available %w(git).each do |bin| next if in_path?(bin) $stderr.puts "ERROR: #{bin} must be avaible in PATH - you might want to freeze using MODE=rubygems" exit 1 end # Create directory to receive the frozen components create_freezer_dir(freezer_dir) if managed?(@component) puts "#{@component} seems to be already managed by git submodule." if @update puts "Trying to update #{@component} ..." `cd #{freezer_dir}/#{@component} && git pull` else puts "you might want to call this rake task using UPDATE=true if you wish to update the frozen gems using this task" end else puts "Creating submodule for #{@component} ..." if framework_component? `cd #{Dir.pwd} & git submodule --quiet add #{Freezer.components[@component.gsub("merb-", '')]} #{File.basename(freezer_dir)}/#{@component}` else `cd #{Dir.pwd} & git submodule --quiet add #{@component} gems/submodules/#{component_name}` end if $?.success? `git submodule init` else # Should this instead be a raise? $stderr.puts("ERROR: unable to create submodule for #{@component} - you might want to freeze using MODE=rubygems (make sure the current project has a git repository)") end end end |
#sudo ⇒ Object
7 8 9 10 |
# File 'lib/merb-freezer/freezer_mode.rb', line 7 def sudo ENV['MERB_SUDO'] ||= "sudo" sudo = windows? ? "" : ENV['MERB_SUDO'] end |
#windows? ⇒ Boolean
12 13 14 |
# File 'lib/merb-freezer/freezer_mode.rb', line 12 def windows? (PLATFORM =~ /win32|cygwin/) rescue nil end |