class PIM::DirectPublication

Public Class Methods

create(enabled = true, from: nil, to: nil, filter_value: nil, map_value: nil, match: nil, revalidate: nil, revalidate_attributes: nil) click to toggle source
# File pim.rb, line 10192
    def self.create enabled = true,
                    from: nil,
                    to: nil,
#                    filter_key: nil,
#                    filter_keys: nil,
                    filter_value: nil,
#                    map_key: nil,
#                    map_keys: nil,
                    map_value: nil,
                    match: nil,
                    revalidate: nil,
                    revalidate_attributes: nil

      from = DirectPublicationFilter.create(from) unless from.nil?
      to = DirectPublicationFilter.create(to) unless to.nil?

#      raise "'filter_keys' must be nil or a Hash" unless (filter_keys.nil? or PIM.is_hash?(filter_keys))
#      raise "'map_keys' must be nil or a Hash" unless (map_keys.nil? or PIM.is_hash?(map_keys))

#      filter_key = DirectPublicationFilter.create(filter_key) unless filter_key.nil?
#      filter_keys = filter_keys.map { |k,v| [k, DirectPublicationFilter.create(v)] }.to_h unless filter_keys.nil?
      filter_value = DirectPublicationFilter.create(filter_value) unless filter_value.nil?

#      map_key = map_key.to_s unless map_key.nil?
#      map_keys = map_key.to_s unless map_keys.nil?
      map_value = map_value.to_s unless map_value.nil?

      match = DirectPublicationFilter.create(match) unless match.nil?

      raise "'revalidate' must be nil or true or false" \
        unless revalidate.nil? or [true, false].include?(revalidate)

      raise "'revalidate_attributes' must be nil or an Array" \
        unless revalidate_attributes.nil? or PIM.is_array?(revalidate_attributes)

      revalidate = !(filter_value.nil? and map_value.nil?) if revalidate.nil?

      self.new(enabled: enabled,
               from: from,
               to: to,
#               filter_key: filter_key,
#               filter_keys: filter_keys,
               filter_value: filter_value,
#               map_key: map_key,
#               map_keys: map_keys,
               map_value: map_value,
               match: match,
               revalidate: revalidate,
               revalidate_attributes: revalidate_attributes)

    end

Public Instance Methods

as_json() click to toggle source
# File pim.rb, line 10244
def as_json
  PIM::Utils.camelize(self.to_h.filter { |k,v| !v.nil? })
end
to_json(*args) click to toggle source
# File pim.rb, line 10248
def to_json *args
  as_json.to_json(*args)
end
verify(attribute) click to toggle source
# File pim.rb, line 10252
def verify attribute

  # Ensure, filter_key and map_key is set correctly according to attribute
  return if filter_key.nil? and filter_keys.nil? and map_key.nil? and map_keys.nil?

  raise "Attribute must be provided to verify 'filter_key', 'filter_keys', 'map_key' or 'map_keys'" if attribute.nil?

  raise "'filter_key' and 'map_key' is only allowed on attribute of type 'Dimensional'" +
        ", but not on attribute '#{attribute.name}' of type  '#{attribute.type_name}'" \
        unless (filter_key.nil? and map_key.nil?) or attribute.type_name == 'Dimensional'

  raise "'filter_keys' and 'map_keys' is only allowed on attribute of type 'MultiDimensional'" +
        ", but not on attribute '#{attribute.name}' of type  '#{attribute.type_name}'" \
        unless (filter_keys.nil? and map_keys.nil?) or attribute.type_name == 'MultiDimensional'

  unless filter_keys.nil?

    raise "'filter_keys' on MultiDimensional attribute '#{attribute.name}' must be a non empty Hash" unless filter_keys.is_a?(Hash)
    key_members = attribute.base_class.key_members
    non_matching_keys = filter_keys.keys.select { |k| !key_members.include?(k) }
    raise "'filter_keys' on MultiDimensional attribute '#{attribute.name}' must be a Hash including any key member (#{key_members.join(', ')})" +
          ", but not #{non_matching_keys.join(', ')}" unless non_matching_keys.empty?

  end

  unless map_keys.nil?

    raise "'map_keys' on MultiDimensional attribute '#{attribute.name}' must be a non empty Hash" unless map_keys.is_a?(Hash)
    key_members = attribute.base_class.key_members
    non_matching_keys = map_keys.keys.select { |k| !key_members.include?(k) }
    raise "'map_keys' on MultiDimensional attribute '#{attribute.name}' must be a Hash including any key member (#{key_members.join(', ')})" +
          ", but not #{non_matching_keys.join(', ')}" unless non_matching_keys.empty?

  end

end