Module: MetasploitDataModels::SerializedPrefs

Included in:
Mdm::Macro, Mdm::User
Defined in:
lib/metasploit_data_models/serialized_prefs.rb

Overview

Allows attributes to be extracted and written to key of serialized Hash prefs.

Instance Method Summary collapse

Instance Method Details

#serialized_prefs_attr_accessor(*args) ⇒ void

This method returns an undefined value.

Setup each arg in args as the name of an attribute embedded in the prefs Hash. Defines #<arg> and #<arg>=(value) methods like standard attr_accessor.

Parameters:

  • args (Array<Symbol>)

    The names of the attributes to store in the prefs Hash.


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/metasploit_data_models/serialized_prefs.rb', line 8

def serialized_prefs_attr_accessor(*args)
  args.each do |method_name|

    method_declarations = <<-RUBY
        def #{method_name}
          return if not self.prefs
          self.prefs[:#{method_name}]
        end

        def #{method_name}=(value)
          temp = self.prefs || {}
          temp[:#{method_name}] = value
          self.prefs = temp
        end
    RUBY

    class_eval method_declarations, __FILE__, __LINE__
  end
end