Class: EacRubyUtils::RequireSub::Base
- Includes:
- Listable
- Defined in:
- lib/eac_ruby_utils/require_sub/base.rb
Constant Summary collapse
- INCLUDE_MODULES_MAP =
{ nil => nil, false => nil, true => :include, include: :include, prepend: :prepend }.freeze
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #active_support_require? ⇒ Boolean
- #apply ⇒ Object
- #base ⇒ Object
- #base? ⇒ Boolean
- #include_modules ⇒ Object
- #include_or_prepend_method ⇒ Object
-
#initialize(file, options = {}) ⇒ Base
constructor
A new instance of Base.
- #require_mode ⇒ Symbol
- #require_sub_files ⇒ Object
- #sub_files ⇒ Object
Constructor Details
#initialize(file, options = {}) ⇒ Base
Returns a new instance of Base.
23 24 25 26 27 28 29 |
# File 'lib/eac_ruby_utils/require_sub/base.rb', line 23 def initialize(file, = {}) @file = file @options = self.class.lists.option.hash_keys_validate!() return unless [OPTION_REQUIRE_MODE] self.class.lists.require_mode.value_validate!([OPTION_REQUIRE_MODE]) end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
21 22 23 |
# File 'lib/eac_ruby_utils/require_sub/base.rb', line 21 def file @file end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
21 22 23 |
# File 'lib/eac_ruby_utils/require_sub/base.rb', line 21 def @options end |
Instance Method Details
#active_support_require? ⇒ Boolean
32 33 34 |
# File 'lib/eac_ruby_utils/require_sub/base.rb', line 32 def active_support_require? [OPTION_REQUIRE_DEPENDENCY] ? true : false end |
#apply ⇒ Object
36 37 38 39 |
# File 'lib/eac_ruby_utils/require_sub/base.rb', line 36 def apply require_sub_files include_modules end |
#base ⇒ Object
41 42 43 |
# File 'lib/eac_ruby_utils/require_sub/base.rb', line 41 def base [OPTION_BASE] || raise('Option :base not setted') end |
#base? ⇒ Boolean
45 46 47 |
# File 'lib/eac_ruby_utils/require_sub/base.rb', line 45 def base? [OPTION_BASE] ? true : false end |
#include_modules ⇒ Object
49 50 51 |
# File 'lib/eac_ruby_utils/require_sub/base.rb', line 49 def include_modules sub_files.each(&:include_module) end |
#include_or_prepend_method ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/eac_ruby_utils/require_sub/base.rb', line 53 def include_or_prepend_method return INCLUDE_MODULES_MAP.fetch([OPTION_INCLUDE_MODULES]) if INCLUDE_MODULES_MAP.key?([OPTION_INCLUDE_MODULES]) raise ::ArgumentError, "Invalid value for 'options[OPTION_INCLUDE_MODULES]': " \ "\"#{[OPTION_INCLUDE_MODULES]}\"" end |
#require_mode ⇒ Symbol
62 63 64 65 66 67 68 |
# File 'lib/eac_ruby_utils/require_sub/base.rb', line 62 def require_mode return [OPTION_REQUIRE_MODE] if [OPTION_REQUIRE_MODE] return REQUIRE_MODE_ACTIVE_SUPPORT if active_support_require? return REQUIRE_MODE_AUTOLOAD if base? REQUIRE_MODE_KERNEL end |
#require_sub_files ⇒ Object
70 71 72 |
# File 'lib/eac_ruby_utils/require_sub/base.rb', line 70 def require_sub_files sub_files.each(&:require_file) end |
#sub_files ⇒ Object
74 75 76 77 |
# File 'lib/eac_ruby_utils/require_sub/base.rb', line 74 def sub_files @sub_files ||= Dir["#{File.dirname(file)}/#{::File.basename(file, '.*')}/*.rb"].sort .map { |path| ::EacRubyUtils::RequireSub::SubFile.new(self, path) } end |