Sha256: b45b3bfb41cab9a25834e80f7415b22eef98776317cf19195b6aacbaaf6ba796

Contents?: true

Size: 1.68 KB

Versions: 27

Compression:

Stored size: 1.68 KB

Contents

module PowerStencil
  module Engine

    module EntitiesDefinition

      SYSTEM_ENTITY_DEFINITION_ENTRY_POINT = 'power_stencil/system_entity_definitions/all'.freeze

      include PowerStencil::Utils::SecureRequire

      def require_definition_files(files_or_dirs, source)
        required_files = []
        files_or_dirs.each do |file_or_dir|
          if File.directory? file_or_dir and File.readable? file_or_dir
            Dir.entries(file_or_dir).grep(/\.rb$/).each do |file|
              required_files << File.join(file_or_dir, file)
            end
            next
          end
          if File.file? file_or_dir and File.readable? file_or_dir
            required_files << file_or_dir
            next
          end
          # This is a ruby library or there is something wrong
          securely_require_with_entity_class_detection file_or_dir, source

        end
        required_files.sort!.each { |file| securely_require_with_entity_class_detection file, source }
        required_files
      end

      private

      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
    end

  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
power_stencil-0.9.4 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.9.3 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.9.2 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.9.1 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.9.0 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.14 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.13 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.12 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.11 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.10 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.9 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.8 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.7 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.6 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.5 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.4 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.3 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.2 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.1 lib/power_stencil/engine/entities_definitions.rb
power_stencil-0.8.0 lib/power_stencil/engine/entities_definitions.rb