Class: EacRubyBase1::RootModuleSetup

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_ruby_base1/root_module_setup.rb,
lib/eac_ruby_base1/root_module_setup/paths.rb,
lib/eac_ruby_base1/root_module_setup/ignore.rb,
lib/eac_ruby_base1/root_module_setup/patches.rb,
lib/eac_ruby_base1/root_module_setup/requires.rb,
lib/eac_ruby_base1/root_module_setup/zeitwerk.rb,
lib/eac_ruby_base1/root_module_setup/require_patch.rb

Defined Under Namespace

Modules: Patches, Paths, Requires, Zeitwerk Classes: Ignore, RequirePatch

Constant Summary collapse

DEFAULT_NAMESPACE =
::Object
LIB_DIRECTORY_BASENAME =
'lib'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_module_file, &block) ⇒ RootModuleSetup

Returns a new instance of RootModuleSetup.

Parameters:

  • root_module_file (Pathname)


25
26
27
28
# File 'lib/eac_ruby_base1/root_module_setup.rb', line 25

def initialize(root_module_file, &block)
  self.root_module_file = root_module_file.to_pathname
  self.block = block
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



21
22
23
# File 'lib/eac_ruby_base1/root_module_setup.rb', line 21

def block
  @block
end

#logging=(value) ⇒ Object (writeonly)

Sets the attribute logging

Parameters:

  • value

    the value to set the attribute logging to.



22
23
24
# File 'lib/eac_ruby_base1/root_module_setup.rb', line 22

def logging=(value)
  @logging = value
end

Class Method Details

.perform(root_module_file) ⇒ Object

Parameters:

  • root_module_file (Pathname)


16
17
18
# File 'lib/eac_ruby_base1/root_module_setup.rb', line 16

def perform(root_module_file, &)
  new(root_module_file, &).perform
end

Instance Method Details

#extension_forModule?

Returns:

  • (Module, nil)


31
32
33
34
35
36
37
# File 'lib/eac_ruby_base1/root_module_setup.rb', line 31

def extension_for
  dirname = ::File.dirname(relative_root_module_file)
  return nil if ['.', '/', ''].include?(dirname)

  require dirname
  ::ActiveSupport::Inflector.constantize(dirname.camelize)
end

#namespaceModule

Returns:

  • (Module)


40
41
42
# File 'lib/eac_ruby_base1/root_module_setup.rb', line 40

def namespace
  extension_for || DEFAULT_NAMESPACE
end

#performvoid

This method returns an undefined value.



45
46
47
48
49
50
51
# File 'lib/eac_ruby_base1/root_module_setup.rb', line 45

def perform
  perform_block
  perform_zeitwerk
  root_module
  perform_requires
  require_patches
end

#root_modulevoid

This method returns an undefined value.



54
55
56
57
58
# File 'lib/eac_ruby_base1/root_module_setup.rb', line 54

def root_module
  relative_root_module_file.each_filename.inject(DEFAULT_NAMESPACE) do |a, e|
    a.const_get(e.camelize)
  end
end