Class: Rox::Core::Registerer
- Inherits:
-
Object
- Object
- Rox::Core::Registerer
- Defined in:
- lib/rox/core/register/registerer.rb
Instance Method Summary collapse
-
#initialize(flag_repository) ⇒ Registerer
constructor
A new instance of Registerer.
- #register_instance(container, namespace) ⇒ Object
Constructor Details
#initialize(flag_repository) ⇒ Registerer
Returns a new instance of Registerer.
4 5 6 7 8 |
# File 'lib/rox/core/register/registerer.rb', line 4 def initialize(flag_repository) @flag_repository = flag_repository @namespaces = [] @mutex = Mutex.new end |
Instance Method Details
#register_instance(container, namespace) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rox/core/register/registerer.rb', line 10 def register_instance(container, namespace) raise ArgumentError, 'A namespace cannot be null' if namespace.nil? @mutex.synchronize do if @namespaces.include?(namespace) raise ArgumentError, "A container with the given namespace (#{namespace}) has already been registered" end end @namespaces << namespace container.instance_variables.each do |attribute_name| begin value = container.instance_variable_get(attribute_name) if !value.nil? && value.is_a?(RoxString) var_name = attribute_name.to_s # removing the attribute starting @ (if [always] exists) var_name[0] = '' if var_name[0] == '@' @flag_repository.add_flag(value, namespace == '' ? var_name : "#{namespace}.#{var_name}") end rescue StandardError next end end end |