summaryrefslogtreecommitdiffhomepage
path: root/lib/felflame
diff options
context:
space:
mode:
Diffstat (limited to 'lib/felflame')
-rw-r--r--lib/felflame/component_manager.rb169
-rw-r--r--lib/felflame/entity_manager.rb124
-rw-r--r--lib/felflame/order.rb24
-rw-r--r--lib/felflame/scene_manager.rb35
-rw-r--r--lib/felflame/stage_manager.rb43
-rw-r--r--lib/felflame/system_manager.rb139
-rw-r--r--lib/felflame/version.rb2
7 files changed, 323 insertions, 213 deletions
diff --git a/lib/felflame/component_manager.rb b/lib/felflame/component_manager.rb
index 43932d2..6ac7463 100644
--- a/lib/felflame/component_manager.rb
+++ b/lib/felflame/component_manager.rb
@@ -1,8 +1,9 @@
-class FelFlame
- class Components
+# frozen_string_literal: true
+
+module FelFlame
+ module Components
@component_map = []
- class <<self
- include Enumerable
+ class << self
# Creates a new {FelFlame::ComponentManager component manager}.
#
# @example
@@ -21,13 +22,14 @@ class FelFlame
raise(NameError.new, "Component Manager '#{component_name}' is already defined")
end
-
const_set(component_name, Class.new(FelFlame::ComponentManager) {})
+ update_const_cache
attrs.each do |attr|
- if FelFlame::Components.const_get(component_name).method_defined?("#{attr}") || FelFlame::Components.const_get(component_name).method_defined?("#{attr}=")
- raise NameError.new "The attribute name \"#{attr}\" is already a method"
+ if FelFlame::Components.const_get(component_name).method_defined?(attr.to_s) || FelFlame::Components.const_get(component_name).method_defined?("#{attr}=")
+ raise NameError, "The attribute name \"#{attr}\" is already a method"
end
+
FelFlame::Components.const_get(component_name).attr_accessor attr
end
attrs_with_defaults.each do |attr, _default|
@@ -46,28 +48,54 @@ class FelFlame
FelFlame::Components.const_get(component_name)
end
- # Iterate over all existing component managers. You also call other enumerable methods instead of each, such as +each_with_index+ or +select+
- # @return [Enumerator]
- def each(&block)
- constants.each(&block)
+ # Stores the components managers in {FelFlame::Components}. This
+ # is needed because calling `FelFlame::Components.constants`
+ # will not let you iterate over the value of the constants
+ # but will instead give you an array of symbols. This caches
+ # the convertion of those symbols to the actual value of the
+ # constants
+ # @!visibility private
+ def const_cache
+ @const_cache || update_const_cache
+ end
+
+ # Updates the array that stores the constants.
+ # Used internally by FelFlame
+ # @!visibility private
+ def update_const_cache
+ @const_cache = constants.map do |constant|
+ const_get constant
+ end
+ end
+
+ # Forwards undefined methods to the array of constants
+ # if the array can handle the request. Otherwise tells
+ # the programmer their code errored
+ # @!visibility private
+ def respond_to_missing?(method, *)
+ if const_cache.respond_to? method
+ true
+ else
+ super
+ end
+ end
+
+ # Makes component module behave like arrays with additional
+ # methods for managing the array
+ # @!visibility private
+ def method_missing(method, *args, **kwargs, &block)
+ if const_cache.respond_to? method
+ const_cache.send(method, *args, **kwargs, &block)
+ else
+ super
+ end
end
end
end
# Component Managers are what is used to create individual components which can be attached to entities.
- # When a Component is created from a Component Manager that has accessors given to it, you can set or get the values of those accessors using standard ruby message sending (e.g [email protected] = 5+), or by using the {#attrs} and {#update_attrs} methods instead.
+ # When a Component is created from a Component Manager that has accessors given to it, you can set or get the values of those accessors using standard ruby message sending (e.g [email protected] = 5+), or by using the {#to_h} and {#update_attrs} methods instead.
class ComponentManager
-
- # Holds the {id unique ID} of a component. The {id ID} is only unique within the scope of the component manager it was created from.
- # @return [Integer]
- attr_reader :id
-
- # A seperate attr_writer was made for documentation readability reasons.
- # Yard will list attr_reader is readonly which is my intention.
- # This value needs to be changable as it is set by other functions.
- # @!visibility private
- attr_writer :id
-
# Allows overwriting the storage of triggers, such as for clearing.
# This method should generally only need to be used internally and
# not by a game developer.
@@ -104,24 +132,40 @@ class FelFlame
def initialize(**attrs)
# Prepare the object
# (this is a function created with metaprogramming
- # in FelFlame::Components
+ # in FelFlame::Components)
set_defaults
- # Generate ID
- new_id = self.class.data.find_index { |i| i.nil? }
- new_id = self.class.data.size if new_id.nil?
- @id = new_id
-
# Fill params
attrs.each do |key, value|
send "#{key}=", value
end
# Save Component
- self.class.data[new_id] = self
+ self.class.push self
end
- class <<self
+ class << self
+ # Makes component managers behave like arrays with additional
+ # methods for managing the array
+ # @!visibility private
+ def respond_to_missing?(method, *)
+ if _data.respond_to? method
+ true
+ else
+ super
+ end
+ end
+
+ # Makes component managers behave like arrays with additional
+ # methods for managing the array
+ # @!visibility private
+ def method_missing(method, *args, **kwargs, &block)
+ if _data.respond_to? method
+ _data.send(method, *args, **kwargs, &block)
+ else
+ super
+ end
+ end
# Allows overwriting the storage of triggers, such as for clearing.
# This method should generally only need to be used internally and
@@ -155,41 +199,28 @@ class FelFlame
# @return [Array<Component>] Array of all Components that belong to a given component manager
# @!visibility private
- def data
+ def _data
@data ||= []
end
-
- # Gets a Component from the given {id unique ID}. Usage is simular to how an Array lookup works.
- #
- # @example
- # # this gets the 'Health' Component with ID 7
- # FelFlame::Components::Health[7]
- # @param component_id [Integer]
- # @return [Component] Returns the Component that uses the given unique {id ID}, nil if there is no Component associated with the given {id ID}
- def [](component_id)
- data[component_id]
- end
-
- # Iterates over all components within the component manager.
- # Special Enumerable methods like +map+ or +each_with_index+ are not implemented
- # @return [Enumerator]
- def each(&block)
- data.compact.each(&block)
- end
- end
-
- # An alias for the {id ID Reader}
- # @return [Integer]
- def to_i
- id
end
- # A list of entity ids that are linked to the component
- # @return [Array<Integer>]
+ # Entities that have this component
+ # @return [Array<Component>]
def entities
@entities ||= []
end
+ # A single entity. Use this if you expect the component to only belong to one entity and you want to access it.
+ # @return [Component]
+ def entity
+ if entities.empty?
+ Warning.warn("This component belongs to NO entities but you called the method that is intended for components belonging to a single entity.\nYou may have a bug in your logic.")
+ elsif entities.length > 1
+ Warning.warn("This component belongs to MANY entities but you called the method that is intended for components belonging to a single entity.\nYou may have a bug in your logic.")
+ end
+ entities.first
+ end
+
# Update attribute values using a hash or keywords.
# @return [Hash<Symbol, Value>] Hash of updated attributes
def update_attrs(**opts)
@@ -200,39 +231,35 @@ class FelFlame
# Execute systems that have been added to execute on variable change
# @return [Boolean] +true+
+ # @!visibility private
def attr_changed_trigger_systems(attr)
systems_to_execute = self.class.attr_triggers[attr]
systems_to_execute = [] if systems_to_execute.nil?
systems_to_execute |= attr_triggers[attr] unless attr_triggers[attr].nil?
- systems_to_execute.sort_by(&:priority).reverse.each(&:call)
+ systems_to_execute.sort_by(&:priority).reverse_each(&:call)
true
end
- # Removes this component from the list and purges all references to this Component from other Entities, as well as its {id ID} and data.
+ # Removes this component from the list and purges all references to this Component from other Entities, as well as its data.
# @return [Boolean] +true+.
def delete
addition_triggers.each do |system|
system.clear_triggers component_or_manager: self
end
- # This needs to be cloned because indices get deleted as
- # the remove command is called, breaking the loop if it
- # wasn't referencing a clone(will get Nil errors)
- iter = entities.map(&:clone)
- iter.each do |entity|
- #FelFlame::Entities[entity_id].remove self #unless FelFlame::Entities[entity_id].nil?
+ entities.reverse_each do |entity|
entity.remove self
end
- self.class.data[id] = nil
+ self.class._data.delete self
instance_variables.each do |var|
instance_variable_set(var, nil)
end
true
end
- # @return [Hash<Symbol, Value>] A hash, where all the keys are attributes linked to their respective values.
- def attrs
+ # @return [Hash<Symbol, Value>] A hash, where all the keys are attributes storing their respective values.
+ def to_h
return_hash = instance_variables.each_with_object({}) do |key, final|
final[key.to_s.delete_prefix('@').to_sym] = instance_variable_get(key)
end
@@ -243,8 +270,8 @@ class FelFlame
# Export all data into a JSON String, which could then later be loaded or saved to a file
# TODO: This function is not yet complete
# @return [String] a JSON formatted String
- #def to_json
+ # def to_json
# # should return a json or hash of all data in this component
- #end
+ # end
end
end
diff --git a/lib/felflame/entity_manager.rb b/lib/felflame/entity_manager.rb
index a05ef93..ef70510 100644
--- a/lib/felflame/entity_manager.rb
+++ b/lib/felflame/entity_manager.rb
@@ -1,53 +1,53 @@
-class FelFlame
- class Entities
- # Holds the unique ID of this entity
- # @return [Integer]
- attr_reader :id
-
- # A seperate attr_writer was made for documentation readability reasons.
- # Yard will list attr_reader is readonly which is my intention.
- # This value needs to be changable as it is set by other functions.
- # @!visibility private
- attr_writer :id
+# frozen_string_literal: true
+module FelFlame
+ class Entities
# Creating a new Entity
# @param components [Components] Can be any number of components, identical duplicates will be automatically purged however different components from the same component manager are allowed.
# @return [Entity]
def initialize(*components)
- # Assign new unique ID
- new_id = self.class.data.find_index(&:nil?)
- new_id = self.class.data.size if new_id.nil?
- self.id = new_id
-
# Add each component
add(*components)
-
- self.class.data[id] = self
+ self.class._data.push self
end
- # A hash that uses component manager constant names as keys, and where the values of those keys are arrays that contain the {FelFlame::ComponentManager#id IDs} of the components attached to this entity.
+ # A hash that uses component manager constant names as keys, and where the values of those keys are arrays that contain the the components attached to this entity.
# @return [Hash<Component_Manager, Array<Integer>>]
def components
@components ||= {}
end
- # An alias for the {#id ID reader}
- # @return [Integer]
- def to_i
- id
+ # A single component from a component manager. Use this if you expect the component to only belong to one entity and you want to access it. Access the component using either parameter notation or array notation. Array notation is conventional for better readablility.
+ # @example
+ # @entity.component[@component_manager] # array notation(the standard)
+ # @entity.component(@component_manager) # method notation
+ # @param manager [ComponentManager] If you pass nil you can then use array notation to access the same value.
+ # @return [Component]
+ def component(manager = nil)
+ if manager.nil?
+ FelFlame::Entities.component_redirect.entity = self
+ FelFlame::Entities.component_redirect
+ else
+ if components[manager].nil?
+ raise "This entity(#{self}) doesnt have any components of this type: #{manager}"
+ elsif components[manager].length > 1
+ Warning.warn("This entity has MANY of this component but you called the method that is intended for having a single of this component type.\nYou may have a bug in your logic.")
+ end
+
+ components[manager].first
+ end
end
- # Removes this Entity from the list and purges all references to this Entity from other Components, as well as its {id ID} and data.
+ # Removes this Entity from the list and purges all references to this Entity from other Components, as well as its data.
# @return [Boolean] +true+
def delete
- components.each do |component_manager, component_array|
- component_array.each do |component|
+ components.each do |_component_manager, component_array|
+ component_array.reverse_each do |component|
component.entities.delete(self)
end
end
- FelFlame::Entities.data[id] = nil
+ FelFlame::Entities._data.delete self
@components = {}
- @id = nil
true
end
@@ -89,6 +89,7 @@ class FelFlame
check_systems component, :removal_triggers if component.entities.include? self
component.entities.delete self
components[component.class].delete component
+ components.delete component.class if components[component.class].empty?
end
true
end
@@ -96,39 +97,64 @@ class FelFlame
# Export all data into a JSON String which can then be saved into a file
# TODO: This function is not yet complete
# @return [String] A JSON formatted String
- #def to_json() end
+ # def to_json() end
- class <<self
- include Enumerable
- # @return [Array<Entity>] Array of all Entities that exist
+ class << self
+ # Makes component managers behave like arrays with additional
+ # methods for managing the array
# @!visibility private
- def data
- @data ||= []
+ def respond_to_missing?(method, *)
+ if _data.respond_to? method
+ true
+ else
+ super
+ end
+ end
+
+ # Makes component managers behave like arrays with additional
+ # methods for managing the array
+ # @!visibility private
+ def method_missing(method, *args, **kwargs, &block)
+ if _data.respond_to? method
+ _data.send(method, *args, **kwargs, &block)
+ else
+ super
+ end
end
- # Gets an Entity from the given {id unique ID}. Usage is simular to how an Array lookup works
- #
- # @example
- # # This gets the Entity with ID 7
- # FelFlame::Entities[7]
- # @param entity_id [Integer]
- # @return [Entity] returns the Entity that uses the given unique ID, nil if there is no Entity associated with the given ID
- def [](entity_id)
- data[entity_id]
+ # Fancy method redirection for when the `component` method is called
+ # in an Entity
+ # WARNING: This method will not correctly work with multithreading
+ # @!visibility private
+ def component_redirect
+ if @component_redirect
+ else
+ @component_redirect = Object.new
+ @component_redirect.instance_variable_set(:@entity, nil)
+ @component_redirect.define_singleton_method(:entity) do
+ instance_variable_get(:@entity)
+ end
+ @component_redirect.define_singleton_method(:entity=) do |value|
+ instance_variable_set(:@entity, value)
+ end
+ @component_redirect.define_singleton_method(:[]) do |component_manager|
+ entity.component(component_manager)
+ end
+ end
+ @component_redirect
end
- # Iterates over all entities. The data is compacted so that means index does not correlate to ID.
- # You also call other enumerable methods instead of each, such as +each_with_index+ or +select+
- # @return [Enumerator]
- def each(&block)
- data.compact.each(&block)
+ # @return [Array<Entity>] Array of all Entities that exist
+ # @!visibility private
+ def _data
+ @data ||= []
end
# Creates a new entity using the data from a JSON string
# TODO: This function is not yet complete
# @param json_string [String] A string that was exported originally using the {FelFlame::Entities#to_json to_json} function
# @param opts [Keywords] What values(its {FelFlame::Entities#id ID} or the {FelFlame::ComponentManager#id component IDs}) should be overwritten TODO: this might change
- #def from_json(json_string, **opts) end
+ # def from_json(json_string, **opts) end
end
end
end
diff --git a/lib/felflame/order.rb b/lib/felflame/order.rb
new file mode 100644
index 0000000..c11438d
--- /dev/null
+++ b/lib/felflame/order.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+module FelFlame
+ module Order
+ # Sets the priority of all items passed into this method
+ # according to the order they were passed.
+ # If an array is one of the elements then it will give all
+ # of those elements in the array the same priority.
+ # @param sortables [(Systems and Array<Systems>) or (Scenes and Array<Scenes>)]
+ # @return [Boolean] +true+.
+ def self.sort(*sortables)
+ sortables.each_with_index do |sorted, index|
+ if sorted.respond_to? :priority
+ sorted.priority = index
+ else
+ sorted.each do |item|
+ item.priority = index
+ end
+ end
+ end
+ true
+ end
+ end
+end
diff --git a/lib/felflame/scene_manager.rb b/lib/felflame/scene_manager.rb
index 315dd55..0024815 100644
--- a/lib/felflame/scene_manager.rb
+++ b/lib/felflame/scene_manager.rb
@@ -1,19 +1,27 @@
-class FelFlame
- class Scenes
- # The Constant name assigned to this Scene
- attr_reader :const_name
+# frozen_string_literal: true
+module FelFlame
+ class Scenes
# Allows overwriting the storage of systems, such as for clearing.
# This method should generally only need to be used internally and
# not by a game developer/
# @!visibility private
attr_writer :systems
+ # How early this Scene should be executed in a list of Scenes
+ attr_accessor :priority
+
+ def priority=(priority)
+ @priority = priority
+ FelFlame::Stage.scenes = FelFlame::Stage.scenes.sort_by(&:priority)
+ priority
+ end
+
# Create a new Scene using the name given
# @param name [String] String format must follow requirements of a constant
- def initialize(name)
+ def initialize(name, priority: 0)
+ self.priority = priority
FelFlame::Scenes.const_set(name, self)
- @const_name = name
end
# The list of Systems this Scene contains
@@ -33,25 +41,28 @@ class FelFlame
# @return [Boolean] +true+
def add(*systems_to_add)
self.systems |= systems_to_add
- systems.sort_by!(&:priority)
- FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
+ self.systems = systems.sort_by(&:priority)
+ systems_to_add.each do |system|
+ system.scenes |= [self]
+ end
true
end
- # Removes any number of SystemS from this Scene
+ # Removes any number of Systems from this Scene
# @return [Boolean] +true+
def remove(*systems_to_remove)
self.systems -= systems_to_remove
- systems.sort_by!(&:priority)
- FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
true
end
# Removes all Systems from this Scene
# @return [Boolean] +true+
def clear
+ systems.each do |system|
+ system.scenes.delete self
+ end
systems.clear
- FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
+ # FelFlame::Stage.update_systems_list if FelFlame::Stage.scenes.include? self
true
end
end
diff --git a/lib/felflame/stage_manager.rb b/lib/felflame/stage_manager.rb
index 87ee955..a192b67 100644
--- a/lib/felflame/stage_manager.rb
+++ b/lib/felflame/stage_manager.rb
@@ -1,19 +1,18 @@
-class FelFlame
- class Stage
- class <<self
+# frozen_string_literal: true
+
+module FelFlame
+ module Stage
+ class << self
# Allows clearing of scenes and systems.
# Used internally by FelFlame and shouldn't need to be ever used by developers
# @!visibility private
- attr_writer :scenes, :systems
+ attr_writer :scenes
# Add any number of Scenes to the Stage
# @return [Boolean] +true+
def add(*scenes_to_add)
self.scenes |= scenes_to_add
- scenes_to_add.each do |scene|
- self.systems |= scene.systems
- end
- systems.sort_by!(&:priority)
+ self.scenes = scenes.sort_by(&:priority)
true
end
@@ -21,35 +20,20 @@ class FelFlame
# @return [Boolean] +true+
def remove(*scenes_to_remove)
self.scenes -= scenes_to_remove
- update_systems_list
- true
- end
-
- # Updates the list of systems from the Scenes added to the Stage and make sure they are ordered correctly
- # This is used internally by FelFlame and shouldn't need to be ever used by developers
- # @return [Boolean] +true+
- # @!visibility private
- def update_systems_list
- systems.clear
- scenes.each do |scene|
- self.systems |= scene.systems
- end
- systems.sort_by!(&:priority)
true
end
# Clears all Scenes that were added to the Stage
# @return [Boolean] +true+
def clear
- systems.clear
- scenes.clear
+ self.scenes.clear
true
end
- # Executes one frame of the game. This executes all the Systems in the Scenes added to the Stage. Systems that exist in two or more different Scenes will still only get executed once.
+ # Executes one frame of the game. This executes all the Scenes added to the Stage in order of their priority.
# @return [Boolean] +true+
def call
- systems.each(&:call)
+ self.scenes.each(&:call)
true
end
@@ -58,13 +42,6 @@ class FelFlame
def scenes
@scenes ||= []
end
-
- # Stores systems in the order the stage manager needs to call them
- # This method should generally only need to be used internally and not by a game developer
- # @!visibility private
- def systems
- @systems ||= []
- end
end
end
end
diff --git a/lib/felflame/system_manager.rb b/lib/felflame/system_manager.rb
index cab2c4d..8982589 100644
--- a/lib/felflame/system_manager.rb
+++ b/lib/felflame/system_manager.rb
@@ -1,10 +1,11 @@
-class FelFlame
+# frozen_string_literal: true
+
+module FelFlame
class Systems
# How early this System should be executed in a list of Systems
attr_accessor :priority
# The Constant name assigned to this System
- attr_reader :const_name
# Allows overwriting the storage of triggers, such as for clearing.
# This method should generally only need to be used internally and
@@ -12,10 +13,20 @@ class FelFlame
# @!visibility private
attr_writer :addition_triggers, :removal_triggers, :attr_triggers
+ # Stores all the scenes this system is a part of.
+ attr_writer :scenes
+
+ def scenes
+ @scenes ||= []
+ end
+
def priority=(priority)
@priority = priority
- FelFlame::Stage.systems.sort_by!(&:priority)
+ scenes.each do |scene|
+ scene.systems = scene.systems.sort_by(&:priority)
+ end
end
+
# Stores references to components or their managers that trigger
# this component when a component or component from that manager
# is added to an entity.
@@ -34,7 +45,6 @@ class FelFlame
@removal_triggers ||= []
end
-
# Stores references to systems that should be triggered when an
# attribute from this manager is changed
# Do not edit this hash as it is managed by FelFlame automatically.
@@ -43,13 +53,47 @@ class FelFlame
@attr_triggers ||= {}
end
- class <<self
- include Enumerable
+ class << self
+ # Stores the systems in {FelFlame::Components}. This
+ # is needed because calling `FelFlame::Components.constants`
+ # will not let you iterate over the value of the constants
+ # but will instead give you an array of symbols. This caches
+ # the convertion of those symbols to the actual value of the
+ # constants
+ def const_cache
+ @const_cache || update_const_cache
+ end
- # Iterate over all Systems, sorted by their priority. You also call other enumerable methods instead of each, such as +each_with_index+ or +select+
- # @return [Enumerator]
- def each(&block)
- constants.map { |sym| const_get(sym) }.sort_by(&:priority).reverse.each(&block)
+ # Updates the array that stores the constants.
+ # Used internally by FelFlame
+ # @!visibility private
+ def update_const_cache
+ @const_cache = constants.map do |constant|
+ const_get constant
+ end
+ end
+
+ # Forwards undefined methods to the array of constants
+ # if the array can handle the request. Otherwise tells
+ # the programmer their code errored
+ # @!visibility private
+ def respond_to_missing?(method, *)
+ if const_cache.respond_to? method
+ true
+ else
+ super
+ end
+ end
+
+ # Makes system module behave like arrays with additional
+ # methods for managing the array
+ # @!visibility private
+ def method_missing(method, *args, **kwargs, &block)
+ if const_cache.respond_to? method
+ const_cache.send(method, *args, **kwargs, &block)
+ else
+ super
+ end
end
end
@@ -70,15 +114,17 @@ class FelFlame
# @param block [Proc] The code you wish to be executed when the system is triggered. Can be defined by using a +do end+ block or using +{ }+ braces.
def initialize(name, priority: 0, &block)
FelFlame::Systems.const_set(name, self)
- @const_name = name
+ FelFlame::Systems.update_const_cache
@priority = priority
@block = block
+ @scenes = []
end
# Manually execute the system a single time
def call
@block.call
end
+
# Redefine what code is executed by this System when it is called upon.
# @param block [Proc] The code you wish to be executed when the system is triggered. Can be defined by using a +do end+ block or using +{ }+ braces.
def redefine(&block)
@@ -109,16 +155,16 @@ class FelFlame
# @param component_or_manager [Component or ComponentManager] The object to clear triggers from. Use Nil to clear triggers from all components associated with this system.
# @return [Boolean] +true+
def clear_triggers(*trigger_types, component_or_manager: nil)
- trigger_types = [:addition_triggers, :removal_triggers, :attr_triggers] if trigger_types.empty?
+ trigger_types = %i[addition_triggers removal_triggers attr_triggers] if trigger_types.empty?
if trigger_types.include? :attr_triggers
- if (trigger_types - [:addition_triggers,
- :removal_triggers,
- :attr_triggers]).empty?
+ if (trigger_types - %i[addition_triggers
+ removal_triggers
+ attr_triggers]).empty?
if component_or_manager.nil?
- #remove all attrs
- self.attr_triggers.each do |cmp_or_mgr, attrs|
+ # remove all attrs
+ attr_triggers.each do |cmp_or_mgr, attrs|
attrs.each do |attr|
next if cmp_or_mgr.attr_triggers[attr].nil?
@@ -127,49 +173,48 @@ class FelFlame
self.attr_triggers = {}
end
else
- #remove attrs relevant to comp_or_man
- unless self.attr_triggers[component_or_manager].nil?
- self.attr_triggers[component_or_manager].each do |attr|
+ # remove attrs relevant to comp_or_man
+ unless attr_triggers[component_or_manager].nil?
+ attr_triggers[component_or_manager].each do |attr|
component_or_manager.attr_triggers[attr].delete self
end
- self.attr_triggers[component_or_manager] = []
+ attr_triggers[component_or_manager] = []
end
end
- else
+ elsif component_or_manager.nil?
- if component_or_manager.nil?
- (trigger_types - [:addition_triggers, :removal_triggers, :attr_triggers]).each do |attr|
- #remove attr
- self.attr_triggers.each do |cmp_or_mgr, attrs|
- cmp_or_mgr.attr_triggers[attr].delete self
- end
- end
- self.attr_triggers.delete (trigger_types - [:addition_triggers,
- :removal_triggers,
- :attr_triggers])
- else
- #remove attr from component_or_manager
- (trigger_types - [:addition_triggers, :removal_triggers, :attr_triggers]).each do |attr|
- next if component_or_manager.attr_triggers[attr].nil?
- component_or_manager.attr_triggers[attr].delete self
+ (trigger_types - %i[addition_triggers removal_triggers attr_triggers]).each do |attr|
+ # remove attr
+ attr_triggers.each do |cmp_or_mgr, _attrs|
+ cmp_or_mgr.attr_triggers[attr].delete self
end
- self.attr_triggers[component_or_manager] -= trigger_types unless self.attr_triggers[component_or_manager].nil?
end
+ attr_triggers.delete(trigger_types - %i[addition_triggers
+ removal_triggers
+ attr_triggers])
+ else
+ # remove attr from component_or_manager
+ (trigger_types - %i[addition_triggers removal_triggers attr_triggers]).each do |attr|
+ next if component_or_manager.attr_triggers[attr].nil?
+
+ component_or_manager.attr_triggers[attr].delete self
+ end
+ attr_triggers[component_or_manager] -= trigger_types unless attr_triggers[component_or_manager].nil?
end
end
- (trigger_types & [:removal_triggers, :addition_triggers] - [:attr_triggers]).each do |trigger_type|
+ (trigger_types & %i[removal_triggers addition_triggers] - [:attr_triggers]).each do |trigger_type|
if component_or_manager.nil?
- #remove all removal triggers
- self.send(trigger_type).each do |trigger|
+ # remove all removal triggers
+ send(trigger_type).each do |trigger|
trigger.send(trigger_type).delete self
end
- self.send("#{trigger_type.to_s}=", [])
+ send("#{trigger_type}=", [])
else
- #remove removal trigger relevant to comp/man
- self.send(trigger_type).delete component_or_manager
+ # remove removal trigger relevant to comp/man
+ send(trigger_type).delete component_or_manager
component_or_manager.send(trigger_type).delete self
end
end
@@ -202,10 +247,10 @@ class FelFlame
else
component_or_manager.attr_triggers[attr] |= [self]
end
- if self.attr_triggers[component_or_manager].nil?
- self.attr_triggers[component_or_manager] = [attr]
+ if attr_triggers[component_or_manager].nil?
+ attr_triggers[component_or_manager] = [attr]
else
- self.attr_triggers[component_or_manager] |= [attr]
+ attr_triggers[component_or_manager] |= [attr]
end
true
end
diff --git a/lib/felflame/version.rb b/lib/felflame/version.rb
index 882774f..9f7f09e 100644
--- a/lib/felflame/version.rb
+++ b/lib/felflame/version.rb
@@ -4,6 +4,6 @@
# Keeps the version of the Gem
module Felflame
# The version of the Gem
- VERSION = "3.0.0"
+ VERSION = '4.0.0'
end
# :nocov: