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.27 lib/workarea/seeds.rb
workarea-core-3.5.26 lib/workarea/seeds.rb
workarea-core-3.4.45 lib/workarea/seeds.rb
workarea-core-3.5.25 lib/workarea/seeds.rb
workarea-core-3.5.23 lib/workarea/seeds.rb
workarea-core-3.4.44 lib/workarea/seeds.rb
workarea-core-3.5.22 lib/workarea/seeds.rb
workarea-core-3.4.43 lib/workarea/seeds.rb
workarea-core-3.5.21 lib/workarea/seeds.rb
workarea-core-3.4.42 lib/workarea/seeds.rb
workarea-core-3.5.20 lib/workarea/seeds.rb
workarea-core-3.4.41 lib/workarea/seeds.rb
workarea-core-3.5.19 lib/workarea/seeds.rb
workarea-core-3.4.40 lib/workarea/seeds.rb
workarea-core-3.5.18 lib/workarea/seeds.rb
workarea-core-3.4.39 lib/workarea/seeds.rb
workarea-core-3.5.17 lib/workarea/seeds.rb
workarea-core-3.4.38 lib/workarea/seeds.rb
workarea-core-3.5.16 lib/workarea/seeds.rb
workarea-core-3.4.37 lib/workarea/seeds.rb