Module: Legion::Extensions::Data

Includes:
Helpers::Data, Helpers::Logger
Defined in:
lib/legion/extensions/data.rb,
lib/legion/extensions/data/model.rb,
lib/legion/extensions/data/migrator.rb

Defined Under Namespace

Modules: Model Classes: Migrator

Constant Summary

Constants included from Helpers::Base

Helpers::Base::NAMESPACE_BOUNDARIES

Instance Method Summary collapse

Methods included from Helpers::Logger

#handle_runner_exception

Methods included from Helpers::Base

#actor_class, #actor_const, #actor_name, #amqp_prefix, #calling_class, #calling_class_array, #from_json, #full_path, #lex_class, #lex_const, #lex_name, #lex_slug, #log_tag, #normalize, #runner_class, #runner_const, #runner_name, #segments, #settings_path, #table_prefix, #to_dotted_hash

Instance Method Details

#buildObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/legion/extensions/data.rb', line 12

def build
  @models = []
  @migrations = []
  if Dir[File.expand_path("#{data_path}/migrations/*.rb")].any?
    log.debug('Has migrations, checking status')
    run
  end

  models = Dir[File.expand_path("#{data_path}/models/*.rb")]
  if models.any?
    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

#extension_modelObject



35
36
37
# File 'lib/legion/extensions/data.rb', line 35

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

#migrate_classObject



47
48
49
# File 'lib/legion/extensions/data.rb', line 47

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

#migrations_pathObject



43
44
45
# File 'lib/legion/extensions/data.rb', line 43

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

#runObject



51
52
53
54
55
56
57
# File 'lib/legion/extensions/data.rb', line 51

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

#schema_versionObject



39
40
41
# File 'lib/legion/extensions/data.rb', line 39

def schema_version
  extension_model.values[:schema_version]
end