Sha256: 84c2206d347da1c758a1ac2802ae39ffef6b6a38d8a3263ec09cc407e8f04c39

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

require 'legion/extensions/data/migrator'
require 'legion/extensions/data/model'

module Legion
  module Extensions
    module Data
      include Legion::Extensions::Helpers::Data
      include Legion::Extensions::Helpers::Logger

      def build
        Legion::Logging.fatal 'testing inside run'
        @models = []
        @migrations = []
        if Dir[File.expand_path("#{data_path}/migrations/*.rb")].count.positive?
          log.debug('Has migrations, checking status')
          run
        end

        models = Dir[File.expand_path("#{data_path}/models/*.rb")]
        if models.count.positive?
          log.debug('Including LEX models')
          models.each do |file|
            require file
          end

          models_class.constants.select do |model|
            models_class.const_get(model).extend Legion::Extensions::Data::Model
          end
        end

        true
      end

      def extension_model
        Legion::Data::Model::Extension[namespace: lex_class.to_s]
      end

      def schema_version
        extension_model.values[:schema_version]
      end

      def migrations_path
        "#{data_path}/migrations/"
      end

      def migrate_class
        @migrate_class ||= Legion::Extensions::Data::Migrator.new(migrations_path, lex_class.to_s, lex_name)
      end

      def run
        Legion::Logging.fatal 'testing inside run'

        return true if migrate_class.is_current?

        log.debug('Running LEX schema migrator')
        results = migrate_class.run
        extension_model.update(schema_version: results)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
legionio-1.2.1 lib/legion/extensions/data.rb
legionio-1.2.0 lib/legion/extensions/data.rb