Module: Metasploit::Model::Association::ClassMethods

Defined in:
lib/metasploit/model/association.rb

Overview

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.

Instance Method Summary collapse

Instance Method Details

#association(name, options = {}) ⇒ Metasploit::Model::Association::Reflection

Registers an association.

Parameters:

  • name (to_sym)

    Name of the association

  • options (Hash{Symbol => String}) (defaults to: {})

Options Hash (options):

  • :class_name (String)

    Name of association's class.

Returns:

Raises:


22
23
24
25
26
27
28
29
30
31
# 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

#association_by_nameHash{Symbol => Metasploit::Model::Association::Reflection}

Associations registered with #association.


37
38
39
# File 'lib/metasploit/model/association.rb', line 37

def association_by_name
  @association_by_name ||= {}
end

#reflect_on_association(name) ⇒ nil, Metasploit::Model::Association::Reflection

Returns reflection for association with the given name.

Parameters:

  • name (#to_sym)

    name of the association whose reflection to retrieve.

Returns:


46
47
48
# File 'lib/metasploit/model/association.rb', line 46

def reflect_on_association(name)
  association_by_name[name.to_sym]
end