class PIM::PrimaryKey

Attributes

attributes[R]

Public Class Methods

new(*attributes, &block) click to toggle source
# File pim.rb, line 5382
    def initialize *attributes, &block
#      raise "Primary calculation block must have 1 method argument defined" if block and block.arity != 1
      @attributes = attributes
      @block = block
    end

Public Instance Methods

calculate_primary_key(values) click to toggle source
# File pim.rb, line 5388
def calculate_primary_key values
  primary_key = ""
  if @attributes
    @attributes.each do |a|
      value = values[a]
      PIM.log_warn "Value for attribute '#{a}' was empty when calculating primary key" if not value
      primary_key << ':' if not primary_key.empty?
      primary_key << value.to_s
    end
  end
  if @block
    value = @block.call(values)
    if value
      primary_key << ':' if not primary_key.empty?
      primary_key << value.to_s
    end
  end
  PIM.log_warn "Calculated primary key is empty" if (@attributes || @block) and not primary_key
  primary_key
end