Parent

Namespace

Included Modules

WpItems

Attributes

wp_target[RW]

Public Class Methods

new(wp_target = nil) click to toggle source

@param [ WpTarget ] wp_target

# File lib/common/collections/wp_items.rb, line 12
def initialize(wp_target = nil)
  self.wp_target = wp_target
end

Public Instance Methods

+(other) click to toggle source

@param [ WpItems ] other

@return [ self ]

# File lib/common/collections/wp_items.rb, line 63
def +(other)
  other.each { |item| self << item }
  self
end
add(*args) click to toggle source

@param [String,] argv

@return [ void ]

# File lib/common/collections/wp_items.rb, line 19
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 = {}) click to toggle source

@param [ String ] name @param [ Hash ] attrs

@return [ WpItem ]

# File lib/common/collections/wp_items.rb, line 47
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

Protected Instance Methods

item_class() click to toggle source

@return [ Class ]

# File lib/common/collections/wp_items.rb, line 70
def item_class
  Object.const_get(self.class.to_s.gsub(/.$/, ''))
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.