Class: SmartIoC::BeanDefinition

Inherits:
Object
  • Object
show all
Includes:
Args
Defined in:
lib/smart_ioc/bean_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Args

#check_arg, #check_arg_any, #not_nil

Constructor Details

#initialize(name:, package:, path:, klass:, scope:, context:, instance:, factory_method:, after_init:) ⇒ BeanDefinition

Returns a new instance of BeanDefinition.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/smart_ioc/bean_definition.rb', line 7

def initialize(name:, package:, path:, klass:, scope:, context:, instance:, factory_method:, after_init:)
  not_nil(name, :name)
  not_nil(package, :package)
  not_nil(path, :path)
  not_nil(klass, :klass)
  not_nil(scope, :scope)
  not_nil(context, :context)
  not_nil(instance, :instance)

  @name           = name
  @package        = package
  @path           = path
  @klass          = klass
  @scope          = scope
  @instance       = instance
  @factory_method = factory_method
  @after_init     = after_init
  @context        = context

  @dependencies = []
end

Instance Attribute Details

#after_initObject (readonly)

Returns the value of attribute after_init.



4
5
6
# File 'lib/smart_ioc/bean_definition.rb', line 4

def after_init
  @after_init
end

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/smart_ioc/bean_definition.rb', line 4

def context
  @context
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



4
5
6
# File 'lib/smart_ioc/bean_definition.rb', line 4

def dependencies
  @dependencies
end

#factory_methodObject (readonly)

Returns the value of attribute factory_method.



4
5
6
# File 'lib/smart_ioc/bean_definition.rb', line 4

def factory_method
  @factory_method
end

#instanceObject (readonly)

Returns the value of attribute instance.



4
5
6
# File 'lib/smart_ioc/bean_definition.rb', line 4

def instance
  @instance
end

#klassObject (readonly)

Returns the value of attribute klass.



4
5
6
# File 'lib/smart_ioc/bean_definition.rb', line 4

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/smart_ioc/bean_definition.rb', line 4

def name
  @name
end

#packageObject (readonly)

Returns the value of attribute package.



4
5
6
# File 'lib/smart_ioc/bean_definition.rb', line 4

def package
  @package
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/smart_ioc/bean_definition.rb', line 4

def path
  @path
end

#scopeObject (readonly)

Returns the value of attribute scope.



4
5
6
# File 'lib/smart_ioc/bean_definition.rb', line 4

def scope
  @scope
end

Instance Method Details

#==(bean_definition) ⇒ Object



49
50
51
# File 'lib/smart_ioc/bean_definition.rb', line 49

def ==(bean_definition)
  bean_definition.name == @name && bean_definition.package == @package && bean_definition.context == @context
end

#add_dependency(bean_name:, ref: nil, package: nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/smart_ioc/bean_definition.rb', line 29

def add_dependency(bean_name:, ref: nil, package: nil)
  check_arg(bean_name, :bean_name, Symbol)
  check_arg(ref, :ref, Symbol) if ref
  check_arg(package, :package, Symbol) if package

  @dependencies << SmartIoC::BeanDependency.new(
    bean:    bean_name,
    ref:     ref,
    package: package
  )
end

#has_factory_method?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/smart_ioc/bean_definition.rb', line 45

def has_factory_method?
  !@factory_method.nil?
end

#inspectObject



57
58
59
60
61
62
63
64
65
66
# File 'lib/smart_ioc/bean_definition.rb', line 57

def inspect
  str = []
  str << "name:           :#{@name}"
  str << "package:        :#{@package}"
  str << "context:        :#{@context}"
  str << "path:           #{@path}"
  str << "instance:       #{@instance}"
  str << "factory_method: #{@factory_method}"
  str.join("\n")
end

#is_instance?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/smart_ioc/bean_definition.rb', line 41

def is_instance?
  @instance
end

#preloadObject



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/smart_ioc/bean_definition.rb', line 68

def preload
  @dependencies.each do |dep|
    bd = SmartIoC.get_bean_definition(
      dep.ref,
      package: dep.package,
      parent_bean_definition: self,
      parent_bean_name: name,
    )

    bd.preload
  end
end

#singleton?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/smart_ioc/bean_definition.rb', line 53

def singleton?
  SmartIoC::Scopes::Singleton::VALUE == @scope
end