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

Advanced View, but with user-defined keys #14

Open
allthesignals opened this issue Jun 26, 2020 · 1 comment
Open

Advanced View, but with user-defined keys #14

allthesignals opened this issue Jun 26, 2020 · 1 comment

Comments

@allthesignals
Copy link

First of all, I love this gem — amazing that it just works perfectly.

Perhaps I'm misunderstanding the documentation, but is there a way to use advanced view but allow for custom key objects?

For example:

      "user_defined_key_here": {  
        table: "2018",
        sources: [
          {name: "lcgms", version: '2018-12-19', minYear: 2018, maxYear: 2019},
          {name: "bluebook", minYear: 2017, maxYear: 2018}
        ]
      },

With advanced view, I find it can enforce an up-front structure of the JSON schema. Is this possible? For now, I can just use the jsoneditor, but I find your advanced view to be much simpler.

That said, this may be a sign that I need to use some other kinds of objects in Rails (read: models), but this is great for now.

@volkov-sergey
Copy link
Member

Hi @allthesignals thanks and sorry for late response.

If I got the point you want to get something like this:

Screenshot from 2020-07-17 12-05-55

I did it with the code:

ATTRIBUTE_TYPES = {
  ...
  jsonb_field: Field::JSONB.with_options(transform: %i[symbolize_keys], advanced_view: {
    user_defined_key_here: Field::JSONB.with_options(transform: %i[symbolize_keys], advanced_view: {
      table: Field::String,
      sources: Field::JSONB.with_options(transform: %i[symbolize_keys], advanced_view: {
        name: Field::String,
        version: Field::String,
        minYear: Field::String,
        maxYear: Field::String
      })
    })
  })
}.freeze

Please update me if I didn't got your point correct. Thanks!

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