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 ...@@ -21,7 +21,7 @@ module PowerStencil
source_provider = entity_class.entity_type_source_provider source_provider = entity_class.entity_type_source_provider
source_provider_display = if source_provider == PowerStencil source_provider_display = if source_provider == PowerStencil
"'#{source_provider.name}'" "'#{source_provider.name}'"
elsif source_provider == project elsif source_provider.is_a? project.class
"project '#{source_provider.name}'" "project '#{source_provider.name}'"
elsif source_provider.is_a? PowerStencil::Plugins::Base elsif source_provider.is_a? PowerStencil::Plugins::Base
"plugin '#{source_provider.name}'" "plugin '#{source_provider.name}'"
......
...@@ -27,7 +27,7 @@ module PowerStencil ...@@ -27,7 +27,7 @@ module PowerStencil
source_provider = entity.class.entity_type_source_provider source_provider = entity.class.entity_type_source_provider
source_provider_display = if source_provider == PowerStencil source_provider_display = if source_provider == PowerStencil
"'#{source_provider.name}'" "'#{source_provider.name}'"
elsif source_provider == project elsif source_provider.is_a? project.class
"project '#{source_provider.name}'" "project '#{source_provider.name}'"
elsif source_provider.is_a? PowerStencil::Plugins::Base elsif source_provider.is_a? PowerStencil::Plugins::Base
"plugin '#{source_provider.name}'" "plugin '#{source_provider.name}'"
......
require 'power_stencil/project/require_entity_definitions'
module PowerStencil module PowerStencil
module Engine module Engine
...@@ -21,30 +23,41 @@ module PowerStencil ...@@ -21,30 +23,41 @@ module PowerStencil
next next
end end
# This is a ruby library or there is something wrong # 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 end
required_files.sort!.each { |file| securely_require_with_entity_class_detection file, source }
required_files required_files
end end
private private
include PowerStencil::Project::RequireEntityDefinition
def load_system_entities_definition def load_system_entities_definition
require_definition_files [SYSTEM_ENTITY_DEFINITION_ENTRY_POINT], PowerStencil require_definition_files [SYSTEM_ENTITY_DEFINITION_ENTRY_POINT], PowerStencil
end end
def securely_require_with_entity_class_detection(entity_definition_file_path, source) # def securely_require_with_entity_class_detection(entity_definition_file_path, source)
before = PowerStencil::Engine::EntitiesHandling.all_types # before = PowerStencil::Engine::EntitiesHandling.all_types
securely_require entity_definition_file_path, fail_on_error: true # securely_require entity_definition_file_path, fail_on_error: true
after = PowerStencil::Engine::EntitiesHandling.all_types # after = PowerStencil::Engine::EntitiesHandling.all_types
after.reject { |k, _| before.keys.include? k } # after.reject { |k, _| before.keys.include? k }
.each do |_, plugin_entity_class| # .each do |_, plugin_entity_class|
plugin_entity_class.instance_eval do # plugin_entity_class.instance_eval do
@entity_type_source_provider = source # @entity_type_source_provider = source
end # end
end # end
end # end
end end
end end
......
require 'power_stencil/project/require_entity_definitions'
module PowerStencil module PowerStencil
module Plugins module Plugins
...@@ -6,25 +8,17 @@ module PowerStencil ...@@ -6,25 +8,17 @@ module PowerStencil
def require_plugin_entity_definitions def require_plugin_entity_definitions
return unless capabilities[:entity_definitions] return unless capabilities[:entity_definitions]
logger.info "Requiring '#{self.name}' plugin entity definitions..." logger.info "Requiring '#{self.name}' plugin entity definitions..."
securely_require_with_entity_class_detection securely_require_with_entity_class_detection(self) do
end plugin_definition[:entity_definitions].each do |entity_definition_file_path|
securely_require entity_definition_file_path, fail_on_error: true
end
end
end
private private
def securely_require_with_entity_class_detection include PowerStencil::Project::RequireEntityDefinition
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
end end
......
...@@ -9,6 +9,7 @@ require 'power_stencil/project/templates' ...@@ -9,6 +9,7 @@ require 'power_stencil/project/templates'
require 'power_stencil/project/plugins' require 'power_stencil/project/plugins'
require 'power_stencil/project/git' require 'power_stencil/project/git'
require 'power_stencil/project/completion' require 'power_stencil/project/completion'
require 'power_stencil/project/require_entity_definitions'
require 'power_stencil/engine/project_engine' require 'power_stencil/engine/project_engine'
require 'power_stencil/engine/entity_engine' require 'power_stencil/engine/entity_engine'
......
...@@ -64,7 +64,7 @@ module PowerStencil ...@@ -64,7 +64,7 @@ module PowerStencil
source_provider = klass.entity_type_source_provider source_provider = klass.entity_type_source_provider
source_provider_display = if source_provider == PowerStencil source_provider_display = if source_provider == PowerStencil
"'#{source_provider.name}'" "'#{source_provider.name}'"
elsif source_provider == self elsif source_provider.is_a? self.class
"project '#{source_provider.name}'" "project '#{source_provider.name}'"
elsif source_provider.is_a? PowerStencil::Plugins::Base elsif source_provider.is_a? PowerStencil::Plugins::Base
"plugin '#{source_provider.name}'" "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 module PowerStencil
VERSION = '0.9.4'.freeze VERSION = '0.9.5'.freeze
end 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