Class: FelFlame::Helper::BaseComponent
- Inherits:
-
Object
- Object
- FelFlame::Helper::BaseComponent
- Defined in:
- component_manager.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
-
#attrs ⇒ Object
def initialize_attr(name, default = nil) #TODO: fill this out #TODO: This might be bad form, maybe exclude completly end.
-
#delete ⇒ Object
Returns true.
- #linked_entities ⇒ Object
- #to_i ⇒ Object
-
#to_json ⇒ Object
TODO: Needs to get id and stuff?.
-
#update_attrs(**opts) ⇒ Object
returns hash of updated attributes.
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
34 35 36 |
# File 'component_manager.rb', line 34 def id @id end |
Class Method Details
.[](val) ⇒ Object
41 42 43 |
# File 'component_manager.rb', line 41 def [](val) data[val] end |
.data ⇒ Object
37 38 39 |
# File 'component_manager.rb', line 37 def data @data ||= [] end |
.each ⇒ Object
62 63 64 65 66 |
# File 'component_manager.rb', line 62 def each data.each do |component| yield component end end |
.new(**opts) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'component_manager.rb', line 45 def new(**opts) new_component = super # Generate ID new_id = self.data.find_index { |i| i.nil? } new_id = self.data.size if new_id.nil? new_component.id = new_id # Fill params opts.each do |key, value| new_component.send "#{key}=", value end # Save Component data[new_id] = new_component end |
Instance Method Details
#attrs ⇒ Object
def initialize_attr(name, default = nil)
#TODO: fill this out
#TODO: This might be bad form, maybe exclude completly
end
103 104 105 106 107 |
# File 'component_manager.rb', line 103 def attrs #TODO: maybe optimize removing the @ symbol instance_variables.each_with_object({}) do |key, final| final[key.to_s.delete_prefix('@').to_sym] = instance_variable_get(key) end end |
#delete ⇒ Object
Returns true
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'component_manager.rb', line 85 def delete #TODO: Remove component linked_entities.each do |entity_id| FelFlame::Entities[entity_id].remove self end self.class.data[id] = nil @linked_entities = nil instance_variables.each do |var| instance_variable_set(var, nil) end true end |
#linked_entities ⇒ Object
73 74 75 |
# File 'component_manager.rb', line 73 def linked_entities @linked_entities ||= [] end |
#to_i ⇒ Object
69 70 71 |
# File 'component_manager.rb', line 69 def to_i id end |
#to_json ⇒ Object
TODO: Needs to get id and stuff?
109 110 111 |
# File 'component_manager.rb', line 109 def to_json #TODO: Needs to get id and stuff? # should return a json or hash of all data in this component end |
#update_attrs(**opts) ⇒ Object
returns hash of updated attributes
78 79 80 81 82 |
# File 'component_manager.rb', line 78 def update_attrs(**opts) opts.each do |key, value| send "#{key}=", value end end |