Class: Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/runner.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_name, runfile = "~/.suprails/config") ⇒ Runner

Returns a new instance of Runner.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/runner.rb', line 31

def initialize(app_name, runfile = "~/.suprails/config")
  Runner.app_name = app_name
  @runfile = File.expand_path(runfile)
  @sources = File.expand_path('~/.suprails/sources/')
  @facets_source = File.expand_path('~/.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
        facet.go Runner.app_name
      end
    end
  end
end

Class Attribute Details

.app_nameObject

Returns the value of attribute app_name.



28
29
30
# File 'lib/runner.rb', line 28

def app_name
  @app_name
end

Instance Method Details

#debug(p = '') ⇒ Object



73
74
75
# File 'lib/runner.rb', line 73

def debug p = ''
  puts "debug: #{p}"
end

#delete(file_name) ⇒ Object



107
108
109
110
# File 'lib/runner.rb', line 107

def delete file_name
  file_name = "#{@base}/#{file_name}"
  File.delete file_name if File.exists?(file_name)
end

#file(source_file, destination) ⇒ Object



100
101
102
103
104
105
# File 'lib/runner.rb', line 100

def file source_file, destination
  require 'ftools'
  source = File.expand_path "#{@sources}/#{source_file}"
  dest = File.expand_path "./#{Runner.app_name}/#{destination}"
  File.copy(source, dest, false) if File.exists? source
end

#folder(folder_name) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/runner.rb', line 91

def folder folder_name
  path = "#{@base}/"
  paths = folder_name.split('/')
  paths.each do |p|
    path += "#{p}/"
    Dir.mkdir path if !File.exists? path
  end
end

#frozen_railsObject



69
70
71
# File 'lib/runner.rb', line 69

def frozen_rails
  `rails #{Runner.app_name} --freeze`
end

#generate(generator, *opts) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'lib/runner.rb', line 81

def generate generator, *opts
  if opts.length
    args = ''
    opts.each {|x| args += " #{x}"}
    `cd #{Runner.app_name}; script/generate #{generator} #{args}`
  else
    `cd #{Runner.app_name}; script/generate #{generator}`
  end
end

#gitObject



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/runner.rb', line 141

def git
  gem = false
  begin
    gem = require 'git'
  rescue LoadError => e
    nil
  end
  if gem
    g = Git.init(@base)
  else
    `cd #{Runner.app_name}; git init`
  end
end

#gplObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/runner.rb', line 112

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

#methodsObject



48
49
50
# File 'lib/runner.rb', line 48

def methods
  super.each{|x| puts x}
end

#plugin(plugin_location) ⇒ Object



77
78
79
# File 'lib/runner.rb', line 77

def plugin plugin_location
  `cd #{Runner.app_name}; script/plugin install #{plugin_location}`
end

#railsObject



65
66
67
# File 'lib/runner.rb', line 65

def rails
  `rails #{Runner.app_name}`
end

#rake(*opts) ⇒ Object



131
132
133
134
135
136
137
138
139
# File 'lib/runner.rb', line 131

def rake *opts
  if opts.length
    args = ''
    opts.each {|x| args += " #{x}"}
    `cd #{Runner.app_name}; rake #{args}`
  else
    `cd #{Runner.app_name}; rake`
  end
end

#runObject



52
53
54
55
56
57
58
59
# File 'lib/runner.rb', line 52

def run
  gems = Gems.new Runner.app_name
  db = DB.new Runner.app_name
  @base = File.expand_path "./#{Runner.app_name}"
  Dir.mkdir(@base)
  text = File.read(@runfile).split('\n')
  text.each {|l| instance_eval(l)}
end

#runcommand(*opts) ⇒ Object



159
160
161
162
163
164
165
166
167
168
# File 'lib/runner.rb', line 159

def runcommand *opts
  cmd = opts.shift
  if opts.length
    args = ''
    opts.each {|x| args += " #{x}"}
    `cd #{Runner.app_name}; #{cmd} #{args}`
  else
    `cd #{Runner.app_name}; #{cmd}`
  end
end

#sources(sourcefolder) ⇒ Object



61
62
63
# File 'lib/runner.rb', line 61

def sources sourcefolder
  @sources = File.expand_path "#{sourcefolder}/"
end

#svnObject



155
156
157
# File 'lib/runner.rb', line 155

def svn
  `cd #{Runner.app_name}; svnadmin create`
end