-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass ruby objects between states #222
Conversation
3ce5c3a
to
b109029
Compare
update:
|
@kbrock I think we could use some specs covering using simple strings not hashes as input/output I applied this to #184 and I'm seeing
This is fixed by my changes https://github.com/ManageIQ/floe/pull/214/files#diff-c61a9c0cebe305116e077d04dc168aa33f6339d348c778addf65ab7c19b2479bR42 and https://github.com/ManageIQ/floe/pull/214/files#diff-24e71eb9cd8cfb4211a041b7a08cfc1d9d33203a6c2ce88dbc153234e82dfe1cR67 |
ec7eb71
to
8c1ee01
Compare
@agrare thanks for the pointer on this one |
Had a question here about the intent. I noticed a comment in #214 where we are expecting "non-json" output, but to clarify, we really are expecting "non-hash" output. Well-formed JSON strings or integers are still JSON even if they aren't a Hash. So my concern here if we don't attempt to JSON parse it, is that invalid outputs can be emitted and we would miss verifying them. So, here we see valid JSON "bare" strings and integers: [1] pry(main)> require "json"
=> true
[2] pry(main)> "test".to_json
=> "\"test\""
[3] pry(main)> JSON.parse(_)
=> "test"
[4] pry(main)> 1.to_json
=> "1"
[5] pry(main)> JSON.parse(_)
=> 1 But this would be invalid output/input: [2] pry(main)> JSON.parse("foo")
~/.gem/ruby/3.1.5/gems/json-2.7.2/lib/json/common.rb:220:in `parse': unexpected token at 'foo' (JSON::ParserError)
from ~/.gem/ruby/3.1.5/gems/json-2.7.2/lib/json/common.rb:220:in `parse'
from (pry):2:in `__pry__'
[3] pry(main)> JSON.parse('{\"xxx":')
~/.gem/ruby/3.1.5/gems/json-2.7.2/lib/json/common.rb:220:in `parse': unexpected token at '{\"xxx":' (JSON::ParserError)
from ~/.gem/ruby/3.1.5/gems/json-2.7.2/lib/json/common.rb:220:in `parse'
from (pry):3:in `__pry__' |
let(:input) { "\"foo\"" } | ||
let(:input) { "foo" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example. I think this is actually invalid input, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is invalid input for CLI.
In the CLI / floe from the command line, I want to see "\"foo\""
.
And possibly the methods for manageiq-providers-workflow
would pass in JSON strings.
But once something is in our inner classes, I want to see ruby.
update:
outstanding:
|
update:
|
un-wip: we are now outputting in json (thanks to other PR) |
Checked commits kbrock/floe@9262ef5~...3dab1ba with ruby 3.1.5, rubocop 1.56.3, haml-lint 0.51.0, and yamllint |
This pull request is not mergeable. Please rebase and repush. |
We've decided to do json in the context. |
Overview
See also #228
Built upon:
I am displaying these opinions so we can more easily discus them:
JSON::ParserError
.CLI
andContext.load
,Context.from_json
(will be used in the provider)Context#input
hold JSON or ruby? rubyContext#output
hold JSON or ruby? rubyContext
in the database be JSON or ruby? ruby, the database serializes it for us.floe/exe
is responsible for converting user strings to ruby/json objects.Task#parse_output
is responsible for converting task output to ruby/json objects.JSON.parse(x) if x.kind_of?(String)