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.
- .clear ⇒ Object
- .get_all_bean_files ⇒ Object
- .get_bean_locations(bean) ⇒ Object
-
.get_bean_package(path) ⇒ nil or String
Package name be absolute bean path.
- .load_all ⇒ Object
Class Method Details
.add_bean(package_name, bean, bean_path) ⇒ Object
Returns nil.
22 23 24 25 26 27 28 29 30 |
# File 'lib/smart_ioc/bean_locations.rb', line 22 def add_bean(package_name, bean, bean_path) @data[package_name] ||= {} package_beans = @data[package_name] package_beans[bean] ||= [] package_beans[bean].push(bean_path) nil end |
.clear ⇒ Object
57 58 59 |
# File 'lib/smart_ioc/bean_locations.rb', line 57 def clear @data = {} end |
.get_all_bean_files ⇒ Object
73 74 75 76 77 78 |
# File 'lib/smart_ioc/bean_locations.rb', line 73 def get_all_bean_files @data .map { |_, bean_locations| bean_locations.values } .flatten .uniq end |
.get_bean_locations(bean) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/smart_ioc/bean_locations.rb', line 34 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.
63 64 65 66 67 68 69 70 71 |
# File 'lib/smart_ioc/bean_locations.rb', line 63 def get_bean_package(path) @data.each do |package, bean_locations| if bean_locations.values.flatten.include?(path) return package end end nil end |
.load_all ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/smart_ioc/bean_locations.rb', line 47 def load_all @data.each do |package, bean_locations| bean_locations.each do |bean, paths| paths.each do |path| load(path) end end end end |