- 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
#config/initializers/twitter_wrangler.rb
require_relative '../lib/twitter_wrangler'
TwitterWrangler.configure do |config|
config.oauth_key - ENV[:twitter_ouath_key]
end
#lib/twitter_wrangler/configuration.rb
module TwitterWrangler
class Configuration
attr_accessor :oauth_key
def initializers
oauth_key = nil
end
end
class << self
attr_accessor :configuration
end
def self.configure
self.configuration ||= Configuration.new
yeild(configuration) if block_given?
end
end
separation of credential concerns
provides clear separation of domain models and outside code creates isolatable test easy path forward for gem extraction
https://speakerdeck.com/patricksroberts/building-extractable-libraries-in-rails-bostonrb