class Targetmy::Config::Site

Constants

REQUIRED_KEYS
SUPPORTED_ADV_PRODUCTS
SUPPORTED_KEYS

Attributes

adv_products[R]
type[R]

Public Class Methods

new(config) click to toggle source
# File lib/targetmy/config/site.rb, line 10
def initialize(config)
  parse config
end

Public Instance Methods

parse(config) click to toggle source
# File lib/targetmy/config/site.rb, line 14
def parse(config)
  config_required_items = REQUIRED_KEYS & config.keys
  raise Targetmy::MissingRequiredKeys if config_required_items.length != REQUIRED_KEYS.length

  SUPPORTED_KEYS.each do |key|
    next unless config.has_key?(key)
    
    case key
    when :adv_products
      @adv_products = []
      parse_adv_products config[key]
    else
      instance_variable_set("@#{key}", config[key])
    end
  end
end
parse_adv_products(prods) click to toggle source
# File lib/targetmy/config/site.rb, line 31
def parse_adv_products(prods)
  adv_products = prods.is_a?(Hash) ? [prods] : prods
  adv_products.each do |prod|
    if prod.has_key?(:type) && SUPPORTED_ADV_PRODUCTS.include?(prod[:type].to_sym)
      type = prod[:type].to_s.capitalize
      klass = Object.const_get("Targetmy::Config::Site::#{type}")

      @adv_products << klass.new(prod)
    else
      raise Targetmy::MissingRequiredKey.new(:type)
    end
  end
end