Skip to content

Instantly share code, notes, and snippets.

@galaydaroman
Created April 27, 2017 03:11
Show Gist options
  • Save galaydaroman/ed2f6871074d579c83ea77124dfbb1ce to your computer and use it in GitHub Desktop.
Save galaydaroman/ed2f6871074d579c83ea77124dfbb1ce to your computer and use it in GitHub Desktop.
# engines file strucuture at CD
# each stuff should be namespaced with, for example, `my_engine`
- engines
+ my_engine
+ app
+ assets
+ images
+ my_engine
image.png
+ javascripts
+ my_engine
application.coffee
+ stylesheets
+ my_engine
application.sass
+ controllers
+ my_engine
application_controller.rb
registration_controller.rb
+ models
+ my_engine
registration.rb
bank_account.rb
+ services
+ my_engine
service1.rb
service2.rb
+ helpers
+ my_engine
application_helper.rb
+ views
+ my_engine
+ registration
show.html.slim
apply.html.slim
+ lib
+ my_engine
engine.rb
version.rb
hash_digger.rb # for example
<another files that we have at lib folder in spacq>
my_engine.rb
+ config
routes.rb
Gemfile
my_engine.gemspec
##################
### File contents
###################
# Gemfile at CD
gem 'my_engine', '~> 1.0.0', path: 'engines/my_engine'
# engines/my_engine/my_engine.gemspec
$:.push File.expand_path('../lib', __FILE__)
require 'my_engine/version'
Gem::Specification.new do |s|
s.name = 'my_engine'
s.version = MyEngine::VERSION
s.authors = ['OppLoans']
s.email = %w()
s.homepage = 'https://github.com/Opploans/F'
s.summary = 'Engine provide registration process'
s.description = 'Engine provide registration process'
s.files = Dir['{app,config,lib}/**/*']
s.add_dependency 'rails'
# other dependencies or development dependencies
end
# engines/my_engine/Gemfile
source 'http://rubygems.org'
gemspec
# engines/my_engine/lib/my_engine.rb
module MyEngine
end
# engines/my_engine/lib/my_engine/version.rb
module MyEngine
VERSION = '1.0.0'
end
# engines/my_engine/lib/my_engine/engine.rb
module MyEngine
class Engine < Rails::Engine
isolate_namespace MyEngine
paths = Dir["#{config.root}/lib/"]
paths << "#{config.root}/app/services"
config.autoload_paths += paths
config.eager_load_paths += paths
initializer :asset_precompile_paths do |app|
app.config.assets.precompile += %w(
my_engine/application.js
my_engine/application.css
my_engine/another.js
)
end
# to initialize something before engine starts (edge cases)
config.to_prepare do
require 'my_engine/hash_digger'
end
end
end
# engines/my_engine/config/routes.rb
MyEngine::Engine.routes.draw do
resource :registration, only: :show
end
# mounting engine at CD routes
# config/routes.rb
Rails.application.routes.draw do
# ...
mount MyEngine::Engine => '/register', as: :my_engine
end
# engines/my_engine/app/controllers/my_engine/application_controller.rb
module MyEngine
class ApplicationController < ApplicationController
end
end
# engines/my_engine/app/controllers/my_engine/registration_controller.rb
module MyEngine
class RegistrationController < MyEngine::ApplicationController
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment