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.



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
   = {}
  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



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
   = 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)


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
  
   = metaclass.send(:instance_variable_get, :@metadata)
  scopes.each { |scope| [:scopes][scope] << block }
end