Class: ResourceTasks

Inherits:
Object
  • Object
show all
Defined in:
app/tasks/resource_tasks.rb

Class Method Summary collapse

Class Method Details

.fix_metadataObject



4
5
6
7
8
9
10
11
12
# File 'app/tasks/resource_tasks.rb', line 4

def self.
  Resource.tree.find_each do |res|
    curr_meta = res.self_and_ancestors.each_with_object({}) do |r, obj|
      obj[r.curriculum_type] = r.short_title
    end
    res..merge! curr_meta
    res.save
  end
end

.generate_unit_bundlesObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/tasks/resource_tasks.rb', line 14

def self.generate_unit_bundles
  Resource.tree.units.each do |unit|
    DocumentBundle::CATEGORIES.each do |category|
      DocumentBundle.update_bundle(unit, category)
      print '.'
    end
  rescue Exception => e # rubocop:disable Lint/RescueException
    puts "Err on update_bundle for #{unit.slug} #{category} : #{e.message}"
  end
  puts "\n"
end

.sync_reading_assignmentsObject



26
27
28
29
30
31
32
33
34
35
36
# File 'app/tasks/resource_tasks.rb', line 26

def self.sync_reading_assignments
  ActiveRecord::Base.transaction do
    %i(units modules grades).each do |level|
      Resource.tree.send(level).find_each do |res|
        res.reading_assignments.destroy_all
        text_ids = res.children.joins(:resource_reading_assignments).pluck(:reading_assignment_text_id).uniq
        text_ids.each { |id| ResourceReadingAssignment.create(resource_id: res.id, reading_assignment_text_id: id) }
      end
    end
  end
end

.update_time_to_teachObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/tasks/resource_tasks.rb', line 38

def self.update_time_to_teach
  ActiveRecord::Base.transaction do
    Resource.lessons.find_each do |res|
      next if res.time_to_teach.present? && res.time_to_teach != 0

      res.update_attributes(time_to_teach: 60)
    end

    %i(units modules grades subjects).each do |level|
      Resource.send(level).find_each do |res|
        total = res.children.map(&:time_to_teach).sum
        res.update_attributes(time_to_teach: total)
      end
    end
  end
end