Sha256: 5c01a30de39846baddf55453b07cbcc6f006630ec9f64aaa2d6d70059b0a78c6

Contents?: true

Size: 1.71 KB

Versions: 62

Compression:

Stored size: 1.71 KB

Contents

require 'faker'
I18n.reload! # For faker

module Workarea
  module Seeds
    def self.run
      Workarea.with_config do |config|
        config.send_email = false

        puts_with_color "== Setting up...", :yellow
        reset

        puts_with_color "\n== Loading MongoDB data", :yellow
        Workarea.config.seeds.each { |c| c.constantize.new.perform }

        puts_with_color "\n== Loading Elasticsearch data", :yellow
        Rake::Task['workarea:search_index:all'].invoke
        Catalog::Category.all.each { |c| IndexCategorization.perform(c) }

        puts_with_color "\nSuccess!", :green
      end
    end

    def self.reset
      delete_search_indexes
      delete_mongoid_data
      delete_redis_data
      install

      Rails.cache.clear
    end

    def self.delete_search_indexes
      puts 'Deleting Elasticsearch indexes...'
      Elasticsearch::Document.all.each(&:delete_indexes!)
    end

    def self.delete_mongoid_data
      puts 'Cleaning MongoDB collections...'
      Mongoid::AuditLog::Entry
        .where(audited_type: /^Workarea::/)
        .delete_all

      Mongoid::Clients
        .with_name('default')
        .collections
        .select { |c| c.name =~ /workarea_/ }
        .each(&:drop)
    end

    def self.delete_redis_data
      puts 'Flushing Redis database...'
      Workarea.redis.flushdb
    end

    def self.install
      puts 'Ensuring MongoDB indexes...'
      Rake::Task['db:mongoid:create_indexes'].invoke

      puts 'Ensuring Elasticsearch indexes...'
      Elasticsearch::Document.all.each(&:create_indexes!)
      Search::Storefront.ensure_dynamic_mappings
    end

    def self.puts_with_color(string, color)
      puts "\e[#{Workarea::COLOR_CODES[color]}m#{string}\e[0m"
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 lib/workarea/seeds.rb
workarea-core-3.4.36 lib/workarea/seeds.rb
workarea-core-3.5.14 lib/workarea/seeds.rb
workarea-core-3.4.35 lib/workarea/seeds.rb
workarea-core-3.5.13 lib/workarea/seeds.rb
workarea-core-3.4.34 lib/workarea/seeds.rb
workarea-core-3.5.12 lib/workarea/seeds.rb
workarea-core-3.4.33 lib/workarea/seeds.rb
workarea-core-3.5.11 lib/workarea/seeds.rb
workarea-core-3.5.10 lib/workarea/seeds.rb
workarea-core-3.4.32 lib/workarea/seeds.rb
workarea-core-3.5.9 lib/workarea/seeds.rb
workarea-core-3.4.31 lib/workarea/seeds.rb
workarea-core-3.5.8 lib/workarea/seeds.rb
workarea-core-3.4.30 lib/workarea/seeds.rb
workarea-core-3.5.7 lib/workarea/seeds.rb
workarea-core-3.4.29 lib/workarea/seeds.rb
workarea-core-3.5.6 lib/workarea/seeds.rb
workarea-core-3.4.28 lib/workarea/seeds.rb
workarea-core-3.5.5 lib/workarea/seeds.rb