Sha256: f3e12f08ed7d4c29003965d4076c49b6be01f84ccbb2e33dc1d697803f2f67cc

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require "pakyow/support/extension"

require "pakyow/loader"

module Pakyow
  class Application
    module Behavior
      # Maintains known aspects and loads them.
      #
      module Aspects
        extend Support::Extension

        apply_extension do
          setting :aspects, []

          after "load" do
            config.aspects.each do |aspect|
              load_aspect(aspect)
            end
          end
        end

        class_methods do
          # Registers an app aspect by name.
          #
          def aspect(name)
            (config.aspects << name.to_sym).uniq!
          end
        end

        private

        def load_aspect(aspect, path: File.join(config.src, aspect.to_s), target: self.class)
          __load_aspect(aspect, path: path, target: target)
        end

        def __load_aspect(aspect, path: File.join(config.src, aspect.to_s), target: self.class)
          Dir.glob(File.join(path, "*.rb")).sort.each do |file_path|
            Loader.new(file_path).call(target)
          end

          Dir.glob(File.join(path, "*")).select { |sub_path| File.directory?(sub_path) }.sort.each do |directory|
            __load_aspect(aspect, path: directory, target: target)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pakyow-core-1.0.6 lib/pakyow/application/behavior/aspects.rb
pakyow-core-1.0.5 lib/pakyow/application/behavior/aspects.rb
pakyow-core-1.0.4 lib/pakyow/application/behavior/aspects.rb
pakyow-core-1.0.3 lib/pakyow/application/behavior/aspects.rb
pakyow-core-1.0.2 lib/pakyow/application/behavior/aspects.rb