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



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

.clearObject



57
58
59
# File 'lib/smart_ioc/bean_locations.rb', line 57

def clear
  @data = {}
end

.get_all_bean_filesObject



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

Parameters:

  • bean (Symbol)

    bean name (ex: :users_repository)



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.

Parameters:

  • path (String)

    absolute bean path

Returns:

  • (nil or String)

    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_allObject



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