lightrail 0.0.1 → 0.99.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/.gitignore +7 -0
  2. data/.rspec +4 -0
  3. data/.travis.yml +11 -0
  4. data/CHANGES.md +8 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +19 -0
  7. data/README.md +205 -0
  8. data/Rakefile +5 -0
  9. data/bin/lightrail +2 -1
  10. data/lib/lightrail.rb +2 -0
  11. data/lib/lightrail/action_controller/metal.rb +0 -2
  12. data/lib/lightrail/cli.rb +16 -0
  13. data/lib/lightrail/commands/application.rb +26 -0
  14. data/lib/lightrail/generators.rb +323 -0
  15. data/lib/lightrail/generators/app_base.rb +281 -0
  16. data/lib/lightrail/generators/app_generator.rb +299 -0
  17. data/lib/lightrail/generators/base.rb +378 -0
  18. data/lib/lightrail/generators/templates/Gemfile +25 -0
  19. data/lib/lightrail/generators/templates/README +259 -0
  20. data/lib/lightrail/generators/templates/Rakefile +7 -0
  21. data/lib/lightrail/generators/templates/app/assets/images/rails.png +0 -0
  22. data/lib/lightrail/generators/templates/app/assets/javascripts/application.js.tt +17 -0
  23. data/lib/lightrail/generators/templates/app/assets/stylesheets/application.css +13 -0
  24. data/lib/lightrail/generators/templates/app/controllers/application_controller.rb +3 -0
  25. data/lib/lightrail/generators/templates/app/helpers/application_helper.rb +2 -0
  26. data/lib/lightrail/generators/templates/app/mailers/.empty_directory +0 -0
  27. data/lib/lightrail/generators/templates/app/models/.empty_directory +0 -0
  28. data/lib/lightrail/generators/templates/app/views/layouts/application.html.erb.tt +14 -0
  29. data/lib/lightrail/generators/templates/config.ru +4 -0
  30. data/lib/lightrail/generators/templates/config/application.rb +67 -0
  31. data/lib/lightrail/generators/templates/config/boot.rb +6 -0
  32. data/lib/lightrail/generators/templates/config/databases/frontbase.yml +31 -0
  33. data/lib/lightrail/generators/templates/config/databases/ibm_db.yml +86 -0
  34. data/lib/lightrail/generators/templates/config/databases/jdbc.yml +62 -0
  35. data/lib/lightrail/generators/templates/config/databases/jdbcmysql.yml +33 -0
  36. data/lib/lightrail/generators/templates/config/databases/jdbcpostgresql.yml +43 -0
  37. data/lib/lightrail/generators/templates/config/databases/jdbcsqlite3.yml +20 -0
  38. data/lib/lightrail/generators/templates/config/databases/mysql.yml +51 -0
  39. data/lib/lightrail/generators/templates/config/databases/oracle.yml +39 -0
  40. data/lib/lightrail/generators/templates/config/databases/postgresql.yml +55 -0
  41. data/lib/lightrail/generators/templates/config/databases/sqlite3.yml +25 -0
  42. data/lib/lightrail/generators/templates/config/environment.rb +5 -0
  43. data/lib/lightrail/generators/templates/config/environments/development.rb.tt +38 -0
  44. data/lib/lightrail/generators/templates/config/environments/production.rb.tt +76 -0
  45. data/lib/lightrail/generators/templates/config/environments/test.rb.tt +36 -0
  46. data/lib/lightrail/generators/templates/config/initializers/backtrace_silencers.rb +7 -0
  47. data/lib/lightrail/generators/templates/config/initializers/inflections.rb +15 -0
  48. data/lib/lightrail/generators/templates/config/initializers/mime_types.rb +5 -0
  49. data/lib/lightrail/generators/templates/config/initializers/secret_token.rb.tt +7 -0
  50. data/lib/lightrail/generators/templates/config/initializers/session_store.rb.tt +8 -0
  51. data/lib/lightrail/generators/templates/config/initializers/wrap_parameters.rb.tt +16 -0
  52. data/lib/lightrail/generators/templates/config/locales/en.yml +5 -0
  53. data/lib/lightrail/generators/templates/config/routes.rb +58 -0
  54. data/lib/lightrail/generators/templates/db/seeds.rb.tt +7 -0
  55. data/lib/lightrail/generators/templates/gitignore +16 -0
  56. data/lib/lightrail/generators/templates/public/404.html +26 -0
  57. data/lib/lightrail/generators/templates/public/422.html +26 -0
  58. data/lib/lightrail/generators/templates/public/500.html +25 -0
  59. data/lib/lightrail/generators/templates/public/favicon.ico +0 -0
  60. data/lib/lightrail/generators/templates/public/index.html +241 -0
  61. data/lib/lightrail/generators/templates/public/robots.txt +5 -0
  62. data/lib/lightrail/generators/templates/public/stylesheets/.empty_directory +0 -0
  63. data/lib/lightrail/generators/templates/script/rails +5 -0
  64. data/lib/lightrail/generators/templates/test/fixtures/.empty_directory +0 -0
  65. data/lib/lightrail/generators/templates/test/functional/.empty_directory +0 -0
  66. data/lib/lightrail/generators/templates/test/integration/.empty_directory +0 -0
  67. data/lib/lightrail/generators/templates/test/performance/browsing_test.rb +12 -0
  68. data/lib/lightrail/generators/templates/test/test_helper.rb +15 -0
  69. data/lib/lightrail/generators/templates/test/unit/.empty_directory +0 -0
  70. data/lib/lightrail/version.rb +1 -1
  71. data/lightrail.gemspec +23 -0
  72. data/logo.png +0 -0
  73. data/spec/lightrail/action_controller/metal_spec.rb +8 -0
  74. data/spec/spec_helper.rb +1 -0
  75. data/tasks/rspec.task +7 -0
  76. metadata +105 -13
  77. data/lib/lightrail/action_controller/param.rb +0 -12
  78. data/lib/lightrail/core_ext/regexp.rb +0 -7
  79. data/lib/lightrail/encryptor.rb +0 -62
