class RvmPow::Pow

Public Instance Methods

addRvmInfoToGemfile() click to toggle source

add rvm ruby and gemset to Gemfile

# File lib/rvmpow.rb, line 50
def addRvmInfoToGemfile
        action = -> do
                rvm = rvmInfo
                File.open(RvmPow::GEMFILE, 'a+') do |file|
                        s = file.read
                        if (s.match(/ruby\s'\d(\.\d)+'/) || s.match(/ruby-gemset=/))
                                puts "\truby or gemset information already present in Gemfile"
                        else
                                file.puts "\n# rvmpow\nruby '#{rvm[:ruby]}'\n#ruby-gemset=#{rvm[:gemset]}"
                        end
                end
        end
        fileAction action
end
createPowenvFile() click to toggle source

create .poenv in current dirrectory

# File lib/rvmpow.rb, line 10
def createPowenvFile
        action = -> do
                File.open(RvmPow::POW_ENV_FILE, "w+") { |file| file.puts RvmPow::POWENV  }
        end
        fileAction action
end
deleteAlwaysRestartFile() click to toggle source

removes always_restart.txt file from ./tmp/

# File lib/rvmpow.rb, line 99
def deleteAlwaysRestartFile
        action = -> { FileUtils.rm_f RvmPow::ALWAYS_RESTART_FILE }
        fileAction action
end
deletePowenvFile() click to toggle source

removes .powenv

# File lib/rvmpow.rb, line 87
def deletePowenvFile
        action = -> { FileUtils.rm_f RvmPow::POW_ENV_FILE }
        fileAction action
end
deleteRestartFile() click to toggle source

removes restart.txt file from ./tmp/

# File lib/rvmpow.rb, line 93
def deleteRestartFile
        action = -> { FileUtils.rm_f RvmPow::RESTART_FILE }
        fileAction action
end
gitignorePowenv() click to toggle source

add .powenv to .gitignore

# File lib/rvmpow.rb, line 42
def gitignorePowenv
        action = -> do
                File.open(RvmPow::GITIGNORE_FILE, 'a') { |file| file.puts RvmPow::GITIGNORE_ENTRY }
        end
        fileAction action
end
restoreGemfile() click to toggle source

removes rvmpow entries from Gemfile

# File lib/rvmpow.rb, line 72
def restoreGemfile
        action = -> do
                File.open(RvmPow::GEMFILE, 'r') do |file|
                        s = file.read
                        if !(s.match(/^#\srvmpow$/))
                                puts "\tNo rvmpow entry found, continuing ..."
                        else
                                removeFromFile(RvmPow::GEMFILE, RvmPow::GEMFILE_MATCHER)
                        end
                end
        end
        fileAction action
end
restoreGitignore() click to toggle source

removes rvmpow entries from .gitignore

# File lib/rvmpow.rb, line 66
def restoreGitignore
        action = -> { removeFromFile(RvmPow::GITIGNORE_FILE, RvmPow::GITIGNORE_MATCHER) }
        fileAction action
end
touchAlwaysRestartFile() click to toggle source

create tmp/always_restart.txt file

# File lib/rvmpow.rb, line 33
def touchAlwaysRestartFile
        action = -> do
                createTmpDirIfNeeded
                FileUtils.touch(RvmPow::ALWAYS_RESTART_FILE)
        end
        fileAction action
end
touchRestartFile() click to toggle source

create tmp/restart.txt file

# File lib/rvmpow.rb, line 24
def touchRestartFile
        action = -> do
                createTmpDirIfNeeded
                FileUtils.touch(RvmPow::RESTART_FILE)
        end
        fileAction action
end

Private Instance Methods

createTmpDirIfNeeded() click to toggle source
# File lib/rvmpow.rb, line 158
def createTmpDirIfNeeded
        FileUtils.mkdir('tmp') if !File.exist?('tmp')
end
fileAction(action) click to toggle source

file action wrapper

# File lib/rvmpow.rb, line 113
def fileAction(action)
        action.call
        true
rescue Exception => err
        puts err.message
        false
end
removeFromFile(file, regex) click to toggle source

removes text from file based on regex

# File lib/rvmpow.rb, line 122
def removeFromFile(file, regex)
        # create tempfile
        tmp = Tempfile.new "foo"

        # Read file
        confFile = File.read(file)
        confFile.gsub!(regex, '').chomp!

        tmp.write confFile
        tmp.close

        FileUtils.mv(tmp.path, file)
        true
rescue Exception => e
        puts e.message
        false
end
rvmInfo() click to toggle source

returns a hash with the ruby and gemset information @return [Hash]

# File lib/rvmpow.rb, line 142
def rvmInfo
        rvm = {}

        rg = `rvm-prompt`
        if !rg.include?('@')
                rvm[:ruby] = rg.chomp.split('-')[1]
                rvm[:gemset] = ''
        else
                rvmArray = rg.chomp.split('@')
                rvm[:ruby] = rvmArray[0].split('-')[1]
                rvm[:gemset] = rvmArray[1]
        end

        rvm
end