Sha256: 90460c18641c70b81a025e5ea080b1a867e4fc8020b8ce6e11890d5f79d2ed78

Contents?: true

Size: 1.68 KB

Versions: 100

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/listable'
require 'eac_ruby_utils/require_sub/sub_file'

module EacRubyUtils
  module RequireSub
    class Base
      INCLUDE_MODULES_MAP = {
        nil => nil,
        false => nil,
        true => :include,
        include: :include,
        prepend: :prepend
      }.freeze

      include ::EacRubyUtils::Listable
      lists.add_symbol :option, :base, :include_modules, :require_dependency

      attr_reader :file, :options

      def initialize(file, options = {})
        @file = file
        @options = self.class.lists.option.hash_keys_validate!(options)
      end

      # @return [Boolean]
      def active_support_require?
        options[OPTION_REQUIRE_DEPENDENCY] ? true : false
      end

      def apply
        require_sub_files
        include_modules
      end

      def base
        options[OPTION_BASE] || raise('Option :base not setted')
      end

      def base?
        options[OPTION_BASE] ? true : false
      end

      def include_modules
        sub_files.each(&:include_module)
      end

      def include_or_prepend_method
        return INCLUDE_MODULES_MAP.fetch(options[OPTION_INCLUDE_MODULES]) if
        INCLUDE_MODULES_MAP.key?(options[OPTION_INCLUDE_MODULES])

        raise ::ArgumentError, "Invalid value for 'options[OPTION_INCLUDE_MODULES]':" \
          " \"#{options[OPTION_INCLUDE_MODULES]}\""
      end

      def require_sub_files
        sub_files.each(&:require_file)
      end

      def sub_files
        @sub_files ||= Dir["#{File.dirname(file)}/#{::File.basename(file, '.*')}/*.rb"].sort
                         .map { |path| ::EacRubyUtils::RequireSub::SubFile.new(self, path) }
      end
    end
  end
end

Version data entries

100 entries across 100 versions & 2 rubygems

Version Path
eac_tools-0.62.1 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.62.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.61.1 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.61.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.60.3 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.60.2 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.60.1 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.60.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.59.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.58.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.57.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.56.1 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.56.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.55.7 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.55.6 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.55.5 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.55.4 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.55.3 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.55.2 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_ruby_utils-0.112.0 lib/eac_ruby_utils/require_sub/base.rb