Sha256: 338960035ec33669e5b5177cf123da2048e7b7e79010886a8aa24fc56e7facf3

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module Schemaless
  #
  # Do the twist!
  #
  module Worker
    # Module class methods
    class << self

      #
      # Run Schemaless live mode
      #
      def run!
        # ::Rails.application.eager_load!
        all_tables.each(&:run!)
      end

      #
      # Run Schemaless migrations
      #
      # ::Rails::Generators
      #   .invoke('schemaless:migration', data, file_name: 'fu',
      #           behavior: :invoke, destination_root: Rails.root)
      def generate!
        ::ActiveRecord::Base.establish_connection 'production'
        all_tables.each do |table|
          next unless table.migrate?
          Schemaless::MigrationGenerator.new([table]).invoke_all
        end
      end

      #
      # Work!
      #
      def all_tables # (models)
        tables = []
        models = ::ActiveRecord::Base.descendants
        #fail 'No models...eager load off?' if models.empty?
        models.each do |model|
          next if model.to_s =~ /ActiveRecord::/
          model.reset_column_information
          tables << ::Schemaless::Table.new(model)
        end
        tables
      end
    end # self
  end # Worker
end # Schemaless

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
schemaless-0.0.3 lib/schemaless/worker.rb