Class: Committee::Middleware::Options::Base
- Inherits:
-
Object
- Object
- Committee::Middleware::Options::Base
- Defined in:
- lib/committee/middleware/options/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#accept_request_filter ⇒ Object
readonly
Returns the value of attribute accept_request_filter.
-
#error_class ⇒ Object
readonly
Returns the value of attribute error_class.
-
#error_handler ⇒ Object
readonly
Returns the value of attribute error_handler.
-
#ignore_error ⇒ Object
readonly
Returns the value of attribute ignore_error.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#raise_error ⇒ Object
readonly
Returns the value of attribute raise_error.
-
#schema ⇒ Object
readonly
Common options.
-
#schema_path ⇒ Object
readonly
Returns the value of attribute schema_path.
-
#strict_reference_validation ⇒ Object
readonly
Schema loading options.
Class Method Summary collapse
-
.from(options) ⇒ Object
Create an Option object from Hash options Returns the object as-is if already an Option object.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Allow Hash-like access for backward compatibility.
- #fetch(key, default = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #to_h ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/committee/middleware/options/base.rb', line 20 def initialize( = {}) @original_options = .dup.freeze # Schema related @schema = [:schema] @schema_path = [:schema_path] @strict_reference_validation = .fetch(:strict_reference_validation, false) # Error handling @error_class = .fetch(:error_class, Committee::ValidationError) @error_handler = [:error_handler] @raise_error = [:raise] || false @ignore_error = .fetch(:ignore_error, false) # Routing @prefix = [:prefix] @accept_request_filter = [:accept_request_filter] || ->(_) { true } validate! end |
Instance Attribute Details
#accept_request_filter ⇒ Object (readonly)
Returns the value of attribute accept_request_filter.
15 16 17 |
# File 'lib/committee/middleware/options/base.rb', line 15 def accept_request_filter @accept_request_filter end |
#error_class ⇒ Object (readonly)
Returns the value of attribute error_class.
10 11 12 |
# File 'lib/committee/middleware/options/base.rb', line 10 def error_class @error_class end |
#error_handler ⇒ Object (readonly)
Returns the value of attribute error_handler.
11 12 13 |
# File 'lib/committee/middleware/options/base.rb', line 11 def error_handler @error_handler end |
#ignore_error ⇒ Object (readonly)
Returns the value of attribute ignore_error.
13 14 15 |
# File 'lib/committee/middleware/options/base.rb', line 13 def ignore_error @ignore_error end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
14 15 16 |
# File 'lib/committee/middleware/options/base.rb', line 14 def prefix @prefix end |
#raise_error ⇒ Object (readonly)
Returns the value of attribute raise_error.
12 13 14 |
# File 'lib/committee/middleware/options/base.rb', line 12 def raise_error @raise_error end |
#schema ⇒ Object (readonly)
Common options
8 9 10 |
# File 'lib/committee/middleware/options/base.rb', line 8 def schema @schema end |
#schema_path ⇒ Object (readonly)
Returns the value of attribute schema_path.
9 10 11 |
# File 'lib/committee/middleware/options/base.rb', line 9 def schema_path @schema_path end |
#strict_reference_validation ⇒ Object (readonly)
Schema loading options
18 19 20 |
# File 'lib/committee/middleware/options/base.rb', line 18 def strict_reference_validation @strict_reference_validation end |
Class Method Details
.from(options) ⇒ Object
Create an Option object from Hash options Returns the object as-is if already an Option object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/committee/middleware/options/base.rb', line 56 def self.from() case when self when Hash new() else raise ArgumentError, "options must be a Hash or #{name}" end end |
Instance Method Details
#[](key) ⇒ Object
Allow Hash-like access for backward compatibility
42 43 44 |
# File 'lib/committee/middleware/options/base.rb', line 42 def [](key) to_h[key] end |
#fetch(key, default = nil) ⇒ Object
46 47 48 |
# File 'lib/committee/middleware/options/base.rb', line 46 def fetch(key, default = nil) to_h.fetch(key, default) end |
#to_h ⇒ Object
50 51 52 |
# File 'lib/committee/middleware/options/base.rb', line 50 def to_h @to_h ||= build_hash end |