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
Instance Method Summary
collapse
#handle_exception, #log
#data_class, #data_path, #models_class
#actor_class, #actor_const, #actor_name, #calling_class, #calling_class_array, #from_json, #full_path, #lex_class, #lex_const, #lex_name, #normalize, #runner_class, #runner_const, #runner_name, #to_dotted_hash
Instance Method Details
#build ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/legion/extensions/data.rb', line 10
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
|
#extension_model ⇒ Object
33
34
35
|
# File 'lib/legion/extensions/data.rb', line 33
def extension_model
Legion::Data::Model::Extension[namespace: lex_class.to_s]
end
|
#migrate_class ⇒ Object
45
46
47
|
# File 'lib/legion/extensions/data.rb', line 45
def migrate_class
@migrate_class ||= Legion::Extensions::Data::Migrator.new(migrations_path, lex_class.to_s)
end
|
#migrations_path ⇒ Object
41
42
43
|
# File 'lib/legion/extensions/data.rb', line 41
def migrations_path
"#{data_path}/migrations/"
end
|
#run ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/legion/extensions/data.rb', line 49
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_version ⇒ Object
37
38
39
|
# File 'lib/legion/extensions/data.rb', line 37
def schema_version
extension_model.values[:schema_version]
end
|