Module: Train::Options::ClassOptions

Defined in:
lib/train/options.rb

Instance Method Summary collapse

Instance Method Details

#default_audit_log_optionsObject

Created separate method to set the default audit log options so that it will be handled separately and will not break any existing functionality



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

def default_audit_log_options
  {
    enable_audit_log: { default: false },
    audit_log_location: { required: true, default: nil },
    audit_log_app_name: { default: "train" },
    audit_log_size: { default: nil },
    audit_log_frequency: { default: 0 },
  }
end

#default_optionsObject



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

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

#include_options(other) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/train/options.rb', line 49

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



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

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