ruby confhighlights
TRANSCRIPT
What is it?● Annually in Australia (Melbourne/Sydney)● Around the world (e.g. Miami, India, Argentina)● Variety of talks held over 2 days ● Local and International speakers● A day of workshops (e.g. Rails Girls Next, C Extensions,
Rspec)● Best practises, examples, inspiration, meet new people● Videos - http://vimeo.com/rubyau
This Year● Continuous Delivery● Rails Engines● Middleware● Ruby 2.1● Minitest● Programming as a Parent● Asset Pipeline● MongoDB● Concurrency Practices in Ruby● JRuby● Security● Loads more ... https://m.lanyrd.com/2014/rubyconf-au/schedule/● Videos - http://vimeo.com/rubyau
Rails Engines● Slow● Buggy● New features take too
long● Disploys are
complicated● So many
dependencies
Rails Enginesrails plugin new <engine_name> --mountable
rails g controller <controller_name>
rake db:migrate
rake <engine_name>:install:migrations
gem 'engine_name', path: "vendor/engines/engine_name"
● engine.rb, routes.rb, application.rb● test app (test/dummy)● namespaced - routes, views, tables etc● migrations● SOA, Model Managers
Rails Engines● Avoid accessing ActiveRecord
directly● Domain API● Smart & Fast test suite => test
changes in the changed engine
C Extensions● C code in a Ruby Gem● E.g. nokogiri● Testable (write Rspec on C code!)● Why? speedier (Ruby is not slow, but not great on
processing e.g. image processing)● Ruby wrapper for C libs
C Extensionsbundle gem <gem_name> create the gem
# <gem_name>.gemspec
spec.add_development_dependency "rake-compiler"
# Rakefile
require "rake/extensiontask"
Rake::ExtensionTask.new('rbshop') do |ext|
ext.lib_dir = "lib/rbshop"
end
mkdir -p ext/gem_name C code lives here
C Extensions# ext/gem_name/extconf.rb add extension config file
require ‘mkmf’ creates makefile to compile C code
create_makefile(‘gem_name’)
# ext/gem_name/gem_name.c
initialise the extension
ruby.h is the C APIe.g. INT2NUM
C Extensions● free() and malloc()● Tell Ruby what
methods to allocate and free memory
● Ruby holds onto memory until it needs to free it
C Extensions➔ Call functions that define modules/classes:
◆ rb_define_module - Creates modules◆ rb_define_class_under - Creates a new class◆ rb_define_alloc_func - Lets you control how allocation happens
➔ Types◆ Strings, Arrays, Hashes, Numbers◆ Check_Type(r_radius, T_FLOAT)◆ E.g. Strings
● rb_str_new(const char *ptr, long len)● rb_str_new2(const char *ptr)● rb_str_cat(VALUE str, const char *ptr, long len)● rb_str_modify(VALUE str)
Community● Rails Girls and Rails Girls Next● RoRo Syd● Ninefold, Re-Interactive● Installfest, Developer Hub● General Assembly● New Groups - Ruby Women, Women Who
Code