Sha256: 5d892bfe29fa075759f346d3898d0dab0c4dced7d8a606b51f83c0e2d0af1979
Contents?: true
Size: 1.93 KB
Versions: 2
Compression:
Stored size: 1.93 KB
Contents
require 'pathname' require 'fileutils' require 'tempfile' include FileUtils module Venomi module Generators module Utils module InstanceMethods @@gemfile_path = "#{Rails.root.to_s}/Gemfile" def yes_no(question) isValid = true question += " [Y/N] " while isValid answer = ask(question, :yellow) do |yn| yn.limit = 1, yn.validate = /[yn]/i end answer.downcase! isValid = (answer == "y" or answer == "n")? false : true end answer end def library_available?(gem_name) begin require gem_name return true rescue LoadError return false end end def libraries_available?(*gems) isAvailable = true gems.each do |gem| return false unless library_available?(gem) end isAvailable end def file?(path) File.exist?(path) end def install_gem(gem_name, version = nil) gem = "gem '" + gem_configurename + "'" gem += ( ", '~> " + version +"'") if version unless file_include?(@@gemfile_path, gem) open(@@gemfile_path, 'a') { |f| f.puts gem } end system 'bundle install' end def replace(path, pattern, new_line) t_file = Tempfile.new('temp.rb') File.open(path, 'r') do |f| f.each_line do |line| t_file.puts (line.include? pattern)? new_line : line end end t_file.close FileUtils.mv(t_file.path, path) end def file_include?(path, include) File.open(path, 'r') do |f| f.each_line do |line| return true if line.include? include end end false end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
venomi-0.0.3 | lib/generators/utils.rb |
venomi-0.0.2 | lib/generators/utils.rb |