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.



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.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 |*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



75
76
77
# File 'lib/runner.rb', line 75

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, absolute = false) ⇒ Object



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

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

#folder(folder_name) ⇒ Object



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

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



71
72
73
# File 'lib/runner.rb', line 71

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

#generate(generator, *opts) ⇒ Object



83
84
85
# File 'lib/runner.rb', line 83

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

#git ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/runner.rb', line 135

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



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

#methods ⇒ Object



50
51
52
# File 'lib/runner.rb', line 50

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

#plugin(plugin_location) ⇒ Object



79
80
81
# File 'lib/runner.rb', line 79

def plugin plugin_location
  runinside("script/plugin install #{plugin_location}")
end

#rails ⇒ Object



67
68
69
# File 'lib/runner.rb', line 67

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

#rake(*opts) ⇒ Object



131
132
133
# File 'lib/runner.rb', line 131

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.expand_path "./#{Runner.app_name}"
  Dir.mkdir(@base)
  text = File.read(@runfile).split('\n')
  text.each {|l| instance_eval(l)}
end

#runinside(*opts) ⇒ Object



153
154
155
# File 'lib/runner.rb', line 153

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

#save ⇒ Object



157
158
159
# File 'lib/runner.rb', line 157

def save
  file @runfile, "doc/suprails.config", true
end

#sources(sourcefolder) ⇒ Object



63
64
65
# File 'lib/runner.rb', line 63

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

#svn ⇒ Object



149
150
151
# File 'lib/runner.rb', line 149

def svn
  runinside 'svnadmin create'
end