Sha256: 6e1cfd81c49a612f21b8a59ea988e8487e7984477c2294a0c40689b1daf5f30f
Contents?: true
Size: 1.35 KB
Versions: 1
Compression:
Stored size: 1.35 KB
Contents
require 'erb' module Penchant class Gemfile attr_reader :path class << self def do_full_env_switch!(env) gemfile = Penchant::Gemfile.new gemfile.run_dot_penchant!(env) if !gemfile.has_gemfile_erb? return false end gemfile.switch_to!(env) end end def initialize(path = Dir.pwd) @path = path end def gemfile_path file_in_path('Gemfile') end def has_gemfile? File.file?('Gemfile') end def has_dot_penchant? File.file?('.penchant') end def gemfile_erb_path file_in_path('Gemfile.erb') end def has_gemfile_erb? File.file?(gemfile_erb_path) end def environment File.readlines(gemfile_path).first.strip[%r{environment: (.*)}, 1] end def switch_to!(gemfile_env = nil) @env = gemfile_env template = File.read(gemfile_erb_path) File.open(gemfile_path, 'wb') do |fh| fh.puts "# generated by penchant, environment: #{@env}" fh.print ERB.new(template).result(binding) end end def run_dot_penchant!(env) DotPenchant.run(env || environment) if has_dot_penchant? end private def file_in_path(file) File.join(@path, file) end def env(check, &block) instance_eval(&block) if check.to_s == @env.to_s end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
penchant-0.0.3 | lib/penchant/gemfile.rb |