Class: SmartIoC::BeanLocations

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_ioc/bean_locations.rb

Overview

SmartIoC::BeanLocations is a storage for locations of package bean definitions. Storage structure:

PACKAGE_NAME => { BEAN_SYM => BEAN_PATH

} Ex: {

repository: {
  users_repository: ['/app/core/infrastructure/repository/users.rb'],
  posts_repository: ['/app/core/infrastructure/repository/posts.rb']
}

}

Class Method Summary collapse

Class Method Details

.add_bean(package_name, bean, bean_path) ⇒ Object

Returns nil.

Parameters:

  • package_name (Symbol)

    bean package name (ex: :repository)

  • bean (Symbol)

    bean name (ex: :users_repository)

  • bean_path (String)

    bean name (ex: :users_repository)

Returns:

  • nil

Raises:

  • (ArgumentError)

    if bean previous bean definition with same name was found for package



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/smart_ioc/bean_locations.rb', line 23

def add_bean(package_name, bean, bean_path)
  @data[package_name] ||= {}
  package_beans = @data[package_name]

  @paths[bean_path] = bean

  package_beans[bean] ||= []
  package_beans[bean].push(bean_path)

  nil
end

.all_bean_namesObject

Returns names of all found beans.

Returns:

  • names of all found beans



36
37
38
# File 'lib/smart_ioc/bean_locations.rb', line 36

def all_bean_names
  @data.values.flat_map(&:keys)
end

.clearObject



59
60
61
# File 'lib/smart_ioc/bean_locations.rb', line 59

def clear
  @data = {}
end

.get_all_bean_filesObject



75
76
77
78
79
80
# File 'lib/smart_ioc/bean_locations.rb', line 75

def get_all_bean_files
  @data
    .map { |_, bean_locations| bean_locations.values }
    .flatten
    .uniq
end

.get_bean_by_path(path) ⇒ Object



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

def get_bean_by_path(path)
  @paths[path]
end

.get_bean_locations(bean) ⇒ Object

Parameters:

  • bean (Symbol)

    bean name (ex: :users_repository)



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/smart_ioc/bean_locations.rb', line 46

def get_bean_locations(bean)
  locations = {}

  @data.each do |package, bean_locations|
    if bean_locations.has_key?(bean)
      locations[package] ||= []
      locations[package] += bean_locations[bean]
    end
  end

  locations
end

.get_bean_package(path) ⇒ nil or String

Returns package name be absolute bean path.

Parameters:

  • path (String)

    absolute bean path

Returns:

  • (nil or String)

    package name be absolute bean path



65
66
67
68
69
70
71
72
73
# File 'lib/smart_ioc/bean_locations.rb', line 65

def get_bean_package(path)
  @data.each do |package, bean_locations|
    if bean_locations.values.flatten.include?(path)
      return package
    end
  end

  nil
end