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:) ⇒ 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
# File 'lib/smart_ioc/bean_definition.rb', line 7

def initialize(name:, package:, path:, klass:, scope:, context:, instance:, factory_method:)
  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
  @context        = context

  @dependencies = []
end

Instance Attribute Details

#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



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

def ==(bean_definition)
  bean_definition.klass == @klass
end

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



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

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)


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

def has_factory_method?
  !@factory_method.nil?
end

#inspectObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/smart_ioc/bean_definition.rb', line 52

def inspect
  str = []
  str << "class:          #{@klass}"
  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)


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

def is_instance?
  @instance
end