module Pupa::Model::ClassMethods

Public Instance Methods

dump(*attributes) click to toggle source

Declare which properties should be dumped to JSON after a scraping task is complete. A subset of these will be imported to the database.

@param [Array<Symbol>] the properties to dump to JSON

# File lib/pupa/models/model.rb, line 48
def dump(*attributes)
  self.properties += attributes # use assignment to not overwrite the parent's attribute
end
foreign_key(*attributes) click to toggle source

Declare the class’ foreign keys.

When importing scraped objects, the foreign keys will be used to draw a dependency graph and derive an evaluation order.

@param [Array<Symbol>] the class’ foreign keys

# File lib/pupa/models/model.rb, line 58
def foreign_key(*attributes)
  self.foreign_keys += attributes
end
foreign_object(*attributes) click to toggle source

Declare the class’ foreign objects.

If some cases, you may not know the ID of an existing foreign object, but you may have other information to identify the object. In that case, put the information you have in a property named after the foreign key without the ‘_id` suffix: for example, `person` for `person_id`. Before saving the object to the database, Pupa.rb will use this information to identify the foreign object.

@param [Array<Symbol>] the class’ foreign objects

# File lib/pupa/models/model.rb, line 72
def foreign_object(*attributes)
  self.foreign_objects += attributes
end
schema=(value) click to toggle source

Sets the class’ schema.

@param [Hash,String] value a hash or a relative or absolute path @note ‘JSON::Validator#initialize_schema` runs fastest if given a hash.

# File lib/pupa/models/model.rb, line 80
def schema=(value)
  self.json_schema = value
  self.validator = JSON::Validator.new(self.json_schema, {}, {
    clear_cache: false,
    parse_data: false,
  })
end