module Metasploit::Model::Association::ClassMethods
Defines DSL for define associations on ActiveModels with {#association}, which can then be retrieved in bulk with {#association_by_name} or a single association's reflection by name with {#reflect_on_association}.
Public Instance Methods
Registers an association.
@param name [to_sym] Name of the association @param options [Hash{Symbol => String}] @option options [String] :class_name Name of association's class. @return [Metasploit::Model::Association::Reflection] the reflection of the registered association. @raise [Metasploit::Model::Invalid] if name is blank. @raise [Metasploit::Model::Invalid] if :class_name is blank.
# File lib/metasploit/model/association.rb, line 22 def association(name, options={}) association = Metasploit::Model::Association::Reflection.new( :model => self, :name => name.to_sym, :class_name => options[:class_name] ) association.valid! association_by_name[association.name] = association end
Associations registered with {#association}.
@return [Hash{Symbol => Metasploit::Model::Association::Reflection}] Maps
{Metasploit::Model::Association::Reflection#name} to {Metasploit::Model::Association::Reflection}.
# File lib/metasploit/model/association.rb, line 37 def association_by_name @association_by_name ||= {} end
Returns reflection for association with the given name.
@param name [#to_sym] name of the association whose reflection to retrieve. @return [nil] if no association with the given `name`. @return [Metasploit::Model::Association::Reflection] if association with the given `name`.
# File lib/metasploit/model/association.rb, line 46 def reflect_on_association(name) association_by_name[name.to_sym] end