class Firestarter::AppBuilder

Public Instance Methods

add_retina_tag() click to toggle source
# File lib/firestarter/app_builder.rb, line 146
def add_retina_tag
  append_to_file "app/assets/javascripts/application.js",
    "//= require retina_tag\n"
end
configure_action_mailer() click to toggle source
# File lib/firestarter/app_builder.rb, line 219
def configure_action_mailer
  action_mailer_host "development", "#{app_name}.local"
  action_mailer_host "test", "www.example.com"
  action_mailer_host "staging", "staging.#{app_name}.com"
  action_mailer_host "production", "#{app_name}.com"
end
configure_generators() click to toggle source
# File lib/firestarter/app_builder.rb, line 42
    def configure_generators # rubocop:disable Metrics/MethodLength
      config = <<-RUBY
    config.generators do |generate|
      generate.helper false
      generate.javascript_engine false
      generate.request_specs false
      generate.routing_specs false
      generate.stylesheets false
      generate.test_framework :rspec
      generate.view_specs false
    end

      RUBY

      inject_into_class "config/application.rb", "Application", config
    end
configure_i18n_in_specs() click to toggle source
# File lib/firestarter/app_builder.rb, line 194
def configure_i18n_in_specs
  copy_file "i18n.rb", "spec/support/i18n.rb"
end
configure_puma() click to toggle source
# File lib/firestarter/app_builder.rb, line 238
def configure_puma
  copy_file "puma.rb", "config/puma.rb", force: true
end
configure_rack_timeout() click to toggle source
# File lib/firestarter/app_builder.rb, line 211
def configure_rack_timeout
  copy_file "rack_timeout.rb", "config/initializers/rack_timeout.rb"
end
configure_rspec() click to toggle source
# File lib/firestarter/app_builder.rb, line 189
def configure_rspec
  remove_file "spec/spec_helper.rb"
  copy_file "spec_helper.rb", "spec/spec_helper.rb"
end
configure_slim() click to toggle source
# File lib/firestarter/app_builder.rb, line 215
def configure_slim
  copy_file "slim.rb", "config/initializers/slim.rb"
end
configure_smtp() click to toggle source
# File lib/firestarter/app_builder.rb, line 68
    def configure_smtp
      copy_file "smtp.rb", "config/initializers/smtp.rb"

      prepend_file "config/environments/production.rb",
        "require Rails.root.join('config/initializers/smtp')\n"

      config = <<-RUBY

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = SMTP_SETTINGS
      RUBY

      inject_into_file "config/environments/production.rb", config,
        after: "config.action_mailer.raise_delivery_errors = false"
    end
configure_spec_support_features() click to toggle source
# File lib/firestarter/app_builder.rb, line 184
def configure_spec_support_features
  empty_directory_with_keep_file "spec/features"
  empty_directory_with_keep_file "spec/support/features"
end
configure_time_formats() click to toggle source
# File lib/firestarter/app_builder.rb, line 206
def configure_time_formats
  remove_file "config/locales/en.yml"
  copy_file "config_locales_en.yml", "config/locales/en.yml"
end
configure_time_zone() click to toggle source
# File lib/firestarter/app_builder.rb, line 198
    def configure_time_zone
      config = <<-RUBY
    config.active_record.default_timezone = :utc

      RUBY
      inject_into_class "config/application.rb", "Application", config
    end
create_application_layout() click to toggle source
# File lib/firestarter/app_builder.rb, line 127
def create_application_layout
  remove_file "app/views/layouts/application.html.erb"
  template "firestarter_layout.slim.erb",
    "app/views/layouts/application.slim",
    force: true
end
create_database() click to toggle source
# File lib/firestarter/app_builder.rb, line 163
def create_database
  bundle_command "exec rake db:create db:migrate"
end
create_partials_directory() click to toggle source
# File lib/firestarter/app_builder.rb, line 115
def create_partials_directory
  empty_directory "app/views/application"
end
create_shared_flashes() click to toggle source
# File lib/firestarter/app_builder.rb, line 119
def create_shared_flashes
  copy_file "_flashes.slim", "app/views/application/_flashes.slim"
end
create_shared_javascripts() click to toggle source
# File lib/firestarter/app_builder.rb, line 123
def create_shared_javascripts
  copy_file "_javascript.slim", "app/views/application/_javascript.slim"
