Module: Ronin::Model::TargetsOS

Included in:
Exploits::Target, Payloads::Encoders::Encoder, Payloads::Payload
Defined in:
lib/ronin/model/targets_os.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ronin/model/targets_os.rb', line 29

def self.included(base)
  base.module_eval do
    # The targeted OS
    belongs_to :os,
               :model => 'Ronin::OS',
               :nullable => true

    #
    # The targeted OS.
    #
    # @param [Array] arguments
    #   If any arguments are given, they will be used to create a new
    #   OS that will be targeted.
    #
    # @return [OS]
    #   The targeted OS.
    #
    # @example Accessing the targeted OS.
    #   target.os
    #   # => nil
    #
    # @example Setting the targeted OS.
    #   target.os(:name => 'FreeBSD', :version => '7.1')
    #   # => #<Ronin::OS type=Ronin::OS id=nil name="FreeBSD"
    #   # version="7.1">
    #
    def os(*arguments)
      unless arguments.empty?
        return self.os = OS.first_or_create(*arguments)
      else
        return relationships[:os].get(self)
      end
    end
  end

  model_name = base.name.split('::').last.snake_case.plural.to_sym
  OS.has OS.n, model_name, :model => base.name
end