Skip to content

Add a Model

Julie Allinson edited this page Apr 27, 2018 · 9 revisions

How to Add a Model

  1. create a template for the model
  2. write tests
  3. create the model
    1. add new properties (and tests)
    2. create the metadata concerns
    3. create the indexer
    4. Autoload any new models / concerns in dog_biscuits.rb
  4. pass tests

Create A Template

Before writing any code, it's sensible to establish the requirements for the new model.

I've created some templates in Google Docs to help with this:

These templates attend to address these questions:

  • What objects are being described?
  • What properties are needed?
  • What predicates represent these properties?
  • Is the property multi-valued or single?
  • How will it be indexed in solr?
  • Is it required?
  • What is the object of the property? (free-text, a value from a controlled list, another object in the repository)

Tests (1)

  • Write tests
  • Create a mock object in /spec/factories/works.rb
  • Test properties in 'support' - follow the same pattern used for other properties
  • Add a spec test in /spec/lib/models/works/MODEL_spec.rb

Create the Model

Create a model.rb where model is the name of the model (eg. thesis.rb)

  • for a work, add it to the lib/dog_biscuits/models/works folder
  • for an authority, add it to the lib/dog_biscuits/models/authorities folder
  • for an agent, add it to the lib/dog_biscuits/models/authorities/agents folder

The work model should contain:

  • includes statement for ::Hydra::Works::WorkBehavior
  • an rdf type value
  • a method that returns true for the name of the model

In addition, the model may contain

  • extra methods and callbacks

  • create a concern to list all of the the metadata, eg.

    • lib/dog_biscuits/models/concerns/model_property_sets/MODEL_metadata.rb
  • If the properties are already defined, include them in this file, otherwise

    • add any new properties, observing the conventions
      • add as individual concerns mixins
      • OR, add to the model itself if they are super-specific to the current model (or, if there are a lot of super-specific properties create lib/dog_biscuits/models/concerns/property_sets/MODEL_metadata.rb)
      • name has_and_belongs_to_many relations as PROPERTY_resource
    • add new properties to models/concerns/extended_solr_document.rb
    • add new properties to property_mappings/property_mappings.rb
  • Add an indexer class called MODEL_indexer in indexers and specify any indexing rules

  • Add to the available models list in lib/dog_biscuits/configuration.rb and add MODEL_properties and MODEL_properties_required; also to the configuration_spec

  • Finally, autoload all new code in the correct place in lib/dog_biscuits.rb - if you don't do this, everything is broken

Tests (2)

  • Make sure tests pass!