class SeedData::DataBuilder

Attributes

data_set_dir[RW]

Public Instance Methods

build(name) click to toggle source
# File lib/seed_data/data_builder.rb, line 10
def build(name)

  data = load_data_set_file(name)

  data.each do |itm|
    build_item(itm)
  end

  return true

end
build_item(itm) click to toggle source

This method should be overwritten by the specific builder implementation.

# File lib/seed_data/data_builder.rb, line 23
def build_item(itm)
  raise 'Not Implemented.'
end
fill_entity(entity, params) click to toggle source
# File lib/seed_data/data_builder.rb, line 41
def fill_entity(entity, params)

  params.keys.each do |key|

    if entity.respond_to?(key.to_sym)
      entity.send("#{key}=", params[key])
    else
      raise SeedData::InvalidDataSetException.new("Invalid Data Set. Unknown entity attribute: #{key}. For entity: #{entity}")
    end

  end

  entity
end
load_data_set_file(name) click to toggle source
# File lib/seed_data/data_builder.rb, line 27
def load_data_set_file(name)

  if @data_set_dir.nil?
    raise SeedData::DataSetDirNotSpecifiedException.new
  end

  begin
    return YAML::load_file(File.join(@data_set_dir, "/data_sets/#{name}.yaml"))
  rescue Errno::ENOENT
    raise SeedData::DataSetNotFoundException.new("DataSet: ''#{name}'', could not be found.")
  end

end