Class: SoftFail
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- SoftFail
- Defined in:
- lib/schema.rb
Overview
The conditions for marking the step as a soft-fail.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 |
# File 'lib/schema.rb', line 1165 def self.from_dynamic!(d) return new(bool: d, soft_fail_element_array: nil, enum: nil) if schema[:bool].right.valid? d return new(enum: d, soft_fail_element_array: nil, bool: nil) if schema[:enum].right.valid? d begin value = d.map { |x| SoftFailElement.from_dynamic!(x) } if schema[:soft_fail_element_array].right.valid? value return new(soft_fail_element_array: value, bool: nil, enum: nil) end rescue StandardError end raise "Invalid union" end |
.from_json!(json) ⇒ Object
1179 1180 1181 |
# File 'lib/schema.rb', line 1179 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
1183 1184 1185 1186 1187 1188 1189 1190 1191 |
# File 'lib/schema.rb', line 1183 def to_dynamic if !bool.nil? bool elsif !enum.nil? enum elsif !soft_fail_element_array.nil? soft_fail_element_array.map(&:to_dynamic) end end |
#to_json(options = nil) ⇒ Object
1193 1194 1195 |
# File 'lib/schema.rb', line 1193 def to_json( = nil) JSON.generate(to_dynamic, ) end |