Module: Ronin::Model::TargetsProduct

Included in:
Exploits::Target
Defined in:
lib/ronin/model/targets_product.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
# File 'lib/ronin/model/targets_product.rb', line 29

def self.included(base)
  base.module_eval do
    # The targeted product
    belongs_to :product,
               :nullable => true

    #
    # The product being targeted.
    #
    # @param [Array] arguments
    #   If any arguments are given, a new Product will be created using
    #   the given arguments.
    #
    # @return [Product]
    #   The product of that is being targeted.
    #
    # @example Accessing the targeted product.
    #   target.product
    #   # => nil
    #
    # @example Setting the targeted product.
    #   target.product(:name => 'Apache', :version => '1.3.3.7')
    #   # => #<Ronin::Product type=Ronin::Product id=nil name="Apache"
    #   # version="1.3.3.7" vendor="Apache">
    #
    def product(*arguments)
      unless arguments.empty?
        return self.product = Product.first_or_create(*arguments)
      else
        return relationships[:product].get(self)
      end
    end
  end

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