-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KBP-121 #time 7h implement responders gem and code refactor for app b…
…uilder
- Loading branch information
İsmail Akbudak
committed
Sep 11, 2017
1 parent
bd60c8e
commit 74e8468
Showing
15 changed files
with
224 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'pathname' | ||
|
||
require File.expand_path(File.join('..', 'lib', 'cybele', 'generators', 'app_generator'), File.dirname(__FILE__)) | ||
require File.expand_path(File.join('..', 'lib', 'cybele', 'app_builder'), File.dirname(__FILE__)) | ||
require File.expand_path(File.join('..', 'lib', 'cybele', 'version'), File.dirname(__FILE__)) | ||
source_path = (Pathname.new(__FILE__).dirname + '../lib').expand_path | ||
$LOAD_PATH << source_path | ||
|
||
require 'cybele' | ||
|
||
if ARGV.empty? | ||
puts 'Please provide a path for the new application' | ||
puts | ||
puts 'See --help for more info' | ||
exit 0 | ||
elsif ['-v', '--version'].include? ARGV[0] | ||
elsif %w[-v --version].include? ARGV[0] | ||
puts Cybele::VERSION | ||
exit 0 | ||
end | ||
|
||
templates_root = File.expand_path(File.join('..', 'templates'), File.dirname(__FILE__)) | ||
Cybele::AppGenerator.source_root templates_root | ||
Cybele::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root | ||
Cybele::AppGenerator.start | ||
root = File.expand_path(File.join('..', 'templates'), File.dirname(__FILE__)) | ||
Cybele::AppGenerator.source_root root | ||
Cybele::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << root | ||
Cybele::AppGenerator.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Cybele | ||
module Helpers | ||
private | ||
|
||
def replace_in_file(relative_path, find, replace) | ||
path = File.join(destination_root, relative_path) | ||
contents = IO.read(path) | ||
unless contents.gsub!(find, replace) | ||
raise "#{find.inspect} not found in #{relative_path}" | ||
end | ||
File.open(path, 'w') { |file| file.write(contents) } | ||
end | ||
|
||
def template_content(file) | ||
File.read(File.expand_path(find_in_source_paths(file))) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Cybele | ||
module Helpers | ||
module Responders | ||
def configure_responders | ||
# Add gems | ||
append_file('Gemfile', template_content('responders_Gemfile.erb')) | ||
run_bundle | ||
|
||
# Add initializers | ||
bundle_command 'exec rails generate responders:install' | ||
|
||
# Add js and json to respond :html | ||
replace_in_file 'app/controllers/application_controller.rb', | ||
'respond_to :html', | ||
'respond_to :html, :js, :json' | ||
replace_in_file 'app/controllers/application_controller.rb', | ||
'require "application_responder"', | ||
"require 'application_responder'" | ||
|
||
# Remove comments in locale/responders.yml | ||
uncomment_lines 'config/locales/responders.en.yml', /alert:/ | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
module Cybele | ||
module Helpers | ||
module Sidekiq | ||
def configure_sidekiq | ||
# Add gems | ||
append_file('Gemfile', template_content('sidekiq_Gemfile.erb')) | ||
|
||
create_sidekiq_files | ||
|
||
# Add sidekiq routes to routes | ||
prepend_file 'config/routes.rb', | ||
template_content('sidekiq_routes_require.erb') | ||
inject_into_file 'config/routes.rb', | ||
template_content('sidekiq_routes_mount.erb'), | ||
after: 'Rails.application.routes.draw do' | ||
end | ||
|
||
private | ||
|
||
def create_sidekiq_files | ||
# Initialize files | ||
template 'sidekiq.rb.erb', | ||
'config/initializers/sidekiq.rb', | ||
force: true | ||
# Add tasks | ||
template 'sidekiq.rake.erb', | ||
'lib/tasks/sidekiq.rake', | ||
force: true | ||
|
||
# Add sidekiq.yml | ||
template 'sidekiq.yml.erb', | ||
'config/sidekiq.yml', | ||
force: true | ||
|
||
# Add sidekiq_schedule.yml | ||
template 'sidekiq_schedule.yml.erb', | ||
'config/sidekiq_schedule.yml', | ||
force: true | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe 'Create new project without default configuration' do | ||
before(:all) do | ||
drop_dummy_database | ||
remove_project_directory | ||
run_cybele('--database=sqlite3 --skip-create-database --skip-sidekiq') | ||
setup_app_dependencies | ||
end | ||
|
||
it 'uses sqlite3 instead of default pg in Gemfile' do | ||
gemfile_file = content('Gemfile') | ||
expect(gemfile_file).not_to match(/^gem 'pg'/) | ||
expect(gemfile_file).to match(/^gem 'sqlite3'/) | ||
end | ||
|
||
it 'uses sqlite3 database template' do | ||
database_file = content('config/database.yml') | ||
expect(database_file).to match(/^default: &default/) | ||
expect(database_file).to match(/adapter: sqlite3/) | ||
end | ||
|
||
it 'do not use sidekiq' do | ||
gemfile_file = content('Gemfile') | ||
expect(gemfile_file).not_to match(/^gem 'sidekiq'/) | ||
expect(gemfile_file).not_to match(/^gem 'sidekiq-cron'/) | ||
expect(gemfile_file).not_to match(/^gem 'cocaine'/) | ||
|
||
expect(File).not_to exist(file_project_path('config/sidekiq.yml')) | ||
|
||
expect(File).not_to exist(file_project_path('config/sidekiq_schedule.yml')) | ||
expect(File).not_to exist(file_project_path('config/initializers/sidekiq.rb')) | ||
expect(File).not_to exist(file_project_path('lib/tasks/sidekiq.rake')) | ||
|
||
routes_file = content('config/routes.rb') | ||
expect(routes_file).not_to match("^require 'sidekiq/web'") | ||
expect(routes_file).not_to match("^require 'sidekiq/cron/web'") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.