Sha256: 4ad6c117b86b8d8334cdfe5641a0a559191725aee15f711ccba0d12002d9cf16
Contents?: true
Size: 1.3 KB
Versions: 1
Compression:
Stored size: 1.3 KB
Contents
module Appt # Defines constants and methods related to configuration module Configuration VALID_OPTIONS_KEYS = [ ].freeze UNKNOWN_CLASSES = { parent_mailer: -> { ActionMailer::Base }, parent_controller: -> { ::ApplicationController }, user_class: -> { nil }, } attr_accessor *VALID_OPTIONS_KEYS # When this module is extended, set all configuration options to their default values def self.extended(base) base.reset end # Convenience method to allow configuration options to be set in a block def configure yield self end # Reset all configuration options to defaults def reset self end UNKNOWN_CLASSES.each do |key, default| attr_accessor key.to_sym end UNKNOWN_CLASSES.each do |key, default| define_method(key) do value = instance_variable_get("@#{key}") || UNKNOWN_CLASSES[key.to_sym] value = value.call if value.respond_to?(:call) c = force_to_constant(value) c end end private def force_to_constant(value) if value.is_a?(Class) value = value.name elsif value.is_a?(Symbol) value = value.to_s end value.try(:constantize) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
appt-0.0.1.beta.2 | lib/appt/configuration.rb |