Class: EacRubyUtils::RootModuleSetup

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

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:



19
20
21
22
# File 'lib/eac_ruby_utils/root_module_setup.rb', line 19

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

Instance Attribute Details

#blockObject

Returns the value of attribute block.



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

def block
  @block
end

#root_module_fileObject

Returns the value of attribute root_module_file.



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

def root_module_file
  @root_module_file
end

Class Method Details

.perform(root_module_file, &block) ⇒ Object

Parameters:



11
12
13
# File 'lib/eac_ruby_utils/root_module_setup.rb', line 11

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

Instance Method Details

#ignore(path) ⇒ Object

Parameters:

  • Relative path to root module’s directory.

Raises:



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/eac_ruby_utils/root_module_setup.rb', line 25

def ignore(path)
  count_before = loader.send(:ignored_paths).count
  target_path = path.to_pathname.basename_sub { |b| "#{b.basename('.*')}.rb" }
                  .expand_path(root_module_directory)
  result = loader.ignore target_path
  return result if result.count > count_before

  raise ::ArgumentError, [
    "Trying to ignore path \"#{path}\" did not increase the ignored paths.",
    "Argument path: \"#{path}\"", "Target path: \"#{target_path}\"", "Ignored paths: #{result}"
  ].join("\n")
end

#performvoid

This method returns an undefined value.



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

def perform
  perform_block
  perform_zeitwerk
end

#root_module_directoryString

Returns:



45
46
47
48
# File 'lib/eac_ruby_utils/root_module_setup.rb', line 45

def root_module_directory
  ::File.expand_path(::File.basename(root_module_file, '.*'),
                     ::File.dirname(root_module_file))
end