Skip to content
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

Invalid parsing of object, containing Procs and other nested objects #215

Open
Mehonoshin opened this issue Sep 5, 2017 · 2 comments
Open

Comments

@Mehonoshin
Copy link

Mehonoshin commented Sep 5, 2017

Hey there!
I found the following issue, it does not highlight all fields of such object.

I understand, that it can be complex problem, but maybe anyone has an idea how to solve this?

s = '<Result:false <Skill {"policy.default.eval"=>#<Proc:0x007fc73d75cfb8@/Users/mexx/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/trailblazer-2.0.7/lib/trailblazer/operation/guard.rb:14 (lambda)>, "policy.default"=>nil, "result.policy.default"=><Result:true {} >, "model.class"=>Blog::Post(id: integer, title: string, body: text, published: boolean, created_at: datetime, updated_at: datetime), "model.action"=>:new, "model"=>#<Blog::Post id: nil, title: nil, body: nil, published: nil, created_at: nil, updated_at: nil>, "result.model"=><Result:true {} >, "contract.default"=>#<Blog::Post::Contracts::Create:0x007fc73aa66f18 @fields={"title"=>"test", "body"=>"123"}, @model=#<Blog::Post id: nil, title: nil, body: nil, published: nil, created_at: nil, updated_at: nil>, @mapper=#<#<Class:0x007fc73aa66450>:0x007fc73aa5cf18 @model=#<Blog::Post id: nil, title: nil, body: nil, published: nil, created_at: nil, updated_at: nil>>, @_changes={"title"=>true, "body"=>true}, @errors=#<Reform::Contract::Errors:0x007fc73aa542c8 @errors={:body=>["size cannot be less than 9", "size cannot be less than 9"]}>>, "contract.default.params"=>{:title=>"test", :body=>"123"}, "representer.default.class"=>false, "result.contract.default"=>#<Blog::Post::Contracts::Create:0x007fc73aa66f18 @fields={"title"=>"test", "body"=>"123"}, @model=#<Blog::Post id: nil, title: nil, body: nil, published: nil, created_at: nil, updated_at: nil>, @mapper=#<#<Class:0x007fc73aa66450>:0x007fc73aa5cf18 @model=#<Blog::Post id: nil, title: nil, body: nil, published: nil, created_at: nil, updated_at: nil>>, @_changes={"title"=>true, "body"=>true}, @errors=#<Reform::Contract::Errors:0x007fc73aa542c8 @errors={:body=>["size cannot be less than 9", "size cannot be less than 9"]}>>} {:current_user=>true, "params"=>{:blog_post=>{:title=>"test", :body=>"123"}}} {"pipetree"=>[>operation.new,>policy.default.eval,>Nested(Blog::Post::Create::Present),>contract.default.validate,>persist.save,>notify!]}> >'


irb(main):008:0> CodeRay.scan(s, :ruby).term

=> "<\e[35mResult\e[0m:\e[1;36mfalse\e[0m <\e[1;34;4mSkill\e[0m {\e[31m\e[1;31m\"\e[0m\e[31mpolicy.default.eval\e[1;31m\"\e[0m\e[31m\e[0m=>\e[1;30m#<Proc:0x007fc73d75cfb8@/Users/mexx/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/trailblazer-2.0.7/lib/trailblazer/operation/guard.rb:14 (lambda)>, \"policy.default\"=>nil, \"result.policy.default\"=><Result:true {} >, \"model.class\"=>Blog::Post(id: integer, title: string, body: text, published: boolean, created_at: datetime, updated_at: datetime), \"model.action\"=>:new, \"model\"=>#<Blog::Post id: nil, title: nil, body: nil, published: nil, created_at: nil, updated_at: nil>, \"result.model\"=><Result:true {} >, \"contract.default\"=>#<Blog::Post::Contracts::Create:0x007fc73aa66f18 @fields={\"title\"=>\"test\", \"body\"=>\"123\"}, @model=#<Blog::Post id: nil, title: nil, body: nil, published: nil, created_at: nil, updated_at: nil>, @mapper=#<#<Class:0x007fc73aa66450>:0x007fc73aa5cf18 @model=#<Blog::Post id: nil, title: nil, body: nil, published: nil, created_at: nil, updated_at: nil>>, @_changes={\"title\"=>true, \"body\"=>true}, @errors=#<Reform::Contract::Errors:0x007fc73aa542c8 @errors={:body=>[\"size cannot be less than 9\", \"size cannot be less than 9\"]}>>, \"contract.default.params\"=>{:title=>\"test\", :body=>\"123\"}, \"representer.default.class\"=>false, \"result.contract.default\"=>#<Blog::Post::Contracts::Create:0x007fc73aa66f18 @fields={\"title\"=>\"test\", \"body\"=>\"123\"}, @model=#<Blog::Post id: nil, title: nil, body: nil, published: nil, created_at: nil, updated_at: nil>, @mapper=#<#<Class:0x007fc73aa66450>:0x007fc73aa5cf18 @model=#<Blog::Post id: nil, title: nil, body: nil, published: nil, created_at: nil, updated_at: nil>>, @_changes={\"title\"=>true, \"body\"=>true}, @errors=#<Reform::Contract::Errors:0x007fc73aa542c8 @errors={:body=>[\"size cannot be less than 9\", \"size cannot be less than 9\"]}>>} {:current_user=>true, \"params\"=>{:blog_post=>{:title=>\"test\", :body=>\"123\"}}} {\"pipetree\"=>[>operation.new,>policy.default.eval,>Nested(Blog::Post::Create::Present),>contract.default.validate,>persist.save,>notify!]}> >\e[0m"

It seems that problem is related to parsing #<Proc:0x007fc73d75cfb8@/Users/mexx/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/trailblazer-2.0.7/lib/trailblazer/operation/guard.rb:14 (lambda)> Procs and other nested objects.

@Mehonoshin Mehonoshin changed the title Invalid highlight of complex ruby object Invalid parsing of object, containing Procs and other nested objects Sep 5, 2017
@korny
Copy link
Member

korny commented Sep 6, 2017

It looks like you're trying to highlight the output of #inspect as Ruby code. However, this isn't valid Ruby syntax – so it's not really CodeRay's fault ;)

@Mehonoshin
Copy link
Author

Yeah, but I'm also trying to solve an issue with higher-level tools, like PRY.
They use CodeRay for such things highlighting: https://monosnap.com/file/YQVmVscdkzgIkp4holKmq3LhmpQRPe

And this results that the output is not very pretty.

I understand that the primary goal of your tool is highlighting of sources, but probably we can implement inspect highlighting too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants