class RSpec::Core::Metadata::HashPopulator

managed by RSpec.
Used internally to populate metadata hashes with computed keys
@private

def build_description_from(parent_description=nil, my_description=nil)

def build_description_from(parent_description=nil, my_description=nil)
  return parent_description.to_s unless my_description
  separator = description_separator(parent_description, my_description)
  parent_description.to_s + separator + my_description.to_s
end

def description_separator(parent_part, child_part)

def description_separator(parent_part, child_part)
  if parent_part.is_a?(Module) && child_part =~ /^(#|::|\.)/
    ''
  else
    ' '
  end
end

def ensure_valid_user_keys

def ensure_valid_user_keys
  RESERVED_KEYS.each do |key|
    if user_metadata.has_key?(key)
      raise <<-EOM.gsub(/^\s+\|/, '')
        |#{"*"*50}
        |:#{key} is not allowed
        |
        |RSpec reserves some hash keys for its own internal use,
        |including :#{key}, which is used on:
        |
        |  #{CallerFilter.first_non_rspec_line}.
        |
        |Here are all of RSpec's reserved hash keys:
        |
        |  #{RESERVED_KEYS.join("\n  ")}
        |#{"*"*50}
      EOM
    end
  end
end

def file_path_and_line_number_from(backtrace)

def file_path_and_line_number_from(backtrace)
  first_caller_from_outside_rspec = backtrace.detect { |l| l !~ CallerFilter::LIB_REGEX }
  first_caller_from_outside_rspec ||= backtrace.first
  /(.+?):(\d+)(?:|:\d+)/.match(first_caller_from_outside_rspec).captures
end

def initialize(metadata, user_metadata, description_args, block)

def initialize(metadata, user_metadata, description_args, block)
  @metadata         = metadata
  @user_metadata    = user_metadata
  @description_args = description_args
  @block            = block
end

def populate

def populate
  ensure_valid_user_keys
  metadata[:execution_result] = Example::ExecutionResult.new
  metadata[:block]            = block
  metadata[:description_args] = description_args
  metadata[:description]      = build_description_from(*metadata[:description_args])
  metadata[:full_description] = full_description
  metadata[:described_class]  = described_class
  populate_location_attributes
  metadata.update(user_metadata)
  RSpec.configuration.apply_derived_metadata_to(metadata)
end

def populate_location_attributes

def populate_location_attributes
  file_path, line_number = if backtrace = user_metadata.delete(:caller)
    file_path_and_line_number_from(backtrace)
  elsif block.respond_to?(:source_location)
    block.source_location
  else
    file_path_and_line_number_from(caller)
  end
  file_path              = Metadata.relative_path(file_path)
  metadata[:file_path]   = file_path
  metadata[:line_number] = line_number.to_i
  metadata[:location]    = "#{file_path}:#{line_number}"
end