Class: Callme::DepMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/callme/dep_metadata.rb

Overview

Stores dep specific data: dep class, name, contract, scope and dep dependencies

Defined Under Namespace

Classes: Attribute, Dsl

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, &block) ⇒ DepMetadata

Constructor here attr means setter injection, arg means constructon injects some_dependency is an attr_accessor defined in the dep class, ref specifies what dependency from container to use to set the attribute



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/callme/dep_metadata.rb', line 17

def initialize(name, options, &block)
  Callme::ArgsValidator.has_key!(options, :class)

  @name           = name
  @dep_class      = options[:class]
  @contract       = options[:contract]
  @scope          = options[:scope] || :singleton
  @instance       = options[:instance].nil? ? true : options[:instance]
  @factory_method = options[:factory_method]
  @attrs          = []

  fetch_attrs!(@dep_class)

  if block
    Dsl.new(@attrs).instance_exec(&block)
  end
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



4
5
6
# File 'lib/callme/dep_metadata.rb', line 4

def attrs
  @attrs
end

#contractObject (readonly)

Returns the value of attribute contract.



4
5
6
# File 'lib/callme/dep_metadata.rb', line 4

def contract
  @contract
end

#dep_classObject (readonly)

Returns the value of attribute dep_class.



4
5
6
# File 'lib/callme/dep_metadata.rb', line 4

def dep_class
  @dep_class
end

#factory_methodObject (readonly)

Returns the value of attribute factory_method.



4
5
6
# File 'lib/callme/dep_metadata.rb', line 4

def factory_method
  @factory_method
end

#instanceObject (readonly)

Returns the value of attribute instance.



4
5
6
# File 'lib/callme/dep_metadata.rb', line 4

def instance
  @instance
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/callme/dep_metadata.rb', line 4

def name
  @name
end

#scopeObject (readonly)

Returns the value of attribute scope.



4
5
6
# File 'lib/callme/dep_metadata.rb', line 4

def scope
  @scope
end

Instance Method Details

#fetch_attrs!(klass) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/callme/dep_metadata.rb', line 35

def fetch_attrs!(klass)
  if klass.respond_to?(:_callme_injectable_attrs)
    klass._callme_injectable_attrs.each do |attr, options|
      options[:ref] ||= attr
      @attrs << Callme::::Attribute.new(attr, options)
    end
  end
end

#has_contract?Boolean



48
49
50
# File 'lib/callme/dep_metadata.rb', line 48

def has_contract?
  !!@contract
end

#has_factory_method?Boolean



44
45
46
# File 'lib/callme/dep_metadata.rb', line 44

def has_factory_method?
  !!@factory_method
end