Class: Barebones::AppBuilder

Inherits:
Rails::AppBuilder
  • Object
show all
Includes:
TextFormatHelpers
Defined in:
lib/barebones/builders/app_builder.rb

Instance Method Summary collapse

Methods included from TextFormatHelpers

#replace_regex_in_file, #spaces

Instance Method Details

#appObject



19
20
21
22
23
24
25
# File 'lib/barebones/builders/app_builder.rb', line 19

def app
  super
  keep_file "app/services"
  keep_file "app/decorators"
  template  "barebones_decorator.rb.erb", 
    "app/decorators/#{app_name.parameterize.underscore}_decorator.rb"
end

#configObject



27
28
29
# File 'lib/barebones/builders/app_builder.rb', line 27

def config
  super
end

#configure_active_job_for_resqueObject



153
154
155
156
157
158
159
160
# File 'lib/barebones/builders/app_builder.rb', line 153

def configure_active_job_for_resque
  application_class_end_line = "#{spaces(2)}end\nend"
  inject_into_file "config/application.rb", 
    before: application_class_end_line do
      "\n#{spaces(4)}# Set ActiveJob to use Resque\n"\
      "#{spaces(4)}config.active_job.queue_adapter = :resque\n"
  end
end

#configure_active_job_for_sidekiqObject



162
163
164
165
166
167
168
169
# File 'lib/barebones/builders/app_builder.rb', line 162

def configure_active_job_for_sidekiq
  application_class_end_line = "#{spaces(2)}end\nend"
  inject_into_file "config/application.rb", 
    before: application_class_end_line do
      "\n#{spaces(4)}# Set ActiveJob to use Sidekiq\n"\
      "#{spaces(4)}config.active_job.queue_adapter = :sidekiq\n"
  end
end

#configure_carrierwaveObject



191
192
193
# File 'lib/barebones/builders/app_builder.rb', line 191

def configure_carrierwave
  template "carrierwave.rb", "config/initializers/carrierwave.rb"
end

#configure_factory_girlObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/barebones/builders/app_builder.rb', line 101

def configure_factory_girl
  application_class_end_line = "#{spaces(2)}end\nend"
  inject_into_file "config/application.rb", 
    before: application_class_end_line do
      "\n#{spaces(4)}# Generate Factories instead of Fixtures\n"\
      "#{spaces(4)}config.generators do |g|\n"\
      "#{spaces(6)}g.factory_girl true\n"\
      "#{spaces(4)}end\n"
  end

  class_end_line = "end\n"
  inject_into_file "test/test_helper.rb",
    after: class_end_line do
      "# Minitest does not provide a way to include or "\
      "extend a module into every test class\n"\
      "# without re-opening the test case class\n"\
      "module Minitest\n"\
      "#{spaces(2)}class Test\n"\
      "#{spaces(4)}include FactoryGirl::Syntax::Methods\n"\
      "#{spaces(2)}end\n"\
      "end\n"
  end
end

#configure_minitestObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/barebones/builders/app_builder.rb', line 125

def configure_minitest
  class_end_line = "#{spaces(2)}end\nend"
  inject_into_file "config/application.rb", 
    before: class_end_line do
      "\n#{spaces(4)}# Auto generate test files\n"\
      "#{spaces(4)}config.generators do |g|\n"\
      "#{spaces(6)}g.test_framework :minitest, spec: true, fixture: false\n"\
      "#{spaces(4)}end\n"
  end

  last_require = "require 'rails/test_help'\n"
  inject_into_file "test/test_helper.rb",
    after: last_require do
      "require 'minitest/reporters'\n"\
      "require 'minitest/spec'\n"\
      "require 'mocha/mini_test'\n"\
      "# Require all support helpers\n"\
      "Dir[Rails.root.join('test/support/**/*.rb')].each { |f| require f }\n"\
      "\n"\
      "Minitest::Reporters.use!(\n"\
      "#{spaces(2)}Minitest::Reporters::DefaultReporter.new,\n"\
      "#{spaces(2)}ENV,\n"\
      "#{spaces(2)}Minitest.backtrace_filter\n"\
      ")\n"
  end
    
end

#configure_pumaObject



195
196
197
198
# File 'lib/barebones/builders/app_builder.rb', line 195

def configure_puma
  template "Procfile", "Procfile"
  template "puma.rb", "config/puma.rb", force: true
end

#configure_redisObject



171
172
173
# File 'lib/barebones/builders/app_builder.rb', line 171

def configure_redis
  template "redis.rb.erb", "config/initializers/redis.rb"
end

#configure_resqueObject



175
176
177
# File 'lib/barebones/builders/app_builder.rb', line 175

def configure_resque
  template "resque.rb", "config/initializers/resque.rb"
end

#configure_sidekiqObject



179
180
181
# File 'lib/barebones/builders/app_builder.rb', line 179

def configure_sidekiq
  template "sidekiq.rb", "config/initializers/sidekiq.rb"
end

#create_api_configurationsObject



72
73
74
75
76
# File 'lib/barebones/builders/app_builder.rb', line 72

def create_api_configurations
  empty_directory "app/views/api/v1/configs"
  template "configs_controller.rb", "app/controllers/api/v1/configs_controller.rb"
  template "config_ping.json.jbuilder", "app/views/api/v1/configs/ping.json.jbuilder"
end

#create_api_constraintsObject



61
62
63
# File 'lib/barebones/builders/app_builder.rb', line 61

def create_api_constraints
  template "api_constraints.rb.erb", "lib/api_constraints.rb"
end

#create_api_layoutsObject



78
79
80
81
82
83
# File 'lib/barebones/builders/app_builder.rb', line 78

def create_api_layouts
  empty_directory "app/views/layouts/api/v1"
  template "layout.json.jbuilder", "app/views/layouts/api/v1/application.json.jbuilder"
  empty_directory "app/views/api/v1/defaults"
  create_file "app/views/api/v1/defaults/default.json.jbuilder"
end

#create_api_v1_defaultsObject



65
66
67
68
69
70
# File 'lib/barebones/builders/app_builder.rb', line 65

def create_api_v1_defaults
  empty_directory "app/controllers/api"
  empty_directory "app/controllers/api/v1"
  template "api_application_controller.rb", "app/controllers/api/v1/application_controller.rb"
  template "api_defaults_concern.rb", "app/controllers/concerns/api_defaults.rb"
end

#create_resque_rake_taskObject



187
188
189
# File 'lib/barebones/builders/app_builder.rb', line 187

def create_resque_rake_task
  template "resque.rake", "lib/tasks/resque.rake"
end

#create_staging_environmentObject



96
97
98
99
# File 'lib/barebones/builders/app_builder.rb', line 96

def create_staging_environment
  environment_path = "config/environments"
  run "cp #{environment_path}/development.rb #{environment_path}/staging.rb"
end

#create_test_jobObject



183
184
185
# File 'lib/barebones/builders/app_builder.rb', line 183

def create_test_job
  template "test_job.rb", "app/jobs/test_job.rb"
end

#customize_routesObject



53
54
55
# File 'lib/barebones/builders/app_builder.rb', line 53

def customize_routes
  template "routes.rb.erb", "config/routes.rb", force: true
end

#customize_secretsObject



85
86
87
# File 'lib/barebones/builders/app_builder.rb', line 85

def customize_secrets
  template "secrets.yml.erb", "config/secrets.yml", force: true
end

#database_ymlObject



31
32
33
# File 'lib/barebones/builders/app_builder.rb', line 31

def database_yml
  template "database.yml.erb", "config/database.yml"
end

#gemfileObject



10
11
12
13
# File 'lib/barebones/builders/app_builder.rb', line 10

def gemfile
  template "Gemfile.erb", "Gemfile"
  replace_regex_in_file("Gemfile", /\n{2,}/, "\n\n")
end

#gitignoreObject



15
16
17
# File 'lib/barebones/builders/app_builder.rb', line 15

def gitignore
  template "barebones_gitignore", ".gitignore"
end

#raise_on_delivery_errorsObject



89
90
91
92
93
94
# File 'lib/barebones/builders/app_builder.rb', line 89

def raise_on_delivery_errors
  file = "config/environments/development.rb"
  gsub_file file, "config.action_mailer.raise_delivery_errors = false" do |match|
    "config.action_mailer.raise_delivery_errors = true"
  end
end

#readmeObject

Overrides



6
7
8
# File 'lib/barebones/builders/app_builder.rb', line 6

def readme
  template "README.md.erb", "README.md"
end

#set_gemsetObject



40
41
42
# File 'lib/barebones/builders/app_builder.rb', line 40

def set_gemset
  create_file ".ruby-gemset", "#{app_name.parameterize.underscore}"
end

#set_ruby_versionObject

Custom



36
37
38
# File 'lib/barebones/builders/app_builder.rb', line 36

def set_ruby_version
  create_file ".ruby-version", "#{Barebones::RUBY_VERSION}"
end

#setup_autoload_pathsObject



44
45
46
47
48
49
50
51
# File 'lib/barebones/builders/app_builder.rb', line 44

def setup_autoload_paths
  application_class_end_line = "#{spaces(2)}end\nend"
  inject_into_file "config/application.rb", 
    before: application_class_end_line do
      "\n#{spaces(4)}# Autoload 'lib' folder\n"\
      "#{spaces(4)}config.autoload_paths += Dir[\"\#{config.root}/lib/**/\"]\n"
  end
end

#setup_ojObject



57
58
59
# File 'lib/barebones/builders/app_builder.rb', line 57

def setup_oj
  template "multi_json.rb", "config/initializers/multi_json.rb"
end