@@ -0,0 +1,281 @@
1
+ require 'digest/md5'
2
+ require 'securerandom'
3
+ require 'active_support/core_ext/string/strip'
4
+ require 'lightrail/version'
5
+ require 'rbconfig'
6
+ require 'open-uri'
7
+ require 'uri'
8
+
9
+ module Lightrail
10
+ module Generators
11
+ class AppBase < Base
12
+ DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db sqlserver )
13
+ JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql jdbc )
14
+ DATABASES.concat(JDBC_DATABASES)
15
+
16
+ attr_accessor :rails_template
17
+ add_shebang_option!
18
+
19
+ argument :app_path, :type => :string
20
+
21
+ def self.add_shared_options_for(name)
22
+ class_option :builder, :type => :string, :aliases => "-b",
23
+ :desc => "Path to a #{name} builder (can be a filesystem path or URL)"
24
+
25
+ class_option :template, :type => :string, :aliases => "-m",
26
+ :desc => "Path to an #{name} template (can be a filesystem path or URL)"
27
+
28
+ class_option :skip_gemfile, :type => :boolean, :default => false,
29
+ :desc => "Don't create a Gemfile"
30
+
31
+ class_option :skip_bundle, :type => :boolean, :default => false,
32
+ :desc => "Don't run bundle install"
33
+
34
+ class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false,
35
+ :desc => "Skip Git ignores and keeps"
36
+
37
+ class_option :skip_active_record, :type => :boolean, :aliases => "-O", :default => false,
38
+ :desc => "Skip Active Record files"
39
+
40
+ class_option :skip_sprockets, :type => :boolean, :aliases => "-S", :default => false,
41
+ :desc => "Skip Sprockets files"
42
+
43
+ class_option :database, :type => :string, :aliases => "-d", :default => "sqlite3",
44
+ :desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
45
+
46
+ class_option :javascript, :type => :string, :aliases => '-j', :default => 'jquery',
47
+ :desc => 'Preconfigure for selected JavaScript library'
48
+
49
+ class_option :skip_javascript, :type => :boolean, :aliases => "-J", :default => false,
50
+ :desc => "Skip JavaScript files"
51
+
52
+ class_option :dev, :type => :boolean, :default => false,
53
+ :desc => "Setup the #{name} with Gemfile pointing to your Rails checkout"
54
+
55
+ class_option :edge, :type => :boolean, :default => false,
56
+ :desc => "Setup the #{name} with Gemfile pointing to Rails repository"
57
+
58
+ class_option :skip_test_unit, :type => :boolean, :aliases => "-T", :default => false,
59
+ :desc => "Skip Test::Unit files"
60
+
61
+ class_option :help, :type => :boolean, :aliases => "-h", :group => :rails,
62
+ :desc => "Show this help message and quit"
63
+
64
+ class_option :old_style_hash, :type => :boolean, :default => false,
65
+ :desc => "Force using old style hash (:foo => 'bar') on Ruby >= 1.9"
66
+ end
67
+
68
+ def initialize(*args)
69
+ @original_wd = Dir.pwd
70
+ super
71
+ convert_database_option_for_jruby
72
+ end
73
+
74
+ protected
75
+
76
+ def builder
77
+ @builder ||= begin
78
+ if path = options[:builder]
79
+ if URI(path).is_a?(URI::HTTP)
80
+ contents = open(path, "Accept" => "application/x-thor-template") {|io| io.read }
81
+ else
82
+ contents = open(File.expand_path(path, @original_wd)) {|io| io.read }
83
+ end
84
+
85
+ prok = eval("proc { #{contents} }", TOPLEVEL_BINDING, path, 1)
86
+ instance_eval(&prok)
87
+ end
88
+
89
+ builder_class = get_builder_class
90
+ builder_class.send(:include, ActionMethods)
91
+ builder_class.new(self)
92
+ end
93
+ end
94
+
95
+ def build(meth, *args)
96
+ builder.send(meth, *args) if builder.respond_to?(meth)
97
+ end
98
+
99
+ def create_root
100
+ self.destination_root = File.expand_path(app_path, destination_root)
101
+ valid_const?
102
+
103
+ empty_directory '.'
104
+ set_default_accessors!
105
+ FileUtils.cd(destination_root) unless options[:pretend]
106
+ end
107
+
108
+ def apply_rails_template
109
+ apply rails_template if rails_template
110
+ rescue Thor::Error, LoadError, Errno::ENOENT => e
111
+ raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}"
112
+ end
113
+
114
+ def set_default_accessors!
115
+ self.rails_template = case options[:template]
116
+ when /^https?:\/\//
117
+ options[:template]
118
+ when String
119
+ File.expand_path(options[:template], Dir.pwd)
120
+ else
121
+ options[:template]
122
+ end
123
+ end
124
+
125
+ def database_gemfile_entry
126
+ options[:skip_active_record] ? "" : "gem '#{gem_for_database}'\n"
127
+ end
128
+
129
+ def include_all_railties?
130
+ !options[:skip_active_record] && !options[:skip_test_unit] && !options[:skip_sprockets]
131
+ end
132
+
133
+ def comment_if(value)
134
+ options[value] ? '# ' : ''
135
+ end
136
+
137
+ def rails_gemfile_entry
138
+ if options.dev?
139
+ <<-GEMFILE.strip_heredoc
140
+ gem 'rails', :path => '#{Rails::Generators::RAILS_DEV_PATH}'
141
+ gem 'journey', :git => 'git://github.com/rails/journey.git'
142
+ gem 'arel', :git => 'git://github.com/rails/arel.git'
143
+ GEMFILE
144
+ elsif options.edge?
145
+ <<-GEMFILE.strip_heredoc
146
+ gem 'rails', :git => 'git://github.com/rails/rails.git', :branch => '3-2-stable'
147
+ gem 'journey', :git => 'git://github.com/rails/journey.git'
148
+ gem 'arel', :git => 'git://github.com/rails/arel.git'
149
+ GEMFILE
150
+ else
151
+ <<-GEMFILE.strip_heredoc
152
+ gem 'rails', '#{Rails::VERSION::STRING}'
153
+
154
+ # Bundle edge Rails instead:
155
+ # gem 'rails', :git => 'git://github.com/rails/rails.git'
156
+ GEMFILE
157
+ end
158
+ end
159
+
160
+ def gem_for_database
161
+ # %w( mysql oracle postgresql sqlite3 frontbase ibm_db sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql )
162
+ case options[:database]
163
+ when "oracle" then "ruby-oci8"
164
+ when "postgresql" then "pg"
165
+ when "frontbase" then "ruby-frontbase"
166
+ when "mysql" then "mysql2"
167
+ when "sqlserver" then "activerecord-sqlserver-adapter"
168
+ when "jdbcmysql" then "activerecord-jdbcmysql-adapter"
169
+ when "jdbcsqlite3" then "activerecord-jdbcsqlite3-adapter"
170
+ when "jdbcpostgresql" then "activerecord-jdbcpostgresql-adapter"
171
+ when "jdbc" then "activerecord-jdbc-adapter"
172
+ else options[:database]
173
+ end
174
+ end
175
+
176
+ def convert_database_option_for_jruby
177
+ if defined?(JRUBY_VERSION)
178
+ case options[:database]
179
+ when "oracle" then options[:database].replace "jdbc"
180
+ when "postgresql" then options[:database].replace "jdbcpostgresql"
181
+ when "mysql" then options[:database].replace "jdbcmysql"
182
+ when "sqlite3" then options[:database].replace "jdbcsqlite3"
183
+ end
184
+ end
185
+ end
186
+
187
+ def ruby_debugger_gemfile_entry
188
+ if RUBY_VERSION < "1.9"
189
+ "gem 'ruby-debug'"
190
+ else
191
+ "gem 'ruby-debug19', :require => 'ruby-debug'"
192
+ end
193
+ end
194
+
195
+ def assets_gemfile_entry
196
+ return if options[:skip_sprockets]
197
+
198
+ gemfile = if options.dev? || options.edge?
199
+ <<-GEMFILE
200
+ # Gems used only for assets and not required
201
+ # in production environments by default.
202
+ group :assets do
203
+ gem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git', :branch => '3-2-stable'
204
+ gem 'coffee-rails', :git => 'git://github.com/rails/coffee-rails.git', :branch => '3-2-stable'
205
+
206
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
207
+ #{javascript_runtime_gemfile_entry}
208
+ gem 'uglifier', '>= 1.0.3'
209
+ end
210
+ GEMFILE
211
+ else
212
+ <<-GEMFILE
213
+ # Gems used only for assets and not required
214
+ # in production environments by default.
215
+ group :assets do
216
+ gem 'sass-rails', '~> 3.2.3'
217
+ gem 'coffee-rails', '~> 3.2.1'
218
+
219
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
220
+ #{javascript_runtime_gemfile_entry}
221
+ gem 'uglifier', '>= 1.0.3'
222
+ end
223
+ GEMFILE
224
+ end
225
+
226
+ gemfile.strip_heredoc.gsub(/^[ \t]*$/, '')
227
+ end
228
+
229
+ def javascript_gemfile_entry
230
+ "gem '#{options[:javascript]}-rails'" unless options[:skip_javascript]
231
+ end
232
+
233
+ def javascript_runtime_gemfile_entry
234
+ if defined?(JRUBY_VERSION)
235
+ "gem 'therubyrhino'\n"
236
+ else
237
+ "# gem 'therubyracer'\n"
238
+ end
239
+ end
240
+
241
+ def bundle_command(command)
242
+ say_status :run, "bundle #{command}"
243
+
244
+ # We are going to shell out rather than invoking Bundler::CLI.new(command)
245
+ # because `rails new` loads the Thor gem and on the other hand bundler uses
246
+ # its own vendored Thor, which could be a different version. Running both
247
+ # things in the same process is a recipe for a night with paracetamol.
248
+ #
249
+ # We use backticks and #print here instead of vanilla #system because it
250
+ # is easier to silence stdout in the existing test suite this way. The
251
+ # end-user gets the bundler commands called anyway, so no big deal.
252
+ #
253
+ # Thanks to James Tucker for the Gem tricks involved in this call.
254
+ print `"#{Gem.ruby}" -rubygems "#{Gem.bin_path('bundler', 'bundle')}" #{command}`
255
+ end
256
+
257
+ def run_bundle
258
+ bundle_command('install') unless options[:skip_gemfile] || options[:skip_bundle]
259
+ end
260
+
261
+ def empty_directory_with_gitkeep(destination, config = {})
262
+ empty_directory(destination, config)
263
+ git_keep(destination)
264
+ end
265
+
266
+ def git_keep(destination)
267
+ create_file("#{destination}/.gitkeep") unless options[:skip_git]
268
+ end
269
+
270
+ # Returns Ruby 1.9 style key-value pair if current code is running on
271
+ # Ruby 1.9.x. Returns the old-style (with hash rocket) otherwise.
272
+ def key_value(key, value)
273
+ if options[:old_style_hash] || RUBY_VERSION < '1.9'
274
+ ":#{key} => #{value}"
275
+ else
276
+ "#{key}: #{value}"
277
+ end
278
+ end
279
+ end
280
+ end
281
+ end
@@ -0,0 +1,299 @@
1
+ require 'lightrail/generators/app_base'
2
+
3
+ module Lightrail
4
+ module ActionMethods
5
+ attr_reader :options
6
+
7
+ def initialize(generator)
8
+ @generator = generator
9
+ @options = generator.options
10
+ end
11
+
12
+ private
13
+ %w(template copy_file directory empty_directory inside
14
+ empty_directory_with_gitkeep create_file chmod shebang).each do |method|
15
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
16
+ def #{method}(*args, &block)
17
+ @generator.send(:#{method}, *args, &block)
18
+ end
19
+ RUBY
20
+ end
21
+
22
+ # TODO: Remove once this is fully in place
23
+ def method_missing(meth, *args, &block)
24
+ @generator.send(meth, *args, &block)
25
+ end
26
+ end
27
+
28
+ # The application builder allows you to override elements of the application
29
+ # generator without being forced to reverse the operations of the default
30
+ # generator.
31
+ #
32
+ # This allows you to override entire operations, like the creation of the
33
+ # Gemfile, README, or JavaScript files, without needing to know exactly
34
+ # what those operations do so you can create another template action.
35
+ class AppBuilder
36
+ def rakefile
37
+ template "Rakefile"
38
+ end
39
+
40
+ def readme
41
+ copy_file "README", "README.rdoc"
42
+ end
43
+
44
+ def gemfile
45
+ template "Gemfile"
46
+ end
47
+
48
+ def configru
49
+ template "config.ru"
50
+ end
51
+
52
+ def gitignore
53
+ copy_file "gitignore", ".gitignore"
54
+ end
55
+
56
+ def app
57
+ directory 'app'
58
+ git_keep 'app/mailers'
59
+ git_keep 'app/models'
60
+ end
61
+
62
+ def config
63
+ empty_directory "config"
64
+
65
+ inside "config" do
66
+ template "routes.rb"
67
+ template "application.rb"
68
+ template "environment.rb"
69
+
70
+ directory "environments"
71
+ directory "initializers"
72
+ directory "locales"
73
+ end
74
+ end
75
+
76
+ def database_yml
77
+ template "config/databases/#{options[:database]}.yml", "config/database.yml"
78
+ end
79
+
80
+ def db
81
+ directory "db"
82
+ end
83
+
84
+ def doc
85
+ directory "doc"
86
+ end
87
+
88
+ def lib
89
+ empty_directory "lib"
90
+ empty_directory_with_gitkeep "lib/tasks"
91
+ empty_directory_with_gitkeep "lib/assets"
92
+ end
93
+
94
+ def log
95
+ empty_directory_with_gitkeep "log"
96
+ end
97
+
98
+ def public_directory
99
+ directory "public", "public", :recursive => false
100
+ end
101
+
102
+ def script
103
+ directory "script" do |content|
104
+ "#{shebang}\n" + content
105
+ end
106
+ chmod "script", 0755, :verbose => false
107
+ end
108
+
109
+ def test
110
+ empty_directory_with_gitkeep "test/fixtures"
111
+ empty_directory_with_gitkeep "test/functional"
112
+ empty_directory_with_gitkeep "test/integration"
113
+ empty_directory_with_gitkeep "test/unit"
114
+
115
+ template "test/performance/browsing_test.rb"
116
+ template "test/test_helper.rb"
117
+ end
118
+
119
+ def tmp
120
+ empty_directory "tmp/cache"
121
+ empty_directory "tmp/cache/assets"
122
+ end
123
+
124
+ def vendor
125
+ vendor_javascripts
126
+ vendor_stylesheets
127
+ end
128
+
129
+ def vendor_javascripts
130
+ empty_directory_with_gitkeep "vendor/assets/javascripts"
131
+ end
132
+
133
+ def vendor_stylesheets
134
+ empty_directory_with_gitkeep "vendor/assets/stylesheets"
135
+ end
136
+ end
137
+
138
+ module Generators
139
+ # We need to store the RAILS_DEV_PATH in a constant, otherwise the path
140
+ # can change in Ruby 1.8.7 when we FileUtils.cd.
141
+ RAILS_DEV_PATH = File.expand_path("../../../../../..", File.dirname(__FILE__))
142
+ RESERVED_NAMES = %w[application destroy benchmarker profiler plugin runner test]
143
+
144
+ class AppGenerator < AppBase
145
+ add_shared_options_for "application"
146
+ source_root File.expand_path("../templates", __FILE__)
147
+
148
+ # Add bin/rails options
149
+ class_option :version, :type => :boolean, :aliases => "-v", :group => :rails,
150
+ :desc => "Show Rails version number and quit"
151
+
152
+ def initialize(*args)
153
+ raise Error, "Options should be given after the application name. For details run: rails --help" if args[0].blank?
154
+
155
+ super
156
+
157
+ if !options[:skip_active_record] && !DATABASES.include?(options[:database])
158
+ raise Error, "Invalid value for --database option. Supported for preconfiguration are: #{DATABASES.join(", ")}."
159
+ end
160
+ end
161
+
162
+ public_task :create_root
163
+
164
+ def create_root_files
165
+ build(:readme)
166
+ build(:rakefile)
167
+ build(:configru)
168
+ build(:gitignore) unless options[:skip_git]
169
+ build(:gemfile) unless options[:skip_gemfile]
170
+ end
171
+
172
+ def create_app_files
173
+ build(:app)
174
+ end
175
+
176
+ def create_config_files
177
+ build(:config)
178
+ end
179
+
180
+ def create_boot_file
181
+ template "config/boot.rb"
182
+ end
183
+
184
+ def create_active_record_files
185
+ return if options[:skip_active_record]
186
+ build(:database_yml)
187
+ end
188
+
189
+ def create_db_files
190
+ build(:db)
191
+ end
192
+
193
+ def create_doc_files
194
+ build(:doc)
195
+ end
196
+
197
+ def create_lib_files
198
+ build(:lib)
199
+ end
200
+
201
+ def create_log_files
202
+ build(:log)
203
+ end
204
+
205
+ def create_public_files
206
+ build(:public_directory)
207
+ end
208
+
209
+ def create_script_files
210
+ build(:script)
211
+ end
212
+
213
+ def create_test_files
214
+ build(:test) unless options[:skip_test_unit]
215
+ end
216
+
217
+ def create_tmp_files
218
+ build(:tmp)
219
+ end
220
+
221
+ def create_vendor_files
222
+ build(:vendor)
223
+ end
224
+
225
+ def finish_template
226
+ build(:leftovers)
227
+ end
228
+
229
+ public_task :apply_rails_template, :run_bundle
230
+
231
+ protected
232
+
233
+ def self.banner
234
+ "lightrail new #{self.arguments.map(&:usage).join(' ')} [options]"
235
+ end
236
+
237
+ # Define file as an alias to create_file for backwards compatibility.
238
+ def file(*args, &block)
239
+ create_file(*args, &block)
240
+ end
241
+
242
+ def app_name
243
+ @app_name ||= defined_app_const_base? ? defined_app_name : File.basename(destination_root)
244
+ end
245
+
246
+ def defined_app_name
247
+ defined_app_const_base.underscore
248
+ end
249
+
250
+ def defined_app_const_base
251
+ Rails.respond_to?(:application) && defined?(Rails::Application) &&
252
+ Rails.application.is_a?(Rails::Application) && Rails.application.class.name.sub(/::Application$/, "")
253
+ end
254
+
255
+ alias :defined_app_const_base? :defined_app_const_base
256
+
257
+ def app_const_base
258
+ @app_const_base ||= defined_app_const_base || app_name.gsub(/\W/, '_').squeeze('_').camelize
259
+ end
260
+ alias :camelized :app_const_base
261
+
262
+ def app_const
263
+ @app_const ||= "#{app_const_base}::Application"
264
+ end
265
+
266
+ def valid_const?
267
+ if app_const =~ /^\d/
268
+ raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers."
269
+ elsif RESERVED_NAMES.include?(app_name)
270
+ raise Error, "Invalid application name #{app_name}. Please give a name which does not match one of the reserved rails words."
271
+ elsif Object.const_defined?(app_const_base)
272
+ raise Error, "Invalid application name #{app_name}, constant #{app_const_base} is already in use. Please choose another application name."
273
+ end
274
+ end
275
+
276
+ def app_secret
277
+ SecureRandom.hex(64)
278
+ end
279
+
280
+ def mysql_socket
281
+ @mysql_socket ||= [
282
+ "/tmp/mysql.sock", # default
283
+ "/var/run/mysqld/mysqld.sock", # debian/gentoo
284
+ "/var/tmp/mysql.sock", # freebsd
285
+ "/var/lib/mysql/mysql.sock", # fedora
286
+ "/opt/local/lib/mysql/mysql.sock", # fedora
287
+ "/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql
288
+ "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4
289
+ "/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5
290
+ "/opt/lampp/var/mysql/mysql.sock" # xampp for linux
291
+ ].find { |f| File.exist?(f) } unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
292
+ end
293
+
294
+ def get_builder_class
295
+ defined?(::AppBuilder) ? ::AppBuilder : Lightrail::AppBuilder
296
+ end
297
+ end
298
+ end
299
+ end