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.24.1 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_ruby_utils-0.100.0 lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.24.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_ruby_utils-0.99.0 lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.23.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.22.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.21.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.20.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.19.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.18.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.17.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.16.1 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_ruby_utils-0.98.0 lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.16.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.15.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.14.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_ruby_utils-0.97.0 lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.13.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb
eac_ruby_utils-0.96.1 lib/eac_ruby_utils/require_sub/base.rb
eac_tools-0.12.0 sub/eac_ruby_utils/lib/eac_ruby_utils/require_sub/base.rb