Class: AppGenerator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ AppGenerator

Returns a new instance of AppGenerator.



18
19
20
21
22
# File 'lib/railsbricks/app_generator.rb', line 18

def initialize(options)
  @options = options
  @app_dir = Dir.pwd + "/#{@options[:app_name]}"
  @rbricks_dir = File.dirname(__FILE__)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



16
17
18
# File 'lib/railsbricks/app_generator.rb', line 16

def options
  @options
end

Instance Method Details

#generate_appObject



24
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
# File 'lib/railsbricks/app_generator.rb', line 24

def generate_app
  # Drop creation if necessary
  if !@options[:generate]
    wputs "App creation aborted...", :error
    new_line
    abort
  end

  # updating necessary global gems
  update_essential_gems

  # install Rails
  install_rails

  # copy foundation app to directory
  create_foundation

  # ui
  StyleBuilder.build_style(@app_dir, @options)

  # database config
  config_db

  # environment variables
  config_env_var

  # authentication
  if @options[:devise]
    AuthBuilder.build_auth(@app_dir, @options)
  end

  # contact form
  add_contact_form

  # google analytics
  set_google_analytics

  # post resource
  if @options[:devise] && @options[:post_resources]
    PostBuilder.build_post(@app_dir, @options)
  elsif @options[:devise] && !@options[:post_resources]
    PostBuilder.clean(@app_dir)
  end

  # prod settings
  if @options[:production]
    set_production
  end

  # Set app name
  set_app_name

  # build Gemfile
  GemfileBuilder.build_gemfile(@app_dir, @options)

  # install gems
  bundle_install

  # create database
  create_database

  # save config
  ConfigHelpers.create_config(@app_dir, @options)

  # annotate models and routes
  annotate

  # git
  set_git

  # Summary
  new_line(2)
  wputs "----> #{@options[:rails_app_name]} created successfully!", :help
  if @options[:devise]
    new_line
    wputs "Admin username: #{@options[:devise_config][:scheme] == 'email' ? '[email protected]' : 'admin' }", :info
    wputs "Admin password: 1234", :info
  end
  new_line
  wputs "Run 'rails server' within #{@options[:app_name]} to start it.", :help
  new_line

end