Class: EacRubyUtils::RequireSub::SubFile

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_ruby_utils/require_sub.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, path) ⇒ SubFile



70
71
72
73
# File 'lib/eac_ruby_utils/require_sub.rb', line 70

def initialize(owner, path)
  @owner = owner
  @path = path
end

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.



68
69
70
# File 'lib/eac_ruby_utils/require_sub.rb', line 68

def owner
  @owner
end

#pathObject (readonly)

Returns the value of attribute path.



68
69
70
# File 'lib/eac_ruby_utils/require_sub.rb', line 68

def path
  @path
end

Instance Method Details

#base_constantObject



75
76
77
78
79
80
81
# File 'lib/eac_ruby_utils/require_sub.rb', line 75

def base_constant
  return nil unless owner.base?

  owner.base.const_get(constant_name)
rescue ::NameError
  nil
end

#constant_nameObject



83
84
85
# File 'lib/eac_ruby_utils/require_sub.rb', line 83

def constant_name
  ::ActiveSupport::Inflector.camelize(::File.basename(path, '.rb'))
end

#include_moduleObject



87
88
89
90
91
92
93
# File 'lib/eac_ruby_utils/require_sub.rb', line 87

def include_module
  return unless module?

  owner.include_or_prepend_method.if_present do |v|
    owner.base.send(v, base_constant)
  end
end

#include_or_prepend_methodObject



95
96
97
98
99
100
# File 'lib/eac_ruby_utils/require_sub.rb', line 95

def include_or_prepend_method
  return :include if owner.options[OPTION_INCLUDE_MODULES]
  return :prepend if owner.options[OPTION_PREPEND_MODULES]

  nil
end

#module?Boolean



102
103
104
# File 'lib/eac_ruby_utils/require_sub.rb', line 102

def module?
  base_constant.is_a?(::Module) && !base_constant.is_a?(::Class)
end

#require_fileObject



106
107
108
# File 'lib/eac_ruby_utils/require_sub.rb', line 106

def require_file
  active_support_require || autoload_require || kernel_require
end