Class: EacRubyUtils::RequireSub::SubFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, path) ⇒ SubFile

Returns a new instance of SubFile.



11
12
13
14
# File 'lib/eac_ruby_utils/require_sub/sub_file.rb', line 11

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

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.



9
10
11
# File 'lib/eac_ruby_utils/require_sub/sub_file.rb', line 9

def owner
  @owner
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/eac_ruby_utils/require_sub/sub_file.rb', line 9

def path
  @path
end

Instance Method Details

#base_constantObject



16
17
18
19
20
21
22
# File 'lib/eac_ruby_utils/require_sub/sub_file.rb', line 16

def base_constant
  return nil unless owner.base?

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

#constant_nameObject



24
25
26
# File 'lib/eac_ruby_utils/require_sub/sub_file.rb', line 24

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

#include_moduleObject



28
29
30
31
32
33
34
# File 'lib/eac_ruby_utils/require_sub/sub_file.rb', line 28

def include_module
  return unless module?

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

#module?Boolean

Returns:



36
37
38
# File 'lib/eac_ruby_utils/require_sub/sub_file.rb', line 36

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

#require_fileObject



40
41
42
# File 'lib/eac_ruby_utils/require_sub/sub_file.rb', line 40

def require_file
  send("#{owner.require_mode}_require")
end