Sha256: 4196bd0ea6a537d0971d4e4e3e3d985655daf8b9fbb8ae36b5c324d0dd696157

Contents?: true

Size: 1.07 KB

Versions: 16

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

namespace :oneoff do # rubocop:disable Metrics/BlockLength
  task fix_math_docs_module_metadata: :environment do
    puts '====> Fix Math Documents Module Metadata'
    Document.filter_by_subject('math').each do |d|
      d.metadata['module'] = d.metadata['unit'] unless d.metadata['module']
      d.save
    end
  end

  task fix_level_positions: :environment do
    def consecutive?(level)
      level.zip(0..level.size).all? { |num, index| num == index }
    end

    def fix_positions(res)
      puts "Fix order for #{res.slug}"
      puts "from #{res.children.pluck(:level_position).inspect}"
      res.children.each_with_index do |r, index|
        if r.level_position != index
          r.level_position = index
          r.save!
        end
      end
      puts "to   #{res.reload.children.pluck(:level_position).inspect}\n\n"
    end

    def check_node(res)
      fix_positions(res) unless consecutive? res.children.pluck(:level_position)
      res.children.each { |c| check_node c }
    end

    Resource.tree.roots.each { |r| check_node(r) }
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
lcms-engine-0.5.5 lib/tasks/oneoff.rake
lcms-engine-0.5.4 lib/tasks/oneoff.rake
lcms-engine-0.5.3 lib/tasks/oneoff.rake
lcms-engine-0.5.2 lib/tasks/oneoff.rake
lcms-engine-0.5.1 lib/tasks/oneoff.rake
lcms-engine-0.5.0 lib/tasks/oneoff.rake
lcms-engine-0.4.2 lib/tasks/oneoff.rake
lcms-engine-0.4.1 lib/tasks/oneoff.rake
lcms-engine-0.4.0 lib/tasks/oneoff.rake
lcms-engine-0.3.1 lib/tasks/oneoff.rake
lcms-engine-0.1.4 lib/tasks/oneoff.rake
lcms-engine-0.3.0 lib/tasks/oneoff.rake
lcms-engine-0.1.3 lib/tasks/oneoff.rake
lcms-engine-0.2.0 lib/tasks/oneoff.rake
lcms-engine-0.1.2 lib/tasks/oneoff.rake
lcms-engine-0.1.0 lib/tasks/oneoff.rake