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_name ⇒ Object

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



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

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

#file(source_file, destination) ⇒ Object



94
95
96
97
98
99
# File 'lib/runner.rb', line 94

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



85
86
87
88
89
90
91
92
# File 'lib/runner.rb', line 85

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_rails ⇒ Object



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
# File 'lib/runner.rb', line 81

def generate generator, *opts
  runinside("script/generate #{generator} #{opts.join(' ')}")
end

#git ⇒ Object



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

def git
  gem = false
  begin
    gem = require 'git'
  rescue LoadError => e
    nil
  end
  if gem
    g = Git.init(@base)
  else
    runinside 'git init'
  end
end

#gpl ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/runner.rb', line 106

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



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
  runinside("script/plugin install #{plugin_location}")
end

#rails ⇒ Object



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

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

#rake(*opts) ⇒ Object



125
126
127
# File 'lib/runner.rb', line 125

def rake *opts
  runinside("rake #{opts.join(' ')}")
end

#run ⇒ Object



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

#runinside(*opts) ⇒ Object



147
148
149
# File 'lib/runner.rb', line 147

def runinside *opts
  shell "cd #{Runner.app_name}; #{opts.join(' ')}"
end

#sources(sourcefolder) ⇒ Object



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

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

#svn ⇒ Object



143
144
145
# File 'lib/runner.rb', line 143

def svn
  runinside 'svnadmin create'
end