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?
Currently the menu generator drops files in
lib/wcc/contentful/model
which reopen theWCC::Contentful::Model::Menu
class to add functionality. These ought to be put inapp/models
as classes which inherit from theWCC::Contentful::Model::x
classes. Example:This is as opposed to the current usage which reopens the class:
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'sinit!
method before we runvalidate_models!
so that we can get the extra per-project validations (see example)button1 = MenuButton.find(id)
vsbutton2 = top_nav_menu.buttons[0]
Even though they represent the same thing in Contentful, right nowbutton2
would be an instance ofWCC::Contentful::Model::MenuButton
not ofMenuButton
. What happens if we try to compare these objects?