Module: Train::Options::InstanceOptions

Defined in:
lib/train/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsHash (readonly)

Returns options, which created this Transport.

Returns:

  • (Hash)

    options, which created this Transport



49
50
51
# File 'lib/train/options.rb', line 49

def options
  @options
end

Instance Method Details

#default_optionsObject



51
52
53
# File 'lib/train/options.rb', line 51

def default_options
  self.class.default_options
end

#merge_options(base, opts) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/train/options.rb', line 55

def merge_options(base, opts)
  res = base.merge(opts || {})
  default_options.each do |field, hm|
    next unless res[field].nil? and hm.key?(:default)
    default = hm[:default]
    if default.is_a? Proc
      res[field] = default.call(res)
    else
      res[field] = default
    end
  end
  res
end

#validate_options(opts) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/train/options.rb', line 69

def validate_options(opts)
  default_options.each do |field, hm|
    if opts[field].nil? and hm[:required]
      fail Train::ClientError,
           "You must provide a value for #{field.to_s.inspect}."
    end
  end
  opts
end