SlideShare a Scribd company logo
Namespace Less Engine
 reuse your projects should be a piece of cake!!

                 Shaokun Wu
            shaokun.wu@gmail.com
What’s wrong with
  Namespace
• Things like Devise are very very COOL!!!!!!
• But we just want to reuse our own
  projects

• And we never will release it as a library for
  people to use
•   we need something could be done in your life

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
   :rememberable, :trackable, :token_authenticatable, :validatable,
   :recoverable, :rememberable, :trackable, :validatable
end



•   that code costs you >1 week, but you only got paid 100
    RMB???????

•   and you have a whole projects to be rewritten in that
    way???????????????????????????????????
What we get for
           Namespace less?
•   reuse your projects (not just a small part of code)
    •   for example, you are a site building company
    •   you have copy/paste your cms, news system, fancy image uploader, wysiwyg editor,
        navigation config...
    •   but every client just wants a fancy different looking...
•   easy to inherits & override anything
    •   controllers
                                                     Hey, I am still copy & paste.
    •   models
                                                    How is the Engine?
    •   views?
    •   helper
•   write code without namespace
    •   MyAwsomeEngine::MyAwsomeModel
    •   MyAwsomeModel                                                  I am still learning the Devise
                                                                   code structure.
•   something robust, not monkey hacking
                                                                       It just updates again...
How?
• Add Namespace less placeholders for
  models & controllers

• Do inline Namespace::ClassName
  definition

• Write code without Namespace
• That’s probably all...
in your engine:
/app/models/department.rb


in your project:
/app/models/department.rb




           Which one will be used?
in your engine:
/app/models/hr/department.rb



in your project:
/app/models/department.rb

class department < Hr::Department
end

                               To fix it!
in your engine:
/app/models/hr/department.rb
/app/models/department.rb


in your project:
/app/models/department.rb

class department < Hr::Department
end

                  To fix it, also make
                 engine not complain!
module Hr
 class DepartmentsController < ApplicationController
   def index
    @departments = Department.all # Hr::Department
   end
 end
end

class Hr::DepartmentsController < ApplicationController
  def index
   @departments = Department.all # Department
  end
end
A model override
    sample
class Hr::Employee < ActiveRecord::Base
  def full_name
   [first_name, last_name].join(" ")
   # Shaokun Wu
  end
end
class Employee < Hr::Employee
  def full_name
   [last_name, first_name].join
   # 伍少坤
 end
Controllers


• The same as models...
What a about View?

• You cannot inherits your view


• But you could override them
Helper
• Not so sure, perhaps something like...
 Module Hr::ApplicationHelper
  def hello_world; end
 end


 Module ApplicationHelper
  include Hr::ApplicationHelper

  def hello_world
  end
 end
Find a better place for
  the placeholder files

class MyEngine < Rails::Engine
  paths["app/controllers"] << "lib/placeholders/controllers"
end
How to use the engine

• in your Gemfile
         gem 'hr', :path => "../hr"

• then
          $ bundle install

• copy the migration files
          $ rake hr_engine:install:migrations
Some Tips
•   add your engine as a submodule instead of a pure Gem
    •   your engine is not perfect
    •   bundle still cannot handle same name of gem in different
        group??
•   write engine rake task to generate models & controllers in your
    projects
•   try with mongoid, but be careful of the namespace
    •   class Department < Hr::Department
    •   # still get hr_departments as the collection name...
    •   # of course, you could set the collection name in mongoid :)
Read this carefully


• http://api.rubyonrails.org/classes/Rails/
  Engine.html
The code here


• https://github.com/shaokun/nl-engine

More Related Content

What's hot

Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)
Fwdays
 
Brief Introduction to Ember
Brief Introduction to EmberBrief Introduction to Ember
Brief Introduction to Ember
Vinay B
 
Introduce cucumber
Introduce cucumberIntroduce cucumber
Introduce cucumber
Bachue Zhou
 
