Method: Kennel::SettingsAsMethods#initialize

Defined in:
lib/kennel/settings_as_methods.rb

#initialize(options = {}) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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