Class: FelFlame::Components
- Inherits:
-
Object
- Object
- FelFlame::Components
- Extended by:
- Enumerable
- Defined in:
- felflame.rb,
component_manager.rb
Overview
Creates component managers and allows accessing them them under the Components namespace as Constants
To see how component managers are used please look at the Helper::ComponentManagerTemplate documentation.
TODO: Improve Component overview
Class Method Summary collapse
-
.each(&block) ⇒ Enumerator
Iterate over all existing component managers.
-
.new(component_name, *attrs, **attrs_with_defaults) ⇒ ComponentManager
Creates a new component manager.
Class Method Details
.each(&block) ⇒ Enumerator
Iterate over all existing component managers. You also call other enumerable methods instead of each, such as each_with_index or select
50 51 52 |
# File 'component_manager.rb', line 50 def each(&block) constants.each(&block) end |
.new(component_name, *attrs, **attrs_with_defaults) ⇒ ComponentManager
Creates a new component manager.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'component_manager.rb', line 23 def new(component_name, *attrs, **attrs_with_defaults) if FelFlame::Components.const_defined?(component_name) raise(NameError.new, "Component Manager '#{component_name}' is already defined") end const_set(component_name, Class.new(FelFlame::Helper::ComponentManager) {}) attrs.each do |attr| FelFlame::Components.const_get(component_name).attr_accessor attr end attrs_with_defaults.each do |attr, _default| #FelFlame::Components.const_get(component_name).attr_accessor attr FelFlame::Components.const_get(component_name).attr_reader attr FelFlame::Components.const_get(component_name).define_method("#{attr}=") do |value| attr_changed_trigger_systems(attr) unless value.equal? send(attr) instance_variable_set("@#{attr}", value) end end FelFlame::Components.const_get(component_name).define_method(:set_defaults) do attrs_with_defaults.each do |attr, default| instance_variable_set("@#{attr}", default) end end FelFlame::Components.const_get(component_name) end |