Module: Train::Options::InstanceOptions
- Defined in:
- lib/train/options.rb
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
Options, which created this Transport.
Instance Method Summary collapse
- #default_audit_log_options ⇒ Object
- #default_options ⇒ Object
- #merge_options(base, opts) ⇒ Object
-
#validate_audit_log_options(opts) ⇒ Object
Introduced this method to validate only audit log options and avoiding call to validate_options so that it will no break existing implementation.
- #validate_options(opts) ⇒ Object
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns options, which created this Transport.
60 61 62 |
# File 'lib/train/options.rb', line 60 def @options end |
Instance Method Details
#default_audit_log_options ⇒ Object
62 63 64 |
# File 'lib/train/options.rb', line 62 def self.class. end |
#default_options ⇒ Object
66 67 68 |
# File 'lib/train/options.rb', line 66 def self.class. end |
#merge_options(base, opts) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/train/options.rb', line 70 def (base, opts) res = base.merge(opts || {}) # Also merge the default audit log options into the options so that those are available at the time of validation. .merge().each do |field, hm| next unless res[field].nil? && hm.key?(:default) default = hm[:default] if default.is_a? Proc res[field] = default.call(res) elsif hm.key?(:coerce) field_value = hm[:coerce].call(res) res[field] = field_value.nil? ? default : field_value else res[field] = default end end res end |
#validate_audit_log_options(opts) ⇒ Object
Introduced this method to validate only audit log options and avoiding call to validate_options so that it will no break existing implementation.
101 102 103 104 105 106 107 108 109 |
# File 'lib/train/options.rb', line 101 def (opts) .each do |field, hm| if opts[field].nil? && hm[:required] raise Train::ClientError, "You must provide a value for #{field.to_s.inspect}." end end opts end |
#validate_options(opts) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/train/options.rb', line 89 def (opts) .each do |field, hm| if opts[field].nil? && hm[:required] raise Train::ClientError, "You must provide a value for #{field.to_s.inspect}." end end opts end |