lib/bolt/result.rb in bolt-0.7.0 vs lib/bolt/result.rb in bolt-0.8.0
- old
+ new
@@ -18,10 +18,14 @@
def to_h
{ 'value' => value }
end
+ def to_result
+ value
+ end
+
def success?
true
end
end
@@ -40,10 +44,20 @@
'msg' => @message
}
}
end
+ def to_result
+ {
+ '_error' => {
+ 'issue_code' => @issue_code,
+ 'kind' => @kind,
+ 'msg' => @message
+ }
+ }
+ end
+
def success?
false
end
end
@@ -62,10 +76,14 @@
'stderr' => @stderr,
'exit_code' => @exit_code
}
end
+ def to_result
+ value
+ end
+
def success?
@exit_code.zero?
end
def message
@@ -84,24 +102,33 @@
def value
@object || @stdout
end
+ def to_result
+ result = @object
+ result['_error'] = @error if @error
+ result
+ end
+
def to_h
hash = super
hash['error'] = error if error
hash
end
private
def output_to_json_hash(output)
- obj = JSON.parse(output)
- if obj.is_a? Hash
- obj
+ begin
+ obj = JSON.parse(output)
+ unless obj.is_a? Hash
+ obj = nil
+ end
+ rescue JSON::ParserError
+ nil
end
- rescue JSON::ParserError
- nil
+ obj || { '_output' => output }
end
end
class TaskSuccess < TaskResult
def success?