Class: Blacklight::Allmaps::ModelsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/blacklight/allmaps/models_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_migrationsObject

Setup the database migrations



20
21
22
# File 'lib/generators/blacklight/allmaps/models_generator.rb', line 20

def copy_migrations
  rake "blacklight_allmaps_engine:install:migrations"
end

#include_sidecar_allmaps_solrdocumentObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/generators/blacklight/allmaps/models_generator.rb', line 24

def include_sidecar_allmaps_solrdocument
  sidecar = <<-SIDECAR
  
  def sidecar_allmaps
    # Find or create, and set version
    sidecar = Blacklight::Allmaps::Sidecar.where(
solr_document_id: id,
    ).first_or_create do |sc|
sc.solr_version = self._source["_version_"]
    end

    sidecar.solr_version = self._source["_version_"]
    sidecar.save

    sidecar
  end
  SIDECAR

  inject_into_file "app/models/solr_document.rb", sidecar, before: /^end/
end