module Kennel::SettingsAsMethods

Constants

SETTING_OVERRIDABLE_METHODS

Public Class Methods

included(base) click to toggle source
# File lib/kennel/settings_as_methods.rb, line 6
def self.included(base)
  base.extend ClassMethods
  base.instance_variable_set(:@settings, [])
end
new(options = {}) click to toggle source
Calls superclass method
# File lib/kennel/settings_as_methods.rb, line 54
def initialize(options = {})
  super()

  unless options.is_a?(Hash)
    raise ArgumentError, "Expected #{self.class.name}.new options to be a Hash, got a #{options.class}"
  end

  options.each do |k, v|
    next if v.class == Proc
    raise ArgumentError, "Expected #{self.class.name}.new option :#{k} to be Proc, for example `#{k}: -> { 12 }`"
  end

  options.each do |name, block|
    self.class.send :validate_setting_exist, name
    define_singleton_method name, &block
  end

  # need expand_path so it works wih rake and when run individually
  pwd = /^#{Regexp.escape(Dir.pwd)}\//
  @invocation_location = caller.detect do |l|
    if found = File.expand_path(l).sub!(pwd, "")
      break found
    end
  end
end

Public Instance Methods

raise_with_location(error, message) click to toggle source
# File lib/kennel/settings_as_methods.rb, line 80
def raise_with_location(error, message)
  message = message.dup
  message << " on #{@invocation_location}" if @invocation_location
  raise error, message
end