Skip to content

Commit

Permalink
Merged in feature/integrate_recipient_interceptor_gem (pull request #5)
Browse files Browse the repository at this point in the history
KBP-125 KBP-126 KBP-128 KBP-127 KBP-136Feature/integrate recipient interceptor gem

Approved-by: İsmail Akbudak <[email protected]>
Approved-by: Fatih Avsan <[email protected]>
  • Loading branch information
Hamdi Bayhan committed Oct 25, 2017
2 parents 5efa2dc + e6d287c commit 3f132b4
Show file tree
Hide file tree
Showing 27 changed files with 296 additions and 17 deletions.
14 changes: 11 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
AllCops:
Includes:
Include:
- 'Rakefile'
- 'Gemfile'
Excludes:
Exclude:
- tmp/**/**/**/**

Documentation:
Enabled: false

Metrics/LineLength:
Max: 90
Max: 110
Exclude:
- 'Gemfile'
- 'cybele.gemspec'

Metrics/ClassLength:
Exclude:
- 'lib/cybele/generators/app_generator.rb'

Style/AccessorMethodName:
Exclude:
- 'lib/cybele/generators/app_generator.rb'
Expand All @@ -38,3 +42,7 @@ Style/FrozenStringLiteralComment:
Style/IndentHeredoc:
Exclude:
- 'spec/features/cli_help_spec.rb'

Naming/HeredocDelimiterNaming:
Exclude:
- 'spec/features/cli_help_spec.rb'
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@ Before generating your application, you will need:

First you should install the cybele gem than you can use it for creating new gem.

```ruby
gem install cybele
cybele project_name
```
```ruby
gem install cybele
cybele project_name
```

When the initialization is completed, there will be some required settings.

* Set .env.local variables
* Set access_token in config/initializers/rollbar.rb
* Set ENV['ROLLBAR_ACCESS_TOKEN'] for Rollbar.
* If Sidekiq will be use, you must open sidekiq option in config/initializers/rollbar.rb like the following:
```ruby
config.use_sidekiq 'queue' => 'default'
```
* If you don't want to use Rollbar in development environment, you can disable for development environment in
in config/initializers/rollbar.rb
* If you want to sign up email notification in staging environment, you can add mails like the following:
```ruby
[Settings.email.sandbox, 'user1@example.com', 'user2@example.com']
```
* Set default values for is_active, time_zone variable using in User and Admin model migrations db/migrate/*.rb
* Change username and password in config/settings.yml
* In public folder run this command ln -s ../VERSION.txt VERSION.txt
Expand Down
3 changes: 3 additions & 0 deletions lib/cybele.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
require 'cybele/version'
require 'cybele/generators/app_generator'
require 'cybele/helpers'
require 'cybele/helpers/staging'
require 'cybele/helpers/sidekiq'
require 'cybele/helpers/responders'
require 'cybele/helpers/simple_form'
require 'cybele/helpers/recipient_interceptor'
require 'cybele/app_builder'
24 changes: 24 additions & 0 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
module Cybele
class AppBuilder < Rails::AppBuilder
include Cybele::Helpers
include Cybele::Helpers::Staging
include Cybele::Helpers::Sidekiq
include Cybele::Helpers::Responders
include Cybele::Helpers::SimpleForm
include Cybele::Helpers::RecipientInterceptor

def readme
template 'README.md.erb',
Expand All @@ -17,6 +20,11 @@ def remove_readme_rdoc
force: true
end

def add_gems
# Add gems
append_file('Gemfile', template_content('Gemfile.erb'))
end

def add_editor_config
copy_file 'editorconfig', '.editorconfig'
end
Expand All @@ -34,5 +42,21 @@ def use_postgres_config_template
def create_database
bundle_command 'exec rake db:create db:migrate'
end

def generate_config
generate 'config:install'
run 'cp config/settings/development.yml config/settings/staging.yml'
append_file('config/settings.yml', template_content('settings.yml.erb'))
end

def generate_rollbar
generate 'rollbar'
end

private

def configure_environment(rails_env, config)
inject_into_file("config/environments/#{rails_env}.rb", "\n#{config}", before: "\nend")
end
end
end
45 changes: 45 additions & 0 deletions lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class AppGenerator < Rails::Generators::AppGenerator
default: false,
group: :cybele,
desc: 'Skip sidekiq integration. Default: don\'t skip'
class_option :skip_simple_form,
type: :boolean,
aliases: nil,
default: false,
group: :cybele,
desc: 'Skip simple_form integration. Default: don\'t skip'

def initialize(*args)
super
Expand All @@ -54,9 +60,17 @@ def initialize(*args)
option_with_ask_limited(:database, DATABASES)
option_with_ask_yes(:skip_create_database)
option_with_ask_yes(:skip_sidekiq)
option_with_ask_yes(:skip_simple_form)
@options.freeze
end

def customize_gemfile
say 'Customize gem file', :green
build :add_gems
build :add_simple_form_gem unless @options[:skip_simple_form]
bundle_command 'install --binstubs=bin/stubs'
end

def setup_editor_config
say 'Add .editor_config file', :green
build :add_editor_config
Expand All @@ -72,6 +86,11 @@ def remove_files_we_dont_need
build :remove_readme_rdoc
end

def setup_config
say 'Generate config', :green
build :generate_config
end

def setup_database
if @options[:database] == 'postgresql'
say 'Set up postgresql template', :green
Expand All @@ -94,6 +113,32 @@ def setup_responders
build :configure_responders
end

def setup_staging_environment
say 'Setting up the staging environment', :green
build :setup_staging_environment
end

def configure_recipient_interceptor
say 'Setup mail settings with recipient_interceptor in staging', :green
build :configure_recipient_interceptor
end

def setup_rollbar
say 'Generate rollbar', :green
build :generate_rollbar
end

def setup_simple_form
return if @options[:skip_simple_form]
say 'Setting up simple_form', :green
build :configure_simple_form
end

def add_staging_secret_key
say 'Add staging secret key to secret.yml file', :green
build :add_staging_secret_key_to_secrets_yml
end

def goodbye
say 'Congratulations! That\'s all...', :green
end
Expand Down
16 changes: 16 additions & 0 deletions lib/cybele/helpers/recipient_interceptor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Cybele
module Helpers
module RecipientInterceptor
def configure_recipient_interceptor
# Add recipient_interceptor staging settings to staging environment file
configure_environment 'staging',
template_content('recipient_interceptor/recipient_interceptor_staging.rb.erb')
# Add recipient_interceptor staging settings to staging environment file
append_file 'config/settings.yml',
template_content('recipient_interceptor/recipient_interceptor_settings.yml.erb')
end
end
end
end
2 changes: 1 addition & 1 deletion lib/cybele/helpers/responders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Helpers
module Responders
def configure_responders
# Add gems
append_file('Gemfile', template_content('responders_Gemfile.erb'))
append_file('Gemfile', template_content('responders/responders_Gemfile.erb'))
run_bundle

# Add initializers
Expand Down
14 changes: 7 additions & 7 deletions lib/cybele/helpers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@ module Helpers
module Sidekiq
def configure_sidekiq
# Add gems
append_file('Gemfile', template_content('sidekiq_Gemfile.erb'))
append_file('Gemfile', template_content('sidekiq/sidekiq_Gemfile.erb'))

create_sidekiq_files

# Add sidekiq routes to routes
prepend_file 'config/routes.rb',
template_content('sidekiq_routes_require.erb')
template_content('sidekiq/sidekiq_routes_require.erb')
inject_into_file 'config/routes.rb',
template_content('sidekiq_routes_mount.erb'),
template_content('sidekiq/sidekiq_routes_mount.erb'),
after: 'Rails.application.routes.draw do'
end

private

def create_sidekiq_files
# Initialize files
template 'sidekiq.rb.erb',
template 'sidekiq/sidekiq.rb.erb',
'config/initializers/sidekiq.rb',
force: true
# Add tasks
template 'sidekiq.rake.erb',
template 'sidekiq/sidekiq.rake.erb',
'lib/tasks/sidekiq.rake',
force: true

# Add sidekiq.yml
template 'sidekiq.yml.erb',
template 'sidekiq/sidekiq.yml.erb',
'config/sidekiq.yml',
force: true

# Add sidekiq_schedule.yml
template 'sidekiq_schedule.yml.erb',
template 'sidekiq/sidekiq_schedule.yml.erb',
'config/sidekiq_schedule.yml',
force: true
end
Expand Down
21 changes: 21 additions & 0 deletions lib/cybele/helpers/simple_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Cybele
module Helpers
module SimpleForm
def configure_simple_form
# Run the simple_form generator
bundle_command 'exec rails generate simple_form:install --bootstrap -force'
# Remove simple_form english file
remove_file 'config/locales/simple_form.en.yml', force: true
# Remove simple_form turkish file
copy_file 'config/locales/simple_form.tr.yml', 'config/locales/simple_form.tr.yml'
end

def add_simple_form_gem
# Add simple_form gem
append_file('Gemfile', template_content('simple_form/simple_form_Gemfile.erb'))
end
end
end
end
15 changes: 15 additions & 0 deletions lib/cybele/helpers/staging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Cybele
module Helpers
module Staging
def setup_staging_environment
run 'cp config/environments/production.rb config/environments/staging.rb'
end

def add_staging_secret_key_to_secrets_yml
append_file 'config/secrets.yml', template_content('secrets.yml.erb')
end
end
end
end
52 changes: 52 additions & 0 deletions spec/features/new_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,56 @@
expect(locale_file).to match('update:')
expect(locale_file).to match('destroy:')
end

it 'uses rollbar' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'rollbar'/)

config_file = content('config/initializers/rollbar.rb')
expect(config_file).to match(/^Rollbar.configure/)
end

it 'uses config and staging file' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'config'/)

config_development_file = content('config/environments/development.rb')
expect(config_development_file).to match(/^Rails.application.configure/)

config_staging_file = content('config/environments/staging.rb')
expect(config_staging_file).to match(/^Rails.application.configure/)

config_production_file = content('config/environments/production.rb')
expect(config_production_file).to match(/^Rails.application.configure/)

config_test_file = content('config/environments/test.rb')
expect(config_test_file).to match(/^Rails.application.configure/)
end

it 'uses recipient_interceptor' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'recipient_interceptor'/)

config_staging_file = content('config/environments/staging.rb')
expect(config_staging_file).to match('RecipientInterceptor.new')
end

it 'uses simple_form' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'simple_form'/)

config_simple_form_file = content('config/initializers/simple_form.rb')
expect(config_simple_form_file).to match(/^SimpleForm.setup/)

simple_form_bootstrap_file = content('config/initializers/simple_form_bootstrap.rb')
expect(simple_form_bootstrap_file).to match(/^SimpleForm.setup/)

simple_form_tr_yml_file = content('config/locales/simple_form.tr.yml')
expect(simple_form_tr_yml_file).to match('simple_form')
end

it 'make control secret_key_base for staging' do
secret_file = content('config/secrets.yml')
expect(secret_file).to match('staging')
end
end
Loading

0 comments on commit 3f132b4

Please sign in to comment.