Commit 6e2f1c97 authored by Laurent Briais's avatar Laurent Briais

Fix for project specific entity definitions

parent ae585b01
Pipeline #96935138 passed with stage
in 1 minute and 13 seconds
......@@ -21,7 +21,7 @@ module PowerStencil
source_provider = entity_class.entity_type_source_provider
source_provider_display = if source_provider == PowerStencil
"'#{source_provider.name}'"
elsif source_provider == project
elsif source_provider.is_a? project.class
"project '#{source_provider.name}'"
elsif source_provider.is_a? PowerStencil::Plugins::Base
"plugin '#{source_provider.name}'"
......
......@@ -27,7 +27,7 @@ module PowerStencil
source_provider = entity.class.entity_type_source_provider
source_provider_display = if source_provider == PowerStencil
"'#{source_provider.name}'"
elsif source_provider == project
elsif source_provider.is_a? project.class
"project '#{source_provider.name}'"
elsif source_provider.is_a? PowerStencil::Plugins::Base
"plugin '#{source_provider.name}'"
......
require 'power_stencil/project/require_entity_definitions'
module PowerStencil
module Engine
......@@ -21,30 +23,41 @@ module PowerStencil
next
end
# This is a ruby library or there is something wrong
securely_require_with_entity_class_detection file_or_dir, source
# securely_require_with_entity_class_detection file_or_dir, source
securely_require_with_entity_class_detection(source) do
securely_require file_or_dir, fail_on_error: true
end
end
required_files.sort!.each do |file|
securely_require_with_entity_class_detection source do
securely_require file, fail_on_error: true
end
end
required_files.sort!.each { |file| securely_require_with_entity_class_detection file, source }
required_files
end
private
include PowerStencil::Project::RequireEntityDefinition
def load_system_entities_definition
require_definition_files [SYSTEM_ENTITY_DEFINITION_ENTRY_POINT], PowerStencil
end
def securely_require_with_entity_class_detection(entity_definition_file_path, source)
before = PowerStencil::Engine::EntitiesHandling.all_types
securely_require entity_definition_file_path, fail_on_error: true
after = PowerStencil::Engine::EntitiesHandling.all_types
after.reject { |k, _| before.keys.include? k }
.each do |_, plugin_entity_class|
plugin_entity_class.instance_eval do
@entity_type_source_provider = source
end
end
end
# def securely_require_with_entity_class_detection(entity_definition_file_path, source)
# before = PowerStencil::Engine::EntitiesHandling.all_types
# securely_require entity_definition_file_path, fail_on_error: true
# after = PowerStencil::Engine::EntitiesHandling.all_types
# after.reject { |k, _| before.keys.include? k }
# .each do |_, plugin_entity_class|
# plugin_entity_class.instance_eval do
# @entity_type_source_provider = source
# end
# end
# end
end
end
......
require 'power_stencil/project/require_entity_definitions'
module PowerStencil
module Plugins
......@@ -6,25 +8,17 @@ module PowerStencil
def require_plugin_entity_definitions
return unless capabilities[:entity_definitions]
logger.info "Requiring '#{self.name}' plugin entity definitions..."
securely_require_with_entity_class_detection
end
securely_require_with_entity_class_detection(self) do
plugin_definition[:entity_definitions].each do |entity_definition_file_path|
securely_require entity_definition_file_path, fail_on_error: true
end
end
end
private
def securely_require_with_entity_class_detection
before = PowerStencil::Engine::EntitiesHandling.all_types
plugin_definition[:entity_definitions].each do |entity_definition_file_path|
securely_require entity_definition_file_path, fail_on_error: true
end
after = PowerStencil::Engine::EntitiesHandling.all_types
after.reject { |k, _| before.keys.include? k }.each do |_, plugin_entity_class|
plugin = self
plugin_entity_class.instance_eval do
@entity_type_source_provider = plugin
end
end
end
include PowerStencil::Project::RequireEntityDefinition
end
......
......@@ -9,6 +9,7 @@ require 'power_stencil/project/templates'
require 'power_stencil/project/plugins'
require 'power_stencil/project/git'
require 'power_stencil/project/completion'
require 'power_stencil/project/require_entity_definitions'
require 'power_stencil/engine/project_engine'
require 'power_stencil/engine/entity_engine'
......
......@@ -64,7 +64,7 @@ module PowerStencil
source_provider = klass.entity_type_source_provider
source_provider_display = if source_provider == PowerStencil
"'#{source_provider.name}'"
elsif source_provider == self
elsif source_provider.is_a? self.class
"project '#{source_provider.name}'"
elsif source_provider.is_a? PowerStencil::Plugins::Base
"plugin '#{source_provider.name}'"
......
module PowerStencil
module Project
module RequireEntityDefinition
def securely_require_with_entity_class_detection(source, &block)
before = PowerStencil::Engine::EntitiesHandling.all_types
yield
after = PowerStencil::Engine::EntitiesHandling.all_types
after.reject { |k, _| before.keys.include? k }.each do |_, defined_entity_class|
provider = source
defined_entity_class.instance_eval do
@entity_type_source_provider = provider
end
end
end
end
end
end
module PowerStencil
VERSION = '0.9.4'.freeze
VERSION = '0.9.5'.freeze
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment