Module: Angostura::Dependencies::ClassMethods

Defined in:
lib/angostura/dependencies.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



8
9
10
# File 'lib/angostura/dependencies.rb', line 8

def dependencies
  @dependencies
end

Instance Method Details

#dependency(*args, **kargs) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/angostura/dependencies.rb', line 18

def dependency(*args, **kargs)
  self.dependencies = args + kargs&.keys
  singleton_class.send(:attr_reader, *dependencies)

  dependencies.each do |dependency|
    define_singleton_method "#{dependency}=" do |value|
      raise Angostura::DependencyTypeError.new(value) if !value.is_a? String
      self.class_eval("@#{dependency} = value")
    end

    define_singleton_method "#{dependency}_class" do
      Object.const_get(self.send(dependency))
    end
  end

  kargs.each do |key, default_value|
    send("#{key}=", default_value)
  end
end

#setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



10
11
12
13
14
15
16
# File 'lib/angostura/dependencies.rb', line 10

def setup
  yield self

  dependencies.each do |dependency|
    raise Angostura::DependencyError.new(dependency) if send(dependency).nil?
  end
end