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

Generator should drop model classes in app/models, not lib/ #15

Open
gburgett opened this issue Mar 16, 2018 · 0 comments
Open

Generator should drop model classes in app/models, not lib/ #15

gburgett opened this issue Mar 16, 2018 · 0 comments

Comments

@gburgett
Copy link
Member

Currently the menu generator drops files in lib/wcc/contentful/model which reopen the WCC::Contentful::Model::Menu class to add functionality. These ought to be put in app/models as classes which inherit from the WCC::Contentful::Model::x classes. Example:

# app/models/menu_button.rb
class MenuButton < WCC::Contentful::Model::MenuButton
  # Override the "page" link validation, because the content type ID in JTJ
  # for pages has a capital P.
  validate_field :link, :Link, link_to: 'Page'

  ...
end

This is as opposed to the current usage which reopens the class:

# lib/wcc/contentful/model/menu_button.rb
class WCC::Contentful::Model::MenuButton < WCC::Contentful::Model

Potential complications:

  • Validation logic (i.e. validate_field) stores validations in a class instance variable @field_validations - need to combine these from multiple subclasses.

  • We need to require these models inside the wcc-contentful gem's init! method before we run validate_models! so that we can get the extra per-project validations (see example)

  • button1 = MenuButton.find(id) vs button2 = top_nav_menu.buttons[0]
    Even though they represent the same thing in Contentful, right now button2
    would be an instance of WCC::Contentful::Model::MenuButton not of MenuButton.
    What happens if we try to compare these objects?

@gburgett gburgett added the -app label Apr 16, 2021
@zube zube bot removed the -app label Jan 31, 2023
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

1 participant