Module: Flows::Util::InheritableSingletonVars::IsolationStrategy
- Defined in:
- lib/flows/util/inheritable_singleton_vars/isolation_strategy.rb
Overview
Strategy which uses procs to generate initial values in target class and children.
This strategy designed to make fully isolated singleton variables between classes.
Can be applied several times to the same class.
Can be applied in the middle of inheritance chain.
Defined Under Namespace
Modules: InheritanceCallback
Constant Summary collapse
- VAR_MAP_VAR_NAME =
:@inheritable_vars_with_isolation
Class Method Summary collapse
-
.call(klass, attrs_with_default = {}) ⇒ Object
Applies behaviour and defaults for singleton variables.
-
.migrate(from_mod, to_mod) ⇒ Object
private
Moves variables between modules.
Class Method Details
.call(klass, attrs_with_default = {}) ⇒ Object
Note:
Variable names should look like :@var or '@var'.
Applies behaviour and defaults for singleton variables.
59 60 61 62 63 64 65 66 |
# File 'lib/flows/util/inheritable_singleton_vars/isolation_strategy.rb', line 59 def call(klass, attrs_with_default = {}) init_variables_with_default_values(klass, attrs_with_default) var_defaults = attrs_with_default add_variables_to_store(klass, var_defaults) inject_inheritance_hook(klass) end |
.migrate(from_mod, to_mod) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Moves variables between modules
71 72 73 74 75 76 77 78 79 |
# File 'lib/flows/util/inheritable_singleton_vars/isolation_strategy.rb', line 71 def migrate(from_mod, to_mod) new_var_map = from_mod.instance_variable_get(VAR_MAP_VAR_NAME).dup to_mod.instance_variable_set(VAR_MAP_VAR_NAME, new_var_map) new_var_map.each do |name, default_value_proc| to_mod.instance_variable_set(name, default_value_proc.call) end end |