Class: WpItems

Inherits:
Array show all
Extended by:
Detectable
Includes:
Output
Defined in:
lib/common/collections/wp_items.rb,
lib/common/collections/wp_items/output.rb,
lib/common/collections/wp_items/detectable.rb

Direct Known Subclasses

WpPlugins, WpThemes, WpTimthumbs, WpUsers

Defined Under Namespace

Modules: Detectable, Output

Instance Attribute Summary collapse

Attributes included from Detectable

#item_xpath, #vulns_file

Instance Method Summary collapse

Methods included from Detectable

aggressive_detection, passive_detection, progress_bar

Methods included from Output

#output

Methods inherited from Array

#_grep_

Constructor Details

#initialize(wp_target = nil) ⇒ WpItems


13
14
15
# File 'lib/common/collections/wp_items.rb', line 13

def initialize(wp_target = nil)
  self.wp_target = wp_target
end

Instance Attribute Details

#wp_targetObject

Returns the value of attribute wp_target


10
11
12
# File 'lib/common/collections/wp_items.rb', line 10

def wp_target
  @wp_target
end

Instance Method Details

#+(other) ⇒ self


64
65
66
67
# File 'lib/common/collections/wp_items.rb', line 64

def +(other)
  other.each { |item| self << item }
  self
end

#add(*args) ⇒ void


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/common/collections/wp_items.rb', line 20

def add(*args)
  index = 0

  until args[index].nil?
    arg = args[index]

    if arg.is_a?(String)
      if (next_arg = args[index + 1]).is_a?(Hash)
        item = create_item(arg, next_arg)
        index += 1
      else
        item = create_item(arg)
      end
    elsif arg.is_a?(Item)
      item = arg
    else
      raise 'Invalid arguments'
    end

    self << item
    index += 1
  end
end

#create_item(name, attrs = {}) ⇒ WpItem


48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/common/collections/wp_items.rb', line 48

def create_item(name, attrs = {})
  raise 'wp_target must be set' unless wp_target

  item_class.new(
    wp_target.uri,
    attrs.merge(
      name: name,
      wp_content_dir: wp_target.wp_content_dir,
      wp_plugins_dir: wp_target.wp_plugins_dir
    ) { |key, oldval, newval| oldval }
  )
end