Class: Runner
- Inherits:
-
Object
- Object
- Runner
- Defined in:
- lib/runner.rb
Class Attribute Summary collapse
-
.app_name ⇒ Object
Returns the value of attribute app_name.
Instance Method Summary collapse
- #debug(p = '') ⇒ Object
- #delete(file_name) ⇒ Object
- #file(source_file, destination, absolute = false) ⇒ Object
- #folder(folder_name) ⇒ Object
- #frozen_rails ⇒ Object
- #generate(generator, *opts) ⇒ Object
- #git ⇒ Object
- #gpl ⇒ Object
-
#initialize(app_name, runfile = "~/.suprails/config") ⇒ Runner
constructor
A new instance of Runner.
- #methods ⇒ Object
- #new_file(filename, contents) ⇒ Object
- #plugin(plugin_location) ⇒ Object
- #rails ⇒ Object
- #rake(*opts) ⇒ Object
- #run ⇒ Object
- #runinside(*opts) ⇒ Object
- #save ⇒ Object
- #sources(sourcefolder) ⇒ Object
- #svn ⇒ Object
Constructor Details
#initialize(app_name, runfile = "~/.suprails/config") ⇒ Runner
Returns a new instance of Runner.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/runner.rb', line 32 def initialize(app_name, runfile = "~/.suprails/config") Runner.app_name = app_name @runfile = File.(runfile) @sources = File.('~/.suprails/sources/') @facets_source = File.('~/.suprails/facets/') Dir["#{@facets_source}/*.rb"].each{|x| load x } Facet.registered_facets.each do |name, facet| self.class.send(:define_method, name) {} instance_eval do self.class.send(:define_method, name) do |*args| args.unshift(Runner.app_name) facet.go *args end end end end |
Class Attribute Details
.app_name ⇒ Object
Returns the value of attribute app_name.
29 30 31 |
# File 'lib/runner.rb', line 29 def app_name @app_name end |
Instance Method Details
#debug(p = '') ⇒ Object
76 77 78 |
# File 'lib/runner.rb', line 76 def debug p = '' puts "debug: #{p}" end |
#delete(file_name) ⇒ Object
109 110 111 112 113 |
# File 'lib/runner.rb', line 109 def delete file_name file_name = "#{@base}/#{file_name}" puts "Deleting: #{@file_name}" File.delete file_name if File.exists?(file_name) end |
#file(source_file, destination, absolute = false) ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/runner.rb', line 98 def file source_file, destination, absolute = false require 'ftools' if absolute source = File. "#{source_file}" else source = File. "#{@sources}/#{source_file}" end dest = File. "./#{Runner.app_name}/#{destination}" File.copy(source, dest, true) if File.exists? source end |
#folder(folder_name) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/runner.rb', line 88 def folder folder_name path = "#{@base}/" puts "New folder: #{@base}" paths = folder_name.split('/') paths.each do |p| path += "#{p}/" Dir.mkdir path if !File.exists? path end end |
#frozen_rails ⇒ Object
72 73 74 |
# File 'lib/runner.rb', line 72 def frozen_rails shell "rails #{Runner.app_name} --freeze" end |
#generate(generator, *opts) ⇒ Object
84 85 86 |
# File 'lib/runner.rb', line 84 def generate generator, *opts runinside("script/generate #{generator} #{opts.join(' ')}") end |
#git ⇒ Object
138 139 140 |
# File 'lib/runner.rb', line 138 def git runinside('git init') end |
#gpl ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/runner.rb', line 115 def gpl puts 'Installing the GPL into COPYING' require 'net/http' http = Net::HTTP.new('www.gnu.org') path = '/licenses/gpl-3.0.txt' begin resp = http.get(path) if resp.code == '200' File.open("#{@base}/COPYING", 'w') do |f| f.puts(resp.body) end else puts "Error #{resp.code} while retrieving GPL text." end rescue SocketError puts 'SocketError: You might not be connected to the internet. GPL retrieval failed.' end end |
#methods ⇒ Object
50 51 52 |
# File 'lib/runner.rb', line 50 def methods super.each{|x| puts x} end |
#new_file(filename, contents) ⇒ Object
154 155 156 157 158 159 |
# File 'lib/runner.rb', line 154 def new_file filename, contents File.open(File.("./#{Runner.app_name}/#{filename}"), 'w') do |f| f.puts contents end puts "Generating file: #{filename}" end |
#plugin(plugin_location) ⇒ Object
80 81 82 |
# File 'lib/runner.rb', line 80 def plugin plugin_location runinside("script/plugin install #{plugin_location}") end |
#rails ⇒ Object
68 69 70 |
# File 'lib/runner.rb', line 68 def rails shell "rails #{Runner.app_name}" end |
#rake(*opts) ⇒ Object
134 135 136 |
# File 'lib/runner.rb', line 134 def rake *opts runinside("rake #{opts.join(' ')}") end |
#run ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/runner.rb', line 54 def run gems = Gems.new Runner.app_name db = DB.new Runner.app_name @base = File. "./#{Runner.app_name}" Dir.mkdir(@base) text = File.read(@runfile) instance_eval(text) end |
#runinside(*opts) ⇒ Object
146 147 148 |
# File 'lib/runner.rb', line 146 def runinside *opts shell "cd #{Runner.app_name}; #{opts.join(' ')}" end |
#save ⇒ Object
150 151 152 |
# File 'lib/runner.rb', line 150 def save file @runfile, "doc/suprails.config", true end |
#sources(sourcefolder) ⇒ Object
63 64 65 66 |
# File 'lib/runner.rb', line 63 def sources sourcefolder @sources = File. "#{sourcefolder}/" puts "Using #{@sources} for file sources" end |
#svn ⇒ Object
142 143 144 |
# File 'lib/runner.rb', line 142 def svn runinside('svnadmin create') end |