Module: TTY::Config::DependencyLoader

Defined in:
lib/tty/config/dependency_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dep_nameObject

Returns the value of attribute dep_name


6
7
8
# File 'lib/tty/config/dependency_loader.rb', line 6

def dep_name
  @dep_name
end

Instance Method Details

#dependency(*dep_names, &block) ⇒ Object

Lazy load a dependency


11
12
13
14
# File 'lib/tty/config/dependency_loader.rb', line 11

def dependency(*dep_names, &block)
  self.dep_name = dep_names
  @block = block
end

#inherited(subclass) ⇒ Object


35
36
37
38
# File 'lib/tty/config/dependency_loader.rb', line 35

def inherited(subclass)
  super
  subclass.send(:dep_name=, dep_name)
end

#loadObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Try loading depedency


27
28
29
30
31
32
33
# File 'lib/tty/config/dependency_loader.rb', line 27

def load
  return if dep_name.nil?

  dep_name.empty? ? @block.() : dep_name.each { |dep| require(dep) }
rescue LoadError, NameError => err
  raise DependencyLoadError, "#{raise_error_message} #{err.message}"
end

#newObject

Load dependency before object instatiation


19
20
21
22
# File 'lib/tty/config/dependency_loader.rb', line 19

def new(*)
  load
  super
end