Class: Adhearsion::Components::ComponentManager::ComponentDefinitionContainer

Inherits:
Module
  • Object
show all
Defined in:
lib/adhearsion/component_manager.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Module

#relationships

Constructor Details

#initialize(&block) ⇒ ComponentDefinitionContainer

Returns a new instance of ComponentDefinitionContainer.



131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/adhearsion/component_manager.rb', line 131

def initialize(&block)
  # Hide our instance variables in the singleton class
   = {}
  metaclass.send(:instance_variable_set, :@metadata, )
  
  [:scopes] = ComponentManager::SCOPE_NAMES.inject({}) do |scopes, name|
    scopes[name] = []
    scopes
  end
  
  super
  
  meta_def(:initialize) { raise "This object has already been instantiated. Are you sure you didn't mean initialization()?" }
end

Class Method Details

.load_code(code) ⇒ Object



118
119
120
121
122
# File 'lib/adhearsion/component_manager.rb', line 118

def load_code(code)
  returning(new) do |instance|
    instance.module_eval code
  end
end

.load_file(filename) ⇒ Object



124
125
126
127
128
# File 'lib/adhearsion/component_manager.rb', line 124

def load_file(filename)
  returning(new) do |instance|
    instance.module_eval File.read(filename), filename
  end
end

.method_added(method_name) ⇒ Object



169
170
171
172
# File 'lib/adhearsion/component_manager.rb', line 169

def self.method_added(method_name)
  @methods ||= []
  @methods << method_name
end

Instance Method Details

#initialization(&block) ⇒ Object Also known as: initialisation



155
156
157
158
159
160
161
162
163
# File 'lib/adhearsion/component_manager.rb', line 155

def initialization(&block)
  # Raise an exception if the initialization block has already been set
   = metaclass.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

Raises:

  • (ArgumentError)


146
147
148
149
150
151
152
153
# File 'lib/adhearsion/component_manager.rb', line 146

def methods_for(*scopes, &block)
  raise ArgumentError if scopes.empty?
  
  ComponentManager.scopes_valid? scopes
  
   = metaclass.send(:instance_variable_get, :@metadata)
  scopes.each { |scope| [:scopes][scope] << block }
end