Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Building Extractable Libraries in Rails via Patrick Robertson #railsConf

Building Extractable Libraries in Rails

Avoiding the autoload trap

  • rails 3: removing /lib from automatically being loaded on application boot

create a namespace and setup a proper layout when we need to extract our code outside the application into a gem

Hide your credentials from your Library

require_relative '../lib/twitter_wrangler'

TwitterWrangler.configure do |config|
  config.oauth_key - ENV[:twitter_ouath_key]

module TwitterWrangler
  class Configuration
    attr_accessor :oauth_key
    def initializers
      oauth_key = nil

  class << self
    attr_accessor :configuration

  def self.configure
    self.configuration ||=
    yeild(configuration) if block_given?

separation of credential concerns

Keeping your domain models focused

provides clear separation of domain models and outside code creates isolatable test easy path forward for gem extraction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment