Module: Rip::Env
Instance Method Summary collapse
- #active ⇒ Object
- #active_dir ⇒ Object
-
#call(meth, *args) ⇒ Object
for being lazy about what we have vs what we want.
- #commands ⇒ Object
- #copy(new) ⇒ Object
- #create(env) ⇒ Object
- #delete(env) ⇒ Object
- #list(env = nil) ⇒ Object
- #ui ⇒ Object
- #use(env) ⇒ Object
Instance Method Details
#active ⇒ Object
76 77 78 79 |
# File 'lib/rip/env.rb', line 76 def active active = File.readlink(active_dir) active.split('/').last end |
#active_dir ⇒ Object
120 121 122 |
# File 'lib/rip/env.rb', line 120 def active_dir File.join(Rip.dir, 'active') end |
#call(meth, *args) ⇒ Object
for being lazy about what we have vs what we want. enables javascript-style method calling where the number of arguments doesn’t need to match the arity
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/rip/env.rb', line 108 def call(meth, *args) arity = method(meth).arity.abs if arity == args.size send(meth, *args) elsif arity == 0 send(meth) else send(meth, args[0, arity]) end end |
#commands ⇒ Object
5 6 7 |
# File 'lib/rip/env.rb', line 5 def commands instance_methods - %w( call active_dir commands ui ) end |
#copy(new) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/rip/env.rb', line 81 def copy(new) if new.strip.empty? return "must give a ripenv to copy to" end dest = File.join(Rip.dir, new) src = Rip::Env.active_dir env = Rip::Env.active if File.exists?(dest) return "#{new} exists" end FileUtils.cp_r src, dest if File.exists? ripfile = File.join(dest, "#{env}.ripenv") FileUtils.cp ripfile, File.join(dest, "#{new}.ripenv") end use new "cloned #{env} to #{new}" end |
#create(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rip/env.rb', line 9 def create(env) dir = File.join(Rip.dir, env) if env.strip.empty? return "must give a ripenv to create" end if File.exists? dir "#{env} exists" else FileUtils.mkdir_p File.join(dir, 'bin') FileUtils.mkdir_p File.join(dir, 'lib') use env "created #{env}" end end |
#delete(env) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rip/env.rb', line 45 def delete(env) if active == env return "can't delete active environment" end if env.strip.empty? return "must give a ripenv to delete" end if File.exists?(target = File.join(Rip.dir, env)) FileUtils.rm_rf target "deleted #{env}" else "can't find #{env}" end end |
#list(env = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rip/env.rb', line 62 def list(env = nil) envs = Dir.glob(File.join(Rip.dir, '*')).map do |env| env.split('/').last end envs.reject! { |env| env =~ /^(rip-|active)/ } if envs.empty? "none. make one with `rip env create <env>`" else envs.join(' ') end end |
#use(env) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rip/env.rb', line 27 def use(env) if env.strip.empty? return "must give a ripenv to use" end if !File.exists?(target = File.join(Rip.dir, env)) return "#{env} doesn't exist" end begin FileUtils.rm active_dir rescue Errno::ENOENT end FileUtils.ln_s(target, active_dir) "using #{env}" end |