The Skinny on Slim
The Skinny on SlimThe Skinny on Slim
The Skinny on Slim
Eric Mulligan
 
Ruby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter BootstrapRuby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter Bootstrap
Marcio Marinho
 
Gemboys
GemboysGemboys
Gemboys
Filippo Dino
 
React.js for Rails Developers
React.js for Rails DevelopersReact.js for Rails Developers
React.js for Rails Developers
Arkency
 
The Asynchronous Pattern (for beginners)
The Asynchronous Pattern (for beginners)The Asynchronous Pattern (for beginners)
The Asynchronous Pattern (for beginners)
Andrea Tino
 
Spring
SpringSpring
Spring
alex.albu
 
Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012
Dimitri de Putte
 
React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016
Justin Gordon
 
Reacting to the Isomorphic Buzz
Reacting to the Isomorphic BuzzReacting to the Isomorphic Buzz
Reacting to the Isomorphic Buzz
Bruce Coddington
 
Rails Engine :: modularize you app
Rails Engine :: modularize you appRails Engine :: modularize you app
Rails Engine :: modularize you app
Muntasim Ahmed
 
CUCUMBER - Making BDD Fun
CUCUMBER - Making BDD FunCUCUMBER - Making BDD Fun
CUCUMBER - Making BDD Fun
SQABD
 
Marrying angular rails
Marrying angular railsMarrying angular rails
Marrying angular rails
Volker Tietz
 
Ramaze - The Underrated Ruby Web Framework
Ramaze - The Underrated Ruby Web FrameworkRamaze - The Underrated Ruby Web Framework
Ramaze - The Underrated Ruby Web Framework
luccastera
 
Scala scripting-slides
Scala scripting-slidesScala scripting-slides
Scala scripting-slides
Daniel Sebban
 
EmberJS BucharestJS
EmberJS BucharestJSEmberJS BucharestJS
EmberJS BucharestJS
Remus Rusanu
 
Story Driven Development With Cucumber
Story Driven Development With CucumberStory Driven Development With Cucumber
Story Driven Development With Cucumber
Sean Cribbs
 
Building CLR/H Registration Site with ASP.NET MVC4 and EF4CodeFirst
Building CLR/H Registration Site with ASP.NET MVC4 and EF4CodeFirstBuilding CLR/H Registration Site with ASP.NET MVC4 and EF4CodeFirst
Building CLR/H Registration Site with ASP.NET MVC4 and EF4CodeFirstJun-ichi Sakamoto
 

What's hot (20)

Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)
 
Brief Introduction to Ember
Brief Introduction to EmberBrief Introduction to Ember
Brief Introduction to Ember
 
Introduce cucumber
Introduce cucumberIntroduce cucumber
Introduce cucumber
 
The Skinny on Slim
The Skinny on SlimThe Skinny on Slim
The Skinny on Slim
 
Ruby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter BootstrapRuby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter Bootstrap
 
Gemboys
GemboysGemboys
Gemboys
 
React.js for Rails Developers
React.js for Rails DevelopersReact.js for Rails Developers
React.js for Rails Developers
 
The Asynchronous Pattern (for beginners)
The Asynchronous Pattern (for beginners)The Asynchronous Pattern (for beginners)
The Asynchronous Pattern (for beginners)
 
Spring
SpringSpring
Spring
 
Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012
 
React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016
 
Reacting to the Isomorphic Buzz
Reacting to the Isomorphic BuzzReacting to the Isomorphic Buzz
Reacting to the Isomorphic Buzz
 
Rails Engine :: modularize you app
Rails Engine :: modularize you appRails Engine :: modularize you app
Rails Engine :: modularize you app
 
CUCUMBER - Making BDD Fun
CUCUMBER - Making BDD FunCUCUMBER - Making BDD Fun
CUCUMBER - Making BDD Fun
 
Marrying angular rails
Marrying angular railsMarrying angular rails
Marrying angular rails
 
Ramaze - The Underrated Ruby Web Framework
Ramaze - The Underrated Ruby Web FrameworkRamaze - The Underrated Ruby Web Framework
Ramaze - The Underrated Ruby Web Framework
 
Scala scripting-slides
Scala scripting-slidesScala scripting-slides
Scala scripting-slides
 
EmberJS BucharestJS
EmberJS BucharestJSEmberJS BucharestJS
EmberJS BucharestJS
 
Story Driven Development With Cucumber
Story Driven Development With CucumberStory Driven Development With Cucumber
Story Driven Development With Cucumber
 
Building CLR/H Registration Site with ASP.NET MVC4 and EF4CodeFirst
Building CLR/H Registration Site with ASP.NET MVC4 and EF4CodeFirstBuilding CLR/H Registration Site with ASP.NET MVC4 and EF4CodeFirst
Building CLR/H Registration Site with ASP.NET MVC4 and EF4CodeFirst
 

Viewers also liked

More to RoC weibo
More to RoC weiboMore to RoC weibo
More to RoC weibo
shaokun
 
Rest Ruby On Rails
Rest Ruby On RailsRest Ruby On Rails
Rest Ruby On Railsshaokun
 
Rack
RackRack
Rack
shaokun
 
WebSocket 实时推特流
WebSocket 实时推特流WebSocket 实时推特流
WebSocket 实时推特流
shaokun
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发
shaokun
 
VIM for the PHP Developer
VIM for the PHP DeveloperVIM for the PHP Developer
VIM for the PHP Developer
John Congdon
 
iOS 图片浏览器 DIY
iOS 图片浏览器 DIYiOS 图片浏览器 DIY
iOS 图片浏览器 DIY
shaokun
 
Git flow
Git flowGit flow
Git flow
shaokun
 
História regional povoamento primeiros tempos
História     regional   povoamento primeiros temposHistória     regional   povoamento primeiros tempos
História regional povoamento primeiros tempos
Marcelo Abreu Gomes
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular application
mirrec
 
Summer Sounds 2007
Summer Sounds 2007Summer Sounds 2007
Summer Sounds 2007guest6e0d
 
Seven Best Positions
Seven Best PositionsSeven Best Positions
Seven Best Positionsguest7d46732
 

Viewers also liked (14)

More to RoC weibo
More to RoC weiboMore to RoC weibo
More to RoC weibo
 
Rest Ruby On Rails
Rest Ruby On RailsRest Ruby On Rails
Rest Ruby On Rails
 
Rack
RackRack
Rack
 
WebSocket 实时推特流
WebSocket 实时推特流WebSocket 实时推特流
WebSocket 实时推特流
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发
 
VIM for the PHP Developer
VIM for the PHP DeveloperVIM for the PHP Developer
VIM for the PHP Developer
 
iOS 图片浏览器 DIY
iOS 图片浏览器 DIYiOS 图片浏览器 DIY
iOS 图片浏览器 DIY
 
Git flow
Git flowGit flow
Git flow
 
História regional povoamento primeiros tempos
História     regional   povoamento primeiros temposHistória     regional   povoamento primeiros tempos
História regional povoamento primeiros tempos
 
Caminata digital3 02_07_2012
Caminata digital3 02_07_2012Caminata digital3 02_07_2012
Caminata digital3 02_07_2012
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular application
 
Singaporean Economy, Today By Talha Lodhi
Singaporean Economy, Today By Talha LodhiSingaporean Economy, Today By Talha Lodhi
Singaporean Economy, Today By Talha Lodhi
 
Summer Sounds 2007
Summer Sounds 2007Summer Sounds 2007
Summer Sounds 2007
 
Seven Best Positions
Seven Best PositionsSeven Best Positions
Seven Best Positions
 

Similar to Namespace less engine

Features, Exportables & You
Features, Exportables & YouFeatures, Exportables & You
Features, Exportables & You
jskulski
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Mike Schinkel
 
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009Yasuko Ohba
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
Taylor Lovett
 
Angularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupAngularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupGoutam Dey
 
Designing True Cross-Platform Apps
Designing True Cross-Platform AppsDesigning True Cross-Platform Apps
Designing True Cross-Platform Apps
FITC
 
Browser Internals for JS Devs: WebU Toronto 2016 by Alex Blom
Browser Internals for JS Devs: WebU Toronto 2016 by Alex BlomBrowser Internals for JS Devs: WebU Toronto 2016 by Alex Blom
Browser Internals for JS Devs: WebU Toronto 2016 by Alex Blom
Alex Blom
 
Ember App Kit & The Ember Resolver
Ember App Kit & The Ember ResolverEmber App Kit & The Ember Resolver
Ember App Kit & The Ember Resolvertboyt
 
Gradle Again
Gradle AgainGradle Again
Gradle Again
Eugen Martynov
 
General Assembly Workshop: Advanced JavaScript
General Assembly Workshop: Advanced JavaScriptGeneral Assembly Workshop: Advanced JavaScript
General Assembly Workshop: Advanced JavaScriptSpike Brehm
 
RoR (Ruby on Rails)
RoR (Ruby on Rails)RoR (Ruby on Rails)
RoR (Ruby on Rails)
scandiweb
 
DSpace UI prototype dsember
DSpace UI prototype dsemberDSpace UI prototype dsember
DSpace UI prototype dsember
Bram Luyten
 
Building a Simple Theme Framework
Building a Simple Theme FrameworkBuilding a Simple Theme Framework
Building a Simple Theme Framework
Joe Casabona
 
Advanced Web Technology.pptx
Advanced Web Technology.pptxAdvanced Web Technology.pptx
Advanced Web Technology.pptx
ssuser35fdf2
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done Right
Mariusz Nowak
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
murtazahaveliwala
 
Angular4 kickstart
Angular4 kickstartAngular4 kickstart
Angular4 kickstart
Foyzul Karim
 
DevOps, A brief introduction to Vagrant & Ansible
DevOps, A brief introduction to Vagrant & AnsibleDevOps, A brief introduction to Vagrant & Ansible
DevOps, A brief introduction to Vagrant & Ansible
Arnaud LEMAIRE
 
Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!
mold
 

Similar to Namespace less engine (20)

Features, Exportables & You
Features, Exportables & YouFeatures, Exportables & You
Features, Exportables & You
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)
 
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
 
Angular js
Angular jsAngular js
Angular js
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
Angularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupAngularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetup
 
Designing True Cross-Platform Apps
Designing True Cross-Platform AppsDesigning True Cross-Platform Apps
Designing True Cross-Platform Apps
 
Browser Internals for JS Devs: WebU Toronto 2016 by Alex Blom
Browser Internals for JS Devs: WebU Toronto 2016 by Alex BlomBrowser Internals for JS Devs: WebU Toronto 2016 by Alex Blom
Browser Internals for JS Devs: WebU Toronto 2016 by Alex Blom
 
Ember App Kit & The Ember Resolver
Ember App Kit & The Ember ResolverEmber App Kit & The Ember Resolver
Ember App Kit & The Ember Resolver
 
Gradle Again
Gradle AgainGradle Again
Gradle Again
 
General Assembly Workshop: Advanced JavaScript
General Assembly Workshop: Advanced JavaScriptGeneral Assembly Workshop: Advanced JavaScript
General Assembly Workshop: Advanced JavaScript
 
RoR (Ruby on Rails)
RoR (Ruby on Rails)RoR (Ruby on Rails)
RoR (Ruby on Rails)
 
DSpace UI prototype dsember
DSpace UI prototype dsemberDSpace UI prototype dsember
DSpace UI prototype dsember
 
Building a Simple Theme Framework
Building a Simple Theme FrameworkBuilding a Simple Theme Framework
Building a Simple Theme Framework
 
Advanced Web Technology.pptx
Advanced Web Technology.pptxAdvanced Web Technology.pptx
Advanced Web Technology.pptx
 
JavaScript Modules Done Right
JavaScript Modules Done RightJavaScript Modules Done Right
JavaScript Modules Done Right
 
Introduction to AngularJs
Introduction to AngularJsIntroduction to AngularJs
Introduction to AngularJs
 
Angular4 kickstart
Angular4 kickstartAngular4 kickstart
Angular4 kickstart
 
DevOps, A brief introduction to Vagrant & Ansible
DevOps, A brief introduction to Vagrant & AnsibleDevOps, A brief introduction to Vagrant & Ansible
DevOps, A brief introduction to Vagrant & Ansible
 
Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!
 

Recently uploaded

Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 

Recently uploaded (20)

Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 

Namespace less engine

  • 1. Namespace Less Engine reuse your projects should be a piece of cake!! Shaokun Wu shaokun.wu@gmail.com
  • 3. • Things like Devise are very very COOL!!!!!! • But we just want to reuse our own projects • And we never will release it as a library for people to use
  • 4. we need something could be done in your life class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :rememberable, :trackable, :token_authenticatable, :validatable, :recoverable, :rememberable, :trackable, :validatable end • that code costs you >1 week, but you only got paid 100 RMB??????? • and you have a whole projects to be rewritten in that way???????????????????????????????????
  • 5. What we get for Namespace less? • reuse your projects (not just a small part of code) • for example, you are a site building company • you have copy/paste your cms, news system, fancy image uploader, wysiwyg editor, navigation config... • but every client just wants a fancy different looking... • easy to inherits & override anything • controllers Hey, I am still copy & paste. • models How is the Engine? • views? • helper • write code without namespace • MyAwsomeEngine::MyAwsomeModel • MyAwsomeModel I am still learning the Devise code structure. • something robust, not monkey hacking It just updates again...
  • 7. • Add Namespace less placeholders for models & controllers • Do inline Namespace::ClassName definition • Write code without Namespace • That’s probably all...
  • 8. in your engine: /app/models/department.rb in your project: /app/models/department.rb Which one will be used?
  • 9. in your engine: /app/models/hr/department.rb in your project: /app/models/department.rb class department < Hr::Department end To fix it!
  • 10. in your engine: /app/models/hr/department.rb /app/models/department.rb in your project: /app/models/department.rb class department < Hr::Department end To fix it, also make engine not complain!
  • 11. module Hr class DepartmentsController < ApplicationController def index @departments = Department.all # Hr::Department end end end class Hr::DepartmentsController < ApplicationController def index @departments = Department.all # Department end end
  • 12. A model override sample class Hr::Employee < ActiveRecord::Base def full_name [first_name, last_name].join(" ") # Shaokun Wu end end class Employee < Hr::Employee def full_name [last_name, first_name].join # 伍少坤 end
  • 13. Controllers • The same as models...
  • 14. What a about View? • You cannot inherits your view • But you could override them
  • 15. Helper • Not so sure, perhaps something like... Module Hr::ApplicationHelper def hello_world; end end Module ApplicationHelper include Hr::ApplicationHelper def hello_world end end
  • 16. Find a better place for the placeholder files class MyEngine < Rails::Engine paths["app/controllers"] << "lib/placeholders/controllers" end
  • 17. How to use the engine • in your Gemfile gem 'hr', :path => "../hr" • then $ bundle install • copy the migration files $ rake hr_engine:install:migrations
  • 18. Some Tips • add your engine as a submodule instead of a pure Gem • your engine is not perfect • bundle still cannot handle same name of gem in different group?? • write engine rake task to generate models & controllers in your projects • try with mongoid, but be careful of the namespace • class Department < Hr::Department • # still get hr_departments as the collection name... • # of course, you could set the collection name in mongoid :)
  • 19. Read this carefully • http://api.rubyonrails.org/classes/Rails/ Engine.html
  • 20. The code here • https://github.com/shaokun/nl-engine

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n