lib/tasks/spotlight_tasks.rake in blacklight-spotlight-0.10.0 vs lib/tasks/spotlight_tasks.rake in blacklight-spotlight-0.10.1
- old
+ new
@@ -28,29 +28,38 @@
Spotlight::Role.create(user: u, exhibit: exhibit, role: 'admin')
puts 'Exhibit created.'
end
desc 'Import an exhibit'
- task import: :environment do
+ task :import, [:exhibit_slug] => :environment do |_, args|
contents = if ENV['FILE']
File.read(ENV['FILE'])
else
STDIN.read
end
data = JSON.parse(contents)
- exhibit = Spotlight::Exhibit.find_or_create_by! slug: data['slug'] do |e|
+ slug = args[:exhibit_slug] || data['slug']
+
+ exhibit = Spotlight::Exhibit.find_or_create_by! slug: slug do |e|
e.title = data['title']
end
exhibit.import data
exhibit.save!
exhibit.reindex_later
puts Spotlight::ExhibitExportSerializer.new(exhibit.reload).to_json
+ end
+
+ desc 'Export an exhibit as JSON'
+ task :export, [:exhibit_slug] => :environment do |_, args|
+ exhibit = Spotlight::Exhibit.find_by(slug: args[:exhibit_slug])
+
+ puts Spotlight::ExhibitExportSerializer.new(exhibit).to_json
end
def prompt_to_create_user
User.find_or_create_by!(email: prompt_for_email) do |u|
puts 'User not found. Enter a password to create the user.'