Module: Odin
- Included in:
- Starter
- Defined in:
- lib/r4/odin.rb
Instance Method Summary collapse
- #bundle(task = '') ⇒ Object
- #concat(filename, part) ⇒ Object
- #content(filename) ⇒ Object
- #cp(from, to) ⇒ Object
- #cp_template(template_dir, path) ⇒ Object
- #file(filename, content) ⇒ Object
- #git(task) ⇒ Object
- #gsub(filename, options = {}, &block) ⇒ Object
- #rails(task) ⇒ Object
- #rake(task) ⇒ Object
- #rm(what) ⇒ Object
- #sub(filename, mark, part, options = {}) ⇒ Object
Instance Method Details
#bundle(task = '') ⇒ Object
71 72 73 |
# File 'lib/r4/odin.rb', line 71 def bundle task='' system "bundle #{task}" end |
#concat(filename, part) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/r4/odin.rb', line 35 def concat filename, part File.open(filename) do |f| content = f.read file filename, content + part end end |
#content(filename) ⇒ Object
31 32 33 |
# File 'lib/r4/odin.rb', line 31 def content filename File.open(filename).read end |
#cp(from, to) ⇒ Object
48 49 50 |
# File 'lib/r4/odin.rb', line 48 def cp from, to system "cp #{from} #{to}" end |
#cp_template(template_dir, path) ⇒ Object
55 56 57 |
# File 'lib/r4/odin.rb', line 55 def cp_template template_dir, path cp "#{template_dir}/#{path}", path end |
#file(filename, content) ⇒ Object
42 43 44 45 46 |
# File 'lib/r4/odin.rb', line 42 def file filename, content File.open(filename, 'w') do |f| f.write content end end |
#git(task) ⇒ Object
67 68 69 |
# File 'lib/r4/odin.rb', line 67 def git task system "git #{task}" end |
#gsub(filename, options = {}, &block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/r4/odin.rb', line 3 def gsub filename, ={}, &block puts [:log] if [:log] fr = File.new(filename) content = fr.read fr.close change = content.clone block.call change unless content==change fw = File.new filename, 'w' fw.write change fw.close end end |
#rails(task) ⇒ Object
63 64 65 |
# File 'lib/r4/odin.rb', line 63 def rails task system "rails #{task}" end |
#rake(task) ⇒ Object
59 60 61 |
# File 'lib/r4/odin.rb', line 59 def rake task system "rake #{task}" end |
#rm(what) ⇒ Object
51 52 53 |
# File 'lib/r4/odin.rb', line 51 def rm what system "rm #{what}" end |
#sub(filename, mark, part, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/r4/odin.rb', line 17 def sub filename, mark, part, ={} File.open(filename) do |f| content = f.read if [:global] change = content.gsub mark, part else change = content.sub mark, part end unless change==content file filename, change end end end |