Class: Adhearsion::Components::ComponentManager::ComponentDefinitionContainer
Class Method Summary collapse
Instance Method Summary collapse
- #initialization(&block) ⇒ Object (also: #initialisation)
-
#initialize(&block) ⇒ ComponentDefinitionContainer
constructor
A new instance of ComponentDefinitionContainer.
- #methods_for(*scopes, &block) ⇒ Object
Methods inherited from Module
Constructor Details
#initialize(&block) ⇒ ComponentDefinitionContainer
Returns a new instance of ComponentDefinitionContainer.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/adhearsion/component_manager.rb', line 132 def initialize(&block) # Hide our instance variables in the singleton class = {} .send(:instance_variable_set, :@metadata, ) [:scopes] = ComponentManager::SCOPE_NAMES.inject({}) do |scopes, name| scopes[name] = [] scopes end super (:initialize) { raise "This object has already been instantiated. Are you sure you didn't mean initialization()?" } end |
Class Method Details
.load_code(code) ⇒ Object
119 120 121 122 123 |
# File 'lib/adhearsion/component_manager.rb', line 119 def load_code(code) returning(new) do |instance| instance.module_eval code end end |
.load_file(filename) ⇒ Object
125 126 127 128 129 |
# File 'lib/adhearsion/component_manager.rb', line 125 def load_file(filename) returning(new) do |instance| instance.module_eval File.read(filename), filename end end |
.method_added(method_name) ⇒ Object
170 171 172 173 |
# File 'lib/adhearsion/component_manager.rb', line 170 def self.method_added(method_name) @methods ||= [] @methods << method_name end |
Instance Method Details
#initialization(&block) ⇒ Object Also known as: initialisation
156 157 158 159 160 161 162 163 164 |
# File 'lib/adhearsion/component_manager.rb', line 156 def initialization(&block) # Raise an exception if the initialization block has already been set = .send(:instance_variable_get, :@metadata) if [:initialization_block] raise "You should only have one initialization() block!" else [:initialization_block] = block end end |
#methods_for(*scopes, &block) ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'lib/adhearsion/component_manager.rb', line 147 def methods_for(*scopes, &block) raise ArgumentError if scopes.empty? ComponentManager.scopes_valid? scopes = .send(:instance_variable_get, :@metadata) scopes.each { |scope| [:scopes][scope] << block } end |