Skip to content

Instantly share code, notes, and snippets.

@ngpestelos
Forked from tansengming/configure.rb
Created August 28, 2013 22:33
Show Gist options
  • Save ngpestelos/6372228 to your computer and use it in GitHub Desktop.
Save ngpestelos/6372228 to your computer and use it in GitHub Desktop.
# How Clearance / Hoptoad does it
module Clearance
class << self
attr_accessor :configuration
end
def self.configure
self.configuration ||= Configuration.new
yield(configuration)
end
class Configuration
attr_accessor :mailer_sender
def initialize
@mailer_sender = '[email protected]'
end
end
end
# to use
Clearance.configure do |config|
config.mailer_sender = '[email protected]'
end
# How Devise does it
module Devise
mattr_accessor :mailer_sender # requires active support
@@mailer_sender = '[email protected]'
class << self
def setup
yield self
end
end
end
# to use
Devise.setup do |config|
config.mailer_sender = '[email protected]'
end
# references: http://robots.thoughtbot.com/post/344833329/mygem-configure-block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment