Class: OpenTopo::Net::Params::BaseParams
- Inherits:
-
Object
- Object
- OpenTopo::Net::Params::BaseParams
show all
- Extended by:
- Forwardable
- Defined in:
- lib/open_topo/net/params/base_params.rb
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BaseParams.
9
10
11
12
13
14
15
|
# File 'lib/open_topo/net/params/base_params.rb', line 9
def initialize
@validation_result = nil
if self.class.contract.nil?
raise NotImplementedError, "Contract not configured"
end
end
|
Class Attribute Details
.contract ⇒ Object
Returns the value of attribute contract.
52
53
54
|
# File 'lib/open_topo/net/params/base_params.rb', line 52
def contract
@contract
end
|
Class Method Details
.validate_with(contract) ⇒ Object
54
55
56
|
# File 'lib/open_topo/net/params/base_params.rb', line 54
def validate_with(contract)
@contract = contract
end
|
Instance Method Details
#error_messages ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/open_topo/net/params/base_params.rb', line 35
def error_messages
if !validation_result.nil? && !validation_result.success?
validation_result.errors(full: true).messages.map(&:text)
else
[]
end
end
|
#to_params ⇒ Object
17
18
19
|
# File 'lib/open_topo/net/params/base_params.rb', line 17
def to_params
raise NotImplementedError, "Method to_params not implemented"
end
|
#valid? ⇒ Boolean
22
23
24
25
|
# File 'lib/open_topo/net/params/base_params.rb', line 22
def valid?
validate
validation_result.success?
end
|
#validate! ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/open_topo/net/params/base_params.rb', line 27
def validate!
if !valid?
raise ::OpenTopo::Errors::ParamsError, "Invalid parameters: #{error_messages.join(", ")}"
end
true
end
|