Skip to content

Instantly share code, notes, and snippets.

@ngpestelos
Forked from tansengming/configure.rb
Created August 28, 2013 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 = 'donotreply@example.com'
end
end
end
# to use
Clearance.configure do |config|
config.mailer_sender = 'donotreply@example.com'
end
# How Devise does it
module Devise
mattr_accessor :mailer_sender # requires active support
@@mailer_sender = 'donotreply@example.com'
class << self
def setup
yield self
end
end
end
# to use
Devise.setup do |config|
config.mailer_sender = 'donotreply@example.com'
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