Slide 1

Slide 1 text

Railties INTEGRANDO GEMS COM O RAILS

Slide 2

Slide 2 text

@cantoniodasilva Carlos Antonio

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Devise maintainer

Slide 5

Slide 5 text

SimpleForm maintainer

Slide 6

Slide 6 text

Responders maintainer

Slide 7

Slide 7 text

Rails commiter

Slide 8

Slide 8 text

guru SC

Slide 9

Slide 9 text

Railties INTEGRANDO GEMS COM O RAILS

Slide 10

Slide 10 text

The Road So Far...

Slide 11

Slide 11 text

Rails 2.3

Slide 12

Slide 12 text

Plugins! vendor/plugins

Slide 13

Slide 13 text

script/plugin install git://github.com/SomeGuy/ my_awesome_plugin.git

Slide 14

Slide 14 text

Engines! app/*

Slide 15

Slide 15 text

App Engine

Slide 16

Slide 16 text

module Rails class Plugin # Engines are plugins with an app/ directory. def engine? has_app_directory? end private def has_app_directory? File.directory?(File.join(directory, 'app')) end end end https://github.com/rails/rails/blob/2-3-stable/railties/lib/rails/plugin.rb

Slide 17

Slide 17 text

module Rails class Plugin # Engines are plugins with an app/ directory. def engine? has_app_directory? end private def has_app_directory? File.directory?(File.join(directory, 'app')) end end end https://github.com/rails/rails/blob/2-3-stable/railties/lib/rails/plugin.rb # Engines are plugins with an app/ directory. def engine? has_app_directory? end private def has_app_directory? File.directory?(File.join(directory, 'app')) end

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

app/ models controllers helpers config/ routes.rb

Slide 20

Slide 20 text

module Rails class Plugin def view_path File.join(directory, 'app', 'views') end def controller_path File.join(directory, 'app', 'controllers') end def routing_file File.join(directory, 'config', 'routes.rb') end private def app_paths [ File.join(directory, 'app', 'models'), File.join(directory, 'app', 'helpers'), controller_path, metal_path ] end end end https://github.com/rails/rails/blob/2-3-stable/railties/lib/rails/plugin.rb

Slide 21

Slide 21 text

module Rails class Plugin def view_path File.join(directory, 'app', 'views') end def controller_path File.join(directory, 'app', 'controllers') end def routing_file File.join(directory, 'config', 'routes.rb') end private def app_paths [ File.join(directory, 'app', 'models'), File.join(directory, 'app', 'helpers'), controller_path, metal_path ] end end end https://github.com/rails/rails/blob/2-3-stable/railties/lib/rails/plugin.rb def view_path File.join(directory, 'app', 'views') end def controller_path File.join(directory, 'app', 'controllers') end def routing_file File.join(directory, 'config', 'routes.rb') end private def app_paths [ File.join(directory, 'app', 'models'), File.join(directory, 'app', 'helpers'), controller_path, metal_path ] end

Slide 22

Slide 22 text

Rails Active Record

Slide 23

Slide 23 text

module Rails class Initializer def load_observers if gems_dependencies_loaded && configuration.frameworks.include?(:active_record) ActiveRecord::Base.instantiate_observers end end def initialize_database if configuration.frameworks.include?(:active_record) ActiveRecord::Base.configurations = configuration.database_configuration ActiveRecord::Base.establish_connection end end end end https://github.com/rails/rails/blob/2-3-stable/railties/lib/initializer.rb

Slide 24

Slide 24 text

module Rails class Initializer def load_observers if gems_dependencies_loaded && configuration.frameworks.include?(:active_record) ActiveRecord::Base.instantiate_observers end end def initialize_database if configuration.frameworks.include?(:active_record) ActiveRecord::Base.configurations = configuration.database_configuration ActiveRecord::Base.establish_connection end end end end https://github.com/rails/rails/blob/2-3-stable/railties/lib/initializer.rb if gems_dependencies_loaded && configuration.frameworks.include?(:active_record) ActiveRecord::Base.instantiate_observers end if configuration.frameworks.include?(:active_record) ActiveRecord::Base.configurations = configuration.database_configuration ActiveRecord::Base.establish_connection end

Slide 25

Slide 25 text

module Rails class Initializer private def default_frameworks [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ] end end end https://github.com/rails/rails/blob/2-3-stable/railties/lib/initializer.rb

Slide 26

Slide 26 text

module Rails class Initializer private def default_frameworks [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ] end end end https://github.com/rails/rails/blob/2-3-stable/railties/lib/initializer.rb def default_frameworks [ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ] end

Slide 27

Slide 27 text

ORMs

Slide 28

Slide 28 text

ORMs Sequel MongoMapper DataMapper Mongoid

Slide 29

Slide 29 text

Frágil

Slide 30

Slide 30 text

monkey Patch

Slide 31

Slide 31 text

module Rails class Initializer def process Rails.configuration = configuration check_ruby_version install_gem_spec_stubs set_load_path add_gem_load_paths require_frameworks set_autoload_paths add_plugin_load_paths load_environment preload_frameworks initialize_encoding initialize_database initialize_cache initialize_framework_caches initialize_logger initialize_framework_logging initialize_dependency_mechanism initialize_whiny_nils initialize_time_zone initialize_i18n initialize_framework_settings initialize_framework_views initialize_metal add_support_load_paths check_for_unbuilt_gems load_gems load_plugins https://github.com/rails/rails/blob/2-3-stable/railties/lib/initializer.rb # pick up any gems that plugins depend on add_gem_load_paths load_gems check_gem_dependencies # bail out if gems are missing - note that check_gem_dependencies # will have already called abort() unless $gems_rake_task is set return unless gems_dependencies_loaded load_application_initializers # the framework is now fully initialized after_initialize # Setup database middleware after initializers have run initialize_database_middleware # Prepare dispatcher callbacks and run 'prepare' callbacks prepare_dispatcher # Routing must be initialized after plugins to allow the former to # extend the routes initialize_routing # Observers are loaded after plugins in case Observers or observed # models are modified by plugins. load_observers # Load view path cache load_view_paths # Load application classes load_application_classes # Disable dependency loading during request cycle disable_dependency_loading # Flag initialized Rails.initialized = true end end end

Slide 32

Slide 32 text

Single Responsibility Principle

Slide 33

Slide 33 text

Single Responsibility Principle

Slide 34

Slide 34 text

Rails 3

Slide 35

Slide 35 text

Modularidade

Slide 36

Slide 36 text

Rails Active Record

Slide 37

Slide 37 text

Rails Active Record

Slide 38

Slide 38 text

Rails

Slide 39

Slide 39 text

Rails Action Controller Action Mailer Action View Active Record Active Resource

Slide 40

Slide 40 text

Rails

Slide 41

Slide 41 text

Rails DataMapper Devise RSpec Mongoid etc...

Slide 42

Slide 42 text

Hooks!

Slide 43

Slide 43 text

Rails:: Railtie

Slide 44

Slide 44 text

Configuração & Inicialização

Slide 45

Slide 45 text

Config

Slide 46

Slide 46 text

module Responders class Railtie < ::Rails::Railtie config.responders = ActiveSupport::OrderedOptions.new config.responders.flash_keys = [ :notice, :alert ] # ... end end https://github.com/plataformatec/responders/blob/v0.9.2/lib/responders.rb Responders

Slide 47

Slide 47 text

module MyApp class Application < ::Rails::Application config.responders.flash_keys = [ :success, :failure ] end end

Slide 48

Slide 48 text

Initializers

Slide 49

Slide 49 text

module Responders class Railtie < ::Rails::Railtie config.responders.flash_keys = [ :notice, :alert ] initializer "responders.flash_responder" do |app| Responders::FlashResponder.flash_keys = app.config.responders.flash_keys # ... end end end https://github.com/plataformatec/responders/blob/v0.9.2/lib/responders.rb Responders

Slide 50

Slide 50 text

module CarrierWave class Railtie < Rails::Railtie initializer "carrierwave.setup_paths" do CarrierWave.root = Rails.root.join(Rails.public_path).to_s # ... end end end https://github.com/jnicklas/carrierwave/blob/v0.6.2/lib/carrierwave.rb CarrierWave

Slide 51

Slide 51 text

Initializers + Hooks

Slide 52

Slide 52 text

module MyGem class Railtie < Rails::Railtie config.before_configuration { # Executa antes das configurações do usuário } end end

Slide 53

Slide 53 text

module MyGem class Railtie < Rails::Railtie config.before_initialize { # Depois da config do usuário, mas antes dos # initializers. } end end

Slide 54

Slide 54 text

module MyGem class Railtie < Rails::Railtie config.to_prepare { # cache_classes = false (development) # Roda toda vez antes de recarregar o ambiente. # cache_classes = true (production) # Roda antes da primeira requisição. } end end

Slide 55

Slide 55 text

module MyGem class Railtie < Rails::Railtie config.before_eager_load { # Antes de carregar todo o código da aplicação, # somente com cache_classes true. } end end

Slide 56

Slide 56 text

module MyGem class Railtie < Rails::Railtie config.after_initialize { # Após todos os demais (configs, initializers, etc), # uma única vez antes da primeira requisição. } end end

Slide 57

Slide 57 text

Development before_configuration => Booting WEBrick before_initialize to_prepare after_initialize [...] INFO WEBrick 1.3.1 to_prepare Request... to_prepare Request... to_prepare Production (cache_classes) before_configuration => Booting WEBrick before_initialize to_prepare before_eager_load after_initialize [...] INFO WEBrick 1.3.1 Request... Request...

Slide 58

Slide 58 text

Development before_configuration => Booting WEBrick before_initialize to_prepare after_initialize [...] INFO WEBrick 1.3.1 to_prepare Request... to_prepare Request... to_prepare Production (cache_classes) before_configuration => Booting WEBrick before_initialize to_prepare before_eager_load after_initialize [...] INFO WEBrick 1.3.1 Request... Request...

Slide 59

Slide 59 text

module ActiveRecord class Railtie < Rails::Railtie config.after_initialize do ActiveSupport.on_load(:active_record) do instantiate_observers ActionDispatch::Reloader.to_prepare do ActiveRecord::Base.instantiate_observers end end end end end https://github.com/rails/rails/tree/3-2-stable/activerecord/lib/active_record/railtie.rb Active Record

Slide 60

Slide 60 text

module Rails module Mongoid class Railtie < Rails::Railtie initializer "instantiate observers" do config.after_initialize do ::Mongoid::instantiate_observers ActionDispatch::Reloader.to_prepare do ::Mongoid.instantiate_observers end end end end end end https://github.com/mongoid/mongoid/blob/3.0.0-stable/lib/mongoid/railtie.rb Mongoid

Slide 61

Slide 61 text

module Haml module Rails class Railtie < ::Rails::Railtie config.before_initialize do Haml.init_rails(binding) Haml::Template.options[:format] = :html5 end end end end https://github.com/indirect/haml-rails/blob/v0.3.5/lib/haml-rails.rb Haml

Slide 62

Slide 62 text

Generators

Slide 63

Slide 63 text

simple_form lib generators simple_form install_generator.rb https://github.com/plataformatec/simple_form SimpleForm

Slide 64

Slide 64 text

simple_form lib generators simple_form install_generator.rb Namespace https://github.com/plataformatec/simple_form SimpleForm

Slide 65

Slide 65 text

simple_form lib generators simple_form install_generator.rb Namespace Generator https://github.com/plataformatec/simple_form SimpleForm

Slide 66

Slide 66 text

module SimpleForm module Generators class InstallGenerator < Rails::Generators::Base desc "Copy SimpleForm default files" source_root File.expand_path('../templates', __FILE__) def copy_config directory 'config' end def copy_scaffold_template # ... end end end end https://github.com/plataformatec/simple_form/blob/v2.0.2/lib/generators/simple_form/install_generator.rb SimpleForm

Slide 67

Slide 67 text

rails generate simple_form:install

Slide 68

Slide 68 text

Convenções

Slide 69

Slide 69 text

module MyGem class Railtie < ::Rails::Railtie generators do require "my_gem/generators" end end end

Slide 70

Slide 70 text

Generators + Hooks

Slide 71

Slide 71 text

module ActiveRecord class Railtie < Rails::Railtie config.app_generators.orm :active_record, :migration => true, :timestamps => true end end https://github.com/rails/rails/tree/3-2-stable/activerecord/lib/active_record/railtie.rb Active Record

Slide 72

Slide 72 text

module Rails module Mongoid class Railtie < Rails::Railtie def self.generator config.respond_to?(:app_generators) ? :app_generators : :generators end config.send(generator).orm :mongoid, migration: false end end end https://github.com/mongoid/mongoid/blob/3.0.0-stable/lib/mongoid/railtie.rb Mongoid

Slide 73

Slide 73 text

module RSpec module Rails class Railtie < ::Rails::Railtie generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators generators.integration_tool :rspec generators.test_framework :rspec end end end https://github.com/rspec/rspec-rails/blob/v2.11.0/lib/rspec-rails.rb RSpec

Slide 74

Slide 74 text

module Responders class Railtie < ::Rails::Railtie if config.respond_to?(:app_generators) config.app_generators.scaffold_controller = :responders_controller else config.generators.scaffold_controller = :responders_controller end end end https://github.com/plataformatec/responders/blob/v0.9.2/lib/responders.rb Responders

Slide 75

Slide 75 text

module Haml module Rails class Railtie < ::Rails::Railtie if ::Rails.version.to_f >= 3.1 config.app_generators.template_engine :haml else config.generators.template_engine :haml end end end end https://github.com/indirect/haml-rails/blob/v0.3.5/lib/haml-rails.rb Haml

Slide 76

Slide 76 text

:assets => true :force_plural => false :helper => true :integration_tool => nil :javascripts => true :javascript_engine => :js :orm => false :performance_tool => nil :resource_controller => :controller :resource_route => true :scaffold_controller => :scaffold_controller :stylesheets => true :stylesheet_engine => :css :test_framework => false :template_engine => :erb https://github.com/rails/rails/blob/3-2-stable/railties/lib/rails/generators.rb

Slide 77

Slide 77 text

Console

Slide 78

Slide 78 text

module MyGem class Railtie < Rails::Railtie console do puts "Hello console!" end end end

Slide 79

Slide 79 text

module ActiveRecord class Railtie < Rails::Railtie console do |app| if app.sandbox? require "active_record/railties/console_sandbox" end ActiveRecord::Base.logger = Logger.new(STDERR) end end end https://github.com/rails/rails/tree/3-2-stable/activerecord/lib/active_record/railtie.rb Active Record

Slide 80

Slide 80 text

module PryRails class Railtie < Rails::Railtie console do # ... código para carregar o Pry end end end https://github.com/rweng/pry-rails/blob/master/lib/pry-rails/railtie.rb Pry Rails

Slide 81

Slide 81 text

Rails 4 SPOILER

Slide 82

Slide 82 text

RAILS 4 https://github.com/rails/rails/commit/951b582

Slide 83

Slide 83 text

module PryRails class Railtie < Rails::Railtie console do if Rails::VERSION::MAJOR == 4 Rails.application.config.console = Pry end end end end https://github.com/rweng/pry-rails/blob/master/lib/pry-rails/railtie.rb Pry Rails

Slide 84

Slide 84 text

Rake Tasks

Slide 85

Slide 85 text

module RSpec module Rails class Railtie < ::Rails::Railtie rake_tasks do load "rspec/rails/tasks/rspec.rake" end end end end https://github.com/rspec/rspec-rails/blob/v2.11.0/lib/rspec-rails.rb RSpec

Slide 86

Slide 86 text

module ActiveRecord class Railtie < Rails::Railtie rake_tasks do load "active_record/railties/databases.rake" end end end https://github.com/rails/rails/tree/3-2-stable/activerecord/lib/active_record/railtie.rb Active Record

Slide 87

Slide 87 text

module Rails module Mongoid class Railtie < Rails::Railtie rake_tasks do load "mongoid/railties/database.rake" end end end end https://github.com/mongoid/mongoid/blob/3.0.0-stable/lib/mongoid/railtie.rb Mongoid

Slide 88

Slide 88 text

Framework Loading

Slide 89

Slide 89 text

module MyGem module SimpleFormExtensions def special_input(*) # ... end end end SimpleForm::FormBuilder.send( :include, MyGem::SimpleFormExtensions)

Slide 90

Slide 90 text

module MyGem module SimpleFormExtensions def special_input(*) # ... end end end SimpleForm::FormBuilder.send( :include, MyGem::SimpleFormExtensions)

Slide 91

Slide 91 text

module SimpleForm class FormBuilder end end ActiveSupport.run_load_hooks( :simple_form, SimpleForm::FormBuilder)

Slide 92

Slide 92 text

module MyGem module SimpleFormExtensions def special_input(*) # ... end end end ActiveSupport.on_load(:simple_form) do include MyGem::SimpleFormExtensions end

Slide 93

Slide 93 text

module ActiveRecord class Base end end ActiveSupport.run_load_hooks( :active_record, ActiveRecord::Base) https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/base.rb Active Record

Slide 94

Slide 94 text

module ActiveRecord class Railtie < Rails::Railtie initializer "active_record.initialize_timezone" do ActiveSupport.on_load(:active_record) do self.time_zone_aware_attributes = true self.default_timezone = :utc end end end end https://github.com/rails/rails/tree/3-2-stable/activerecord/lib/active_record/railtie.rb Active Record

Slide 95

Slide 95 text

module MyGem module ActiveRecordExtensions end end ActiveSupport.on_load(:active_record) do include MyGem::ActiveRecordExtensions end

Slide 96

Slide 96 text

ActiveSupport.on_load(:active_record) do include MyGem::ActiveRecordExtensions end ActiveSupport.on_load(:action_controller) do include MyGem::ActionControllerExtensions end

Slide 97

Slide 97 text

Criar uma Railtie?

Slide 98

Slide 98 text

module MyGem class Railtie < Rails::Railtie end end

Slide 99

Slide 99 text

Você nem sempre precisa de uma Railtie!

Slide 100

Slide 100 text

Initializers Railtie: quando?

Slide 101

Slide 101 text

rake tasks Railtie: quando?

Slide 102

Slide 102 text

Expor configs de sua gem Railtie: quando?

Slide 103

Slide 103 text

Extensões para o console Railtie: quando?

Slide 104

Slide 104 text

Generators em outro diretório Railtie: quando?

Slide 105

Slide 105 text

Alterar um generator default Railtie: quando?

Slide 106

Slide 106 text

Rails:: Engine

Slide 107

Slide 107 text

Engine < Railtie

Slide 108

Slide 108 text

Paths + Autoload

Slide 109

Slide 109 text

app/ * assets controllers helpers mailers models views

Slide 110

Slide 110 text

https://github.com/plataformatec/devise/tree/v2.1.2/app

Slide 111

Slide 111 text

config/ environments/ #{Rails.env}.rb initializers/*.rb locales/*.{rb,yml} routes.rb

Slide 112

Slide 112 text

https://github.com/plataformatec/devise/tree/v2.1.2/config

Slide 113

Slide 113 text

lib/ assets/* tasks/*.rake vendor/ assets/*

Slide 114

Slide 114 text

https://github.com/rails/jquery-rails/tree/v2.1.2/vendor/assets/javascripts

Slide 115

Slide 115 text

module MyGem class Railtie < ::Rails::Engine # Você pode alterar os paths padrão. paths.app.controllers << "lib/controllers" end end

Slide 116

Slide 116 text

Criar uma Engine?

Slide 117

Slide 117 text

module MyGem class Railtie < ::Rails::Engine end end

Slide 118

Slide 118 text

module Jquery module Rails class Engine < ::Rails::Engine end end end https://github.com/rails/jquery-rails/blob/v2.1.2/lib/jquery/rails/engine.rb Jquery Rails

Slide 119

Slide 119 text

module Devise class Engine < ::Rails::Engine config.devise = Devise # Force routes to be loaded if we are doing any # eager load. config.before_eager_load { |app| app.reload_routes! } initializer "devise.url_helpers" do Devise.include_helpers(Devise::Controllers) end initializer "devise.omniauth" do |app| # ... end # ... end end https://github.com/plataformatec/devise/blob/v2.1.2/lib/devise/rails.rb Devise

Slide 120

Slide 120 text

Quando eu preciso de uma Engine?

Slide 121

Slide 121 text

Rotas Railtie: quando?

Slide 122

Slide 122 text

Models Railtie: quando?

Slide 123

Slide 123 text

Controllers Railtie: quando?

Slide 124

Slide 124 text

Views Railtie: quando?

Slide 125

Slide 125 text

app/* Railtie: quando?

Slide 126

Slide 126 text

config/* Railtie: quando?

Slide 127

Slide 127 text

Rails:: Plugin

Slide 128

Slide 128 text

Plugin < Engine

Slide 129

Slide 129 text

rails plugin install

Slide 130

Slide 130 text

vendor/plugins

Slide 131

Slide 131 text

init.rb

Slide 132

Slide 132 text

Criar uma Plugin?

Slide 133

Slide 133 text

Você não cria :)

Slide 134

Slide 134 text

module Rails class Plugin < Engine def self.inherited(base) raise "You cannot inherit from Rails::Plugin" end end end https://github.com/rails/rails/blob/3-2-stable/railties/lib/rails/plugin.rb

Slide 135

Slide 135 text

module Rails class Plugin < Engine def self.inherited(base) raise "You cannot inherit from Rails::Plugin" end end end https://github.com/rails/rails/blob/3-2-stable/railties/lib/rails/plugin.rb def self.inherited(base) raise "You cannot inherit from Rails::Plugin" end

Slide 136

Slide 136 text

Lembre-se: interno ao Rails :)

Slide 137

Slide 137 text

Quando eu preciso de um Plugin?

Slide 138

Slide 138 text

Você não precisa (não mais :)

Slide 139

Slide 139 text

Rails 4 SPOILER

Slide 140

Slide 140 text

RAILS 4 https://github.com/rails/rails/commit/dad7fdc

Slide 141

Slide 141 text

gems <3

Slide 142

Slide 142 text

Rails:: Application

Slide 143

Slide 143 text

Application < Engine

Slide 144

Slide 144 text

Start!

Slide 145

Slide 145 text

require config/boot.rb Rails boot

Slide 146

Slide 146 text

require railties + engines Rails boot

Slide 147

Slide 147 text

Define Rails.application Rails boot

Slide 148

Slide 148 text

Run before_configuration Rails boot

Slide 149

Slide 149 text

Load config/environment/ENV.rb Rails boot

Slide 150

Slide 150 text

Run before_initialize Rails boot

Slide 151

Slide 151 text

Initialize railties Rails boot

Slide 152

Slide 152 text

Configure railties Rails boot

Slide 153

Slide 153 text

Run railties#initializers Rails boot

Slide 154

Slide 154 text

Build middleware Rails boot

Slide 155

Slide 155 text

Run to_prepare Rails boot

Slide 156

Slide 156 text

Run before_eager_load Rails boot

Slide 157

Slide 157 text

Run after_initialize Rails boot

Slide 158

Slide 158 text

Booted!

Slide 159

Slide 159 text

Criar uma Application?

Slide 160

Slide 160 text

rails new my_app

Slide 161

Slide 161 text

module MyApp class Application < Rails::Application end end

Slide 162

Slide 162 text

>> require 'rails/all' => true >> class MyApp < Rails::Application; end => nil >> Rails.application => # >> class OtherApp < Rails::Application; end RuntimeError: You cannot have more than one Rails::Application

Slide 163

Slide 163 text

Single Responsibility Principle

Slide 164

Slide 164 text

Win!

Slide 165

Slide 165 text

Criando uma gem

Slide 166

Slide 166 text

Bundler

Slide 167

Slide 167 text

$ bundle gem rsonrails create rsonrails/Gemfile create rsonrails/Rakefile create rsonrails/LICENSE.txt create rsonrails/README.md create rsonrails/.gitignore create rsonrails/rsonrails.gemspec create rsonrails/lib/rsonrails.rb create rsonrails/lib/rsonrails/version.rb Initializating git repo in /Users/carlos/rsonrails bundle gem

Slide 168

Slide 168 text

Copyright (c) 2012 Carlos Antonio da Silva MIT License Permission is hereby granted, free of charge, to any person obtaining... License

Slide 169

Slide 169 text

# Rsonrails TODO: Write a gem description ## Installation Add this line to your application's Gemfile: gem 'rsonrails' ... ## Usage ... ## Contributing ... Readme

Slide 170

Slide 170 text

source 'https://rubygems.org' # Specify your gem's dependencies in rsonrails.gemspec gemspec Gemfile

Slide 171

Slide 171 text

# -*- encoding: utf-8 -*- lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'rsonrails/version' Gem::Specification.new do |gem| gem.name = "rsonrails" gem.version = Rsonrails::VERSION gem.authors = ["Carlos Antonio da Silva"] gem.email = ["[email protected]"] gem.description = %q{TODO: Write a gem description} gem.summary = %q{TODO: Write a gem summary} gem.homepage = "" gem.files = `git ls-files`.split($/) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ["lib"] end rsonrails.gemspec

Slide 172

Slide 172 text

require "rsonrails/version" module Rsonrails # Your code goes here... end lib/rsonrails.rb

Slide 173

Slide 173 text

module Rsonrails VERSION = "0.0.1" end lib/rsonrails/version.rb

Slide 174

Slide 174 text

Railtie?

Slide 175

Slide 175 text

module Rsonrails class Railtie < Rails::Railtie # config.rsonrails = ActiveSupport::OrderedOptions.new # rake_tasks {} # config.to_prepare {} # initializer {} end end lib/rsonrails.rb

Slide 176

Slide 176 text

module Rsonrails class Railtie < Rails::Railtie # config.rsonrails = ActiveSupport::OrderedOptions.new # rake_tasks {} # config.to_prepare {} # initializer {} end end require "rsonrails/version" require "rsonrails/railtie" module Rsonrails # Your code goes here... end lib/rsonrails/railtie.rb lib/rsonrails.rb

Slide 177

Slide 177 text

! Rails?

Slide 178

Slide 178 text

require "rsonrails/version" if defined?(Rails) require "rsonrails/railtie" end module Rsonrails # Your code goes here... end lib/rsonrails.rb

Slide 179

Slide 179 text

require "bundler/gem_tasks" Rakefile

Slide 180

Slide 180 text

$ rake -T rake build # Build rsonrails-0.0.1.gem into the pkg directory rake install # Build and install rsonrails-0.0.1.gem into system gems rake release # Create tag v0.0.1 and build and push rsonrails-0.0.1.gem to Rubygems rake tasks

Slide 181

Slide 181 text

Bundler

Slide 182

Slide 182 text

Bundler <3 <3 <3

Slide 183

Slide 183 text

No content

Slide 184

Slide 184 text

Railtie Engine Application

Slide 185

Slide 185 text

No content

Slide 186

Slide 186 text

plataformatec/ simple_form

Slide 187

Slide 187 text

plataformatec/ responders

Slide 188

Slide 188 text

plataformatec/ devise

Slide 189

Slide 189 text

rails/rails/ **/*railtie.rb

Slide 190

Slide 190 text

http://pragprog.com/book/jvrails/crafting-rails-applications

Slide 191

Slide 191 text

WITH GREAT MOUSTACHE COMES GREAT RESPONSIBILITY

Slide 192

Slide 192 text

Estamos contratando! plataformatec.com.br

Slide 193

Slide 193 text

No content

Slide 194

Slide 194 text

INTEGRANDO GEMS COM O RAILS @cantoniodasilva Obrigado!