Sha256: 5349fb1eb40ed0a0815d55ee61f8b5119da512139e7369e7a5aa6da5400f9402

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 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
        @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)
      end

      def 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

6 entries across 6 versions & 1 rubygems

Version Path
legionio-0.4.3 lib/legion/extensions/data.rb
legionio-0.4.2 lib/legion/extensions/data.rb
legionio-0.4.1 lib/legion/extensions/data.rb
legionio-0.4.0 lib/legion/extensions/data.rb
legionio-0.3.2 lib/legion/extensions/data.rb
legionio-0.3.1 lib/legion/extensions/data.rb