Giter VIP home page Giter VIP logo

Comments (5)

pond avatar pond commented on July 17, 2024

If an errors collection is empty, it acquires the status code from the first item added.

I'm not sure you should be mutating the errors instance inline, but if you are, it'd be a question of removing the one error entry (which might empty the collection) then adding a new one (which if the collection was now empty should auto-set the status code for you).

from hoodoo.

waynehoover avatar waynehoover commented on July 17, 2024

The reason we are mutating here is because the errors instance could already have more than one error in it. So removing it then adding a new one might not be adding it to an empty array, which then wouldn't update the status code.

from hoodoo.

waynehoover avatar waynehoover commented on July 17, 2024

Now that I think about it one possible way to do it now is to dup the errors, modiy them, empty the Hoodoo:Errors#errors collection, then add all the new modified errors in.

from hoodoo.

pond avatar pond commented on July 17, 2024

I'd probably:

  • Create a new Errors instance
  • Iterate through the source Errors instance, transmogrifying entires if necessary
  • Call add_precompiled_error on the new Errors instance to add the possibly-altered error entries back

Done. Actually it's probably even cleaner to iterate, then either add_precompiled_error for one you aren't modifying, or use add_error to add the thing or things you actually want for the case when you want to change an entry into something else. Code should be easier to read.

See also the source code for Errors#merge! in errors.rb.

from hoodoo.

waynehoover avatar waynehoover commented on July 17, 2024

I'm going to close this, I implemented this with public APIs here: https://github.com/LoyaltyNZ/service_purchase/pull/108

from hoodoo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.