Class: CommonwealthVlrEngine::ModelGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/commonwealth_vlr_engine/model_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_migrationsObject

Setup the database migrations



60
61
62
# File 'lib/generators/commonwealth_vlr_engine/model_generator.rb', line 60

def copy_migrations
  rake 'railties:install:migrations'
end

#get_migrations_submoduleObject

get the database migrations from the submodule github.com/boston-library/commonwealth-db-migrations.git



52
53
54
55
56
57
# File 'lib/generators/commonwealth_vlr_engine/model_generator.rb', line 52

def get_migrations_submodule
  Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..'))) do
    `git submodule init`
    `git submodule update`
  end
end

#inject_search_builder_behaviorObject

Limit the institutions



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/commonwealth_vlr_engine/model_generator.rb', line 21

def inject_search_builder_behavior
  unless IO.read("app/models/#{search_builder_model}.rb").include?('def institutions_filter')
    marker = 'Blacklight::Solr::SearchBuilderBehavior'
    insert_into_file "app/models/#{search_builder_model}.rb", :after => marker do
      %q{

  # limit to a specific institution
  def institution_limit(solr_parameters = {})
solr_parameters[:fq] ||= []
solr_parameters[:fq] << '+institution_pid_ssi:"' + CommonwealthVlrEngine.config[:institution][:pid] + '"'
  end
}
    end
  end
end

#inject_solr_document_behaviorObject

OpenSeadragon support?



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/commonwealth_vlr_engine/model_generator.rb', line 38

def inject_solr_document_behavior
  unless IO.read("app/models/#{document_model_name}.rb").include?('Blacklight::Gallery::OpenseadragonSolrDocument')
    marker = 'include Blacklight::Solr::Document'
    insert_into_file "app/models/#{document_model_name}.rb", :after => marker do
      %q{

  include Blacklight::Gallery::OpenseadragonSolrDocument
}
    end
  end
end