Class: SmartIoC::BeanLocations
- Inherits:
-
Object
- Object
- SmartIoC::BeanLocations
- 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
-
.add_bean(package_name, bean, bean_path) ⇒ Object
Nil.
-
.all_bean_names ⇒ Object
Names of all found beans.
- .clear ⇒ Object
- .get_all_bean_files ⇒ Object
- .get_bean_by_path(path) ⇒ Object
- .get_bean_locations(bean) ⇒ Object
-
.get_bean_package(path) ⇒ nil or String
Package name be absolute bean path.
Class Method Details
.add_bean(package_name, bean, bean_path) ⇒ Object
Returns nil.
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_names ⇒ Object
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 |
.clear ⇒ Object
59 60 61 |
# File 'lib/smart_ioc/bean_locations.rb', line 59 def clear @data = {} end |
.get_all_bean_files ⇒ Object
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
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.
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 |