Module: Metasploit::Model::Translation::ClassMethods

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

Overview

Adds #lookup_ancestors and #i18n_scope so that Metasploit::Model modules can participate in translation lookups.

Instance Method Summary collapse

Instance Method Details

#i18n_scopeString

Classes that include a metasploit-model are trying to share code between ActiveRecord and ActiveModel, so the scope should be neither 'activerecord' nor 'activemodel'.

Returns:

  • (String)

    'metasploit.model'


27
28
29
# File 'lib/metasploit/model/translation.rb', line 27

def i18n_scope
  'metasploit.model'
end

#lookup_ancestorsArray<Module>

When localizing a string, it goes through the lookup returned by this method, which is used in ActiveModel::Name#human, # ActiveModel::Errors#full_messages and ActiveModel::Translation#human_attribute_name.

Returns:

  • (Array<Module>)

    Array of Class#ancestors that respond to module_name.


17
18
19
20
21
# File 'lib/metasploit/model/translation.rb', line 17

def lookup_ancestors
  self.ancestors.select { |ancestor|
    ancestor.respond_to?(:model_name)
  }
end