end
customize_error_pages() click to toggle source
# File lib/firestarter/app_builder.rb, line 274
    def customize_error_pages
      meta_tags = <<-EOS
  <meta charset='utf-8' />
  <meta name='ROBOTS' content='NOODP' />
      EOS

      %w(500 404 422).each do |page|
        inject_into_file "public/#{page}.html", meta_tags, after: "<head>\n"
        replace_in_file "public/#{page}.html", /<!--.+-->\n/, ""
      end
    end
disable_xml_params() click to toggle source
# File lib/firestarter/app_builder.rb, line 292
def disable_xml_params
  copy_file "disable_xml_params.rb", "config/initializers/disable_xml_params.rb"
end
enable_database_cleaner() click to toggle source
# File lib/firestarter/app_builder.rb, line 180
def enable_database_cleaner
  copy_file "database_cleaner_rspec.rb", "spec/support/database_cleaner.rb"
end
enable_factory_girl_syntax() click to toggle source
# File lib/firestarter/app_builder.rb, line 59
def enable_factory_girl_syntax
  copy_file "factory_girl_syntax_rspec.rb", "spec/support/factory_girl.rb"
end
enable_rack_deflater() click to toggle source
# File lib/firestarter/app_builder.rb, line 84
    def enable_rack_deflater
      config = <<-RUBY

  # Enable deflate / gzip compression of controller-generated responses
  config.middleware.use Rack::Deflater
      RUBY

      inject_into_file "config/environments/production.rb", config,
        after: "config.serve_static_assets = false\n"
    end
enable_unobtrusive_pry_in_specs() click to toggle source
# File lib/firestarter/app_builder.rb, line 176
def enable_unobtrusive_pry_in_specs
  copy_file "unobtrusive_pry.rb", "spec/support/pry.rb"
end
fix_i18n_deprecation_warning() click to toggle source
# File lib/firestarter/app_builder.rb, line 226
    def fix_i18n_deprecation_warning
      config = <<-RUBY
    config.i18n.enforce_available_locales = true

      RUBY
      inject_into_class "config/application.rb", "Application", config
    end
generate_rspec() click to toggle source
# File lib/firestarter/app_builder.rb, line 234
def generate_rspec
  generate "rspec:install"
end
gitignore_files() click to toggle source
# File lib/firestarter/app_builder.rb, line 253
def gitignore_files # rubocop:disable Metrics/MethodLength
  remove_file ".gitignore"
  copy_file "firestarter_gitignore", ".gitignore"
  [
    "app/views/pages",
    "spec/lib",
    "spec/controllers",
    "spec/helpers",
    "spec/support/matchers",
    "spec/support/mixins",
    "spec/support/shared_examples",
  ].each do |dir|
    run "mkdir #{dir}"
    run "touch #{dir}/.keep"
  end
end
init_git() click to toggle source
# File lib/firestarter/app_builder.rb, line 270
def init_git
  run "git init"
end
provide_dev_prime_task() click to toggle source
# File lib/firestarter/app_builder.rb, line 38
def provide_dev_prime_task
  copy_file "development_seeds.rb", "lib/tasks/development_seeds.rake"
end
provide_setup_script() click to toggle source
# File lib/firestarter/app_builder.rb, line 32
def provide_setup_script
  remove_file "bin/setup"
  copy_file "bin_setup", "bin/setup"
  run "chmod a+x bin/setup"
end
raise_on_delivery_errors() click to toggle source
# File lib/firestarter/app_builder.rb, line 13
def raise_on_delivery_errors
  replace_in_file "config/environments/development.rb",
    "raise_delivery_errors = false", "raise_delivery_errors = true"
end
raise_on_unpermitted_parameters() click to toggle source
# File lib/firestarter/app_builder.rb, line 18
    def raise_on_unpermitted_parameters
      action_on_unpermitted_parameters = <<-RUBY

  # Raise an ActionController::UnpermittedParameters exception when
  # a parameter is not explcitly permitted but is passed anyway.
  config.action_controller.action_on_unpermitted_parameters = :raise
      RUBY
      inject_into_file(
        "config/environments/development.rb",
        action_on_unpermitted_parameters,
        before: "\nend",
      )
    end
rakefile() click to toggle source
# File lib/firestarter/app_builder.rb, line 9
def rakefile
  template "Rakefile.erb", "Rakefile"
end
readme() click to toggle source
# File lib/firestarter/app_builder.rb, line 5
def readme
  template "README.md.erb", "README.md"
end
remove_require_tree() click to toggle source
# File lib/firestarter/app_builder.rb, line 140
def remove_require_tree
  replace_in_file "app/assets/javascripts/application.js",
    %r{//= require_tree .\n},
    ""
end
remove_routes_comment_lines() click to toggle source
# File lib/firestarter/app_builder.rb, line 286
def remove_routes_comment_lines
  replace_in_file "config/routes.rb",
    /Rails.application\.routes\.draw do.*end/m,
    "Rails.application.routes.draw do\nend"
end
replace_gemfile() click to toggle source
# File lib/firestarter/app_builder.rb, line 167
def replace_gemfile
  remove_file "Gemfile"
  template "Gemfile.erb", "Gemfile"
end
scss_lint_config() click to toggle source
# File lib/firestarter/app_builder.rb, line 296
def scss_lint_config
  copy_file "scss-lint.yml", ".scss-lint.yml"
end
set_ruby_to_version_being_used() click to toggle source
# File lib/firestarter/app_builder.rb, line 172
def set_ruby_to_version_being_used
  template "ruby-version.erb", ".ruby-version"
end
setup_default_rake_task() click to toggle source
# File lib/firestarter/app_builder.rb, line 300
def setup_default_rake_task
  append_file "Rakefile" do
    "task(:default).clear\ntask :default => [:spec]\n"
  end
end
setup_foreman() click to toggle source
# File lib/firestarter/app_builder.rb, line 242
def setup_foreman
  copy_file "sample.env", ".sample.env"
  copy_file "Procfile", "Procfile"
end
setup_metrics() click to toggle source
# File lib/firestarter/app_builder.rb, line 306
def setup_metrics
  copy_file "metrics", ".metrics"
  copy_file "metrics.reek", ".metrics.reek"
end
setup_secret_token() click to toggle source
# File lib/firestarter/app_builder.rb, line 109
def setup_secret_token
  template "secret_token.rb.erb",
    "config/initializers/secret_token.rb",
    force: true
end
setup_staging_environment() click to toggle source
# File lib/firestarter/app_builder.rb, line 95
    def setup_staging_environment
      staging_file = "config/environments/staging.rb"
      copy_file "staging.rb", staging_file

      config = <<-RUBY

#{app_name.classify}::Application.configure do
  # ...
end
      RUBY

      append_file staging_file, config
    end
setup_stylesheets() click to toggle source
# File lib/firestarter/app_builder.rb, line 247
def setup_stylesheets
  remove_file "app/assets/stylesheets/application.css"
  copy_file "application.sass",
    "app/assets/stylesheets/application.sass"
end
test_factories_first() click to toggle source
# File lib/firestarter/app_builder.rb, line 63
def test_factories_first
  copy_file "factories_spec.rb", "spec/models/factories_spec.rb"
  append_file "Rakefile", factories_spec_rake_task
end
use_postgres_config_template() click to toggle source
# File lib/firestarter/app_builder.rb, line 151
def use_postgres_config_template
  template "postgresql_database.yml.erb", "config/database.yml",
    force: true
end
use_rubocop_config() click to toggle source
# File lib/firestarter/app_builder.rb, line 156
def use_rubocop_config
  download_file(
    "https://github.com/subvisual/guides/blob/master/linters/ruby/.rubocop.yml",
    ".rubocop.yml"
  )
end

Private Instance Methods

factories_spec_rake_task() click to toggle source
# File lib/firestarter/app_builder.rb, line 320
def factories_spec_rake_task
  IO.read find_in_source_paths("factories_spec_rake_task.rb")
end
generate_secret() click to toggle source
# File lib/firestarter/app_builder.rb, line 324
def generate_secret
  SecureRandom.hex(64)
end
override_path_for_tests() click to toggle source
# File lib/firestarter/app_builder.rb, line 313
def override_path_for_tests
  if ENV["TESTING"]
    support_bin = File.expand_path(File.join("..", "..", "spec", "fakes", "bin"))
    "PATH=#{support_bin}:$PATH"
  end
end