GithubHelp home page GithubHelp logo

Serialize from hash about surrealist HOT 5 CLOSED

nesaulov avatar nesaulov commented on May 3, 2024 2
Serialize from hash

from surrealist.

Comments (5)

nesaulov avatar nesaulov commented on May 3, 2024

@glaucocustodio, thank you, I guess that's a good feature to have, I would be glad accepting a PR. The only thing to keep in mind is that we don't want to pollute the Surrealist::Builder class, as it's already quite complex. I suggest having a separate class, a HashBuilder for example, which accepts only hashes and validates them directly, not based on method_missing. There will also be a different (and easier) way to validate hash schema, something like

hash.keys.length == schema.keys.length
hash.keys.map(&:to_sym).sort == schema.keys.sort

And we will also need tests covering different cases, apparently.

from surrealist.

glaucocustodio avatar glaucocustodio commented on May 3, 2024

Using my wrapper for hash, I just needed to change the check_for_ar method like below to support hash validation:

def check_for_ar(schema, instance, key, value)
  if ar_collection?(instance, key)
    construct_collection(schema, instance, key, value)
  else
    ins = if instance.respond_to?(key)
        instance.send(key)
      elsif instance.is_a?(Hash)
        instance[key]
      else
        instance
      end
    call(value, ins)
  end
end

from surrealist.

nesaulov avatar nesaulov commented on May 3, 2024

You see, I don't think that 4 if statements in one method is a good thing at all. And the semantics are broken here - why would we check for active record if we are just serializing a hash

from surrealist.

glaucocustodio avatar glaucocustodio commented on May 3, 2024

You are right, this code is not very good. I need to take some time to create the HashBuilder.

from surrealist.

nesaulov avatar nesaulov commented on May 3, 2024

Closing this due to #106

from surrealist.

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.