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.4.27 lib/workarea/seeds.rb
workarea-core-3.5.4 lib/workarea/seeds.rb
workarea-core-3.4.26 lib/workarea/seeds.rb
workarea-core-3.5.3 lib/workarea/seeds.rb
workarea-core-3.4.25 lib/workarea/seeds.rb
workarea-core-3.5.2 lib/workarea/seeds.rb
workarea-core-3.4.24 lib/workarea/seeds.rb
workarea-core-3.5.1 lib/workarea/seeds.rb
workarea-core-3.4.23 lib/workarea/seeds.rb
workarea-core-3.4.22 lib/workarea/seeds.rb
workarea-core-3.5.0 lib/workarea/seeds.rb
workarea-core-3.4.21 lib/workarea/seeds.rb
workarea-core-3.5.0.beta.1 lib/workarea/seeds.rb
workarea-core-3.4.20 lib/workarea/seeds.rb
workarea-core-3.4.19 lib/workarea/seeds.rb
workarea-core-3.4.18 lib/workarea/seeds.rb
workarea-core-3.4.17 lib/workarea/seeds.rb
workarea-core-3.4.16 lib/workarea/seeds.rb
workarea-core-3.4.15 lib/workarea/seeds.rb
workarea-core-3.4.14 lib/workarea/seeds.rb