Class: InlineForms::Creator
- Inherits:
-
Thor
- Object
- Thor
- InlineForms::Creator
- Includes:
- Thor::Actions
- Defined in:
- bin/inline_forms
Constant Summary collapse
- DATABASE_OPTIONS =
%w(sqlite mysql)
Class Method Summary collapse
- .database ⇒ Object
- .dry_run? ⇒ Boolean
- .email ⇒ Object
- .install_example? ⇒ Boolean
- .password ⇒ Object
- .runtest ⇒ Object
- .skiprvm ⇒ Object
- .source_root ⇒ Object
- .using_sqlite? ⇒ Boolean
Instance Method Summary collapse
Class Method Details
.database ⇒ Object
42 43 44 |
# File 'bin/inline_forms', line 42 def self.database DATABASE_OPTIONS.include?([:database]) ? [:database] : 'sqlite' end |
.dry_run? ⇒ Boolean
34 35 36 |
# File 'bin/inline_forms', line 34 def self.dry_run? [:dry] end |
.email ⇒ Object
50 51 52 |
# File 'bin/inline_forms', line 50 def self.email [:email] end |
.install_example? ⇒ Boolean
38 39 40 |
# File 'bin/inline_forms', line 38 def self.install_example? [:example] end |
.password ⇒ Object
54 55 56 |
# File 'bin/inline_forms', line 54 def self.password [:password] end |
.runtest ⇒ Object
30 31 32 |
# File 'bin/inline_forms', line 30 def self.runtest [:runtest] end |
.skiprvm ⇒ Object
26 27 28 |
# File 'bin/inline_forms', line 26 def self.skiprvm [:skiprvm] end |
.source_root ⇒ Object
12 13 14 |
# File 'bin/inline_forms', line 12 def self.source_root File.dirname(__FILE__)+"/.." end |
.using_sqlite? ⇒ Boolean
46 47 48 |
# File 'bin/inline_forms', line 46 def self.using_sqlite? database == 'sqlite' end |
Instance Method Details
#create(app_name) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'bin/inline_forms', line 25 def create(app_name) def self.skiprvm [:skiprvm] end def self.runtest [:runtest] end def self.dry_run? [:dry] end def self.install_example? [:example] end def self.database DATABASE_OPTIONS.include?([:database]) ? [:database] : 'sqlite' end def self.using_sqlite? database == 'sqlite' end def self.email [:email] end def self.password [:password] end if install_example? && dry_run? say "--example and --dry-run can not be used together", :red exit 1 end if install_example? && !using_sqlite? say "--example can only be used with an sqlite development database", :red exit 1 end say "This is a dry run. I hope you know what you are doing...", :red if dry_run? say "Creating #{app_name} with inline_forms v#{VERSION} and development database #{database}...", :green regex = /\A[0-9a-zA-Z][0-9a-zA-Z_-]+[0-9a-zA-Z]\Z/ if ! regex.match(app_name) say "Error: APP must match #{regex.source}", :red exit 1 end if File.exists?(app_name) say "Error: APP exists", :red exit 1 end # TODO: optioneel, detecteren dat er RVM er is als het niet zo is dan zonder RVM instaleren # Maybe via the method.options (THOR)?? # using_rvm = false # for testing purpose only need to do this another way. require 'rvm' # if RVM is detected and the user has not disabled using rvm via command than use rvm else without if RVM.current && ![:skiprvm] # Let the user know that he are installing the inline_forms with support of RVM say "Installing inline_forms with RVM", :green # which ruby version is currently activated? ruby_version = (%x[rvm current]).gsub(/@.*/,'') # Create a ruby rvm-file version based on the version detected create_file "#{app_name}/.ruby-version", ruby_version # Creat a ruby-gemset rvm-file based on the version detected create_file "#{app_name}/.ruby-gemset", app_name else # Let the user know that he is installing inline_forms without RVM say "Installing inline_forms without RVM", :green end if dry_run? empty_directory(app_name) else empty_directory(app_name) # need to pass all agruments for app template .each do | k,v | ENV[k] = v.to_s end ENV['using_sqlite'] = using_sqlite?.to_s ENV['install_example'] = install_example?.to_s ENV['ruby_version'] = ruby_version app_template_file = File.join(File.dirname(__FILE__), 'inline_forms_app_template.rb') if ! run("rails _3.2.12_ new #{app_name} -m #{app_template_file} --skip-bundle --skip-gemfile --skip-test-unit") say "Rails could not create the app '#{app_name}', maybe because it is a reserved word...", :red exit 1 end end end |