elikem
9/26/2014 - 2:28 PM

Configuration blocks

Configuration blocks

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
Clearance.configure do |config|
  config.mailer_sender = 'donotreply@example.com'
end

# OR

Clearance.configuration.mailer_sender

# OR

Clearance.configuration.mailer_sender = 'new.email@example.com'