Class: IocRb::BeanMetadata

Inherits:
Object show all
Defined in:
lib/ioc_rb/bean_metadata.rb

Overview

Stores bean specific data: bean class, name, scope and bean dependencies

Defined Under Namespace

Classes: Attribute, Dsl

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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

Parameters:

  • name (Symbol)

    bean name



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

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

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

  fetch_attrs!(@bean_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/ioc_rb/bean_metadata.rb', line 4

def attrs
  @attrs
end

#bean_classObject (readonly)

Returns the value of attribute bean_class.



4
5
6
# File 'lib/ioc_rb/bean_metadata.rb', line 4

def bean_class
  @bean_class
end

#factory_methodObject (readonly)

Returns the value of attribute factory_method.



4
5
6
# File 'lib/ioc_rb/bean_metadata.rb', line 4

def factory_method
  @factory_method
end

#instanceObject (readonly)

Returns the value of attribute instance.



4
5
6
# File 'lib/ioc_rb/bean_metadata.rb', line 4

def instance
  @instance
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/ioc_rb/bean_metadata.rb', line 4

def name
  @name
end

#scopeObject (readonly)

Returns the value of attribute scope.



4
5
6
# File 'lib/ioc_rb/bean_metadata.rb', line 4

def scope
  @scope
end

Instance Method Details

#fetch_attrs!(klass) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/ioc_rb/bean_metadata.rb', line 34

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

#has_factory_method?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ioc_rb/bean_metadata.rb', line 43

def has_factory_method?
  !!@factory_method
end