Module: Train::Options::ClassOptions

Defined in:
lib/train/options.rb

Instance Method Summary collapse

Instance Method Details

#default_optionsObject



33
34
35
36
# File 'lib/train/options.rb', line 33

def default_options
  @default_options = {} unless defined? @default_options
  @default_options
end

#include_options(other) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/train/options.rb', line 38

def include_options(other)
  unless other.respond_to?(:default_options)
    raise "Trying to include options from module #{other.inspect}, "\
         "which doesn't seem to support options."
  end
  default_options.merge!(other.default_options)
end

#option(name, conf = nil, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/train/options.rb', line 14

def option(name, conf = nil, &block)
  d = conf || {}
  unless d.is_a? Hash
    raise Train::ClientError,
      "The transport plugin #{self} declared an option #{name} "\
      "and didn't provide a valid configuration hash."
  end

  if !conf.nil? && !conf[:default].nil? && block_given?
    raise Train::ClientError,
      "The transport plugin #{self} declared an option #{name} "\
      "with both a default value and block. Only use one of these."
  end

  d[:default] = block if block_given?

  default_options[name] = d
end