class SchemaRD::Metadata::Writer

Writer for metadata yaml

Public Class Methods

new(output_file) click to toggle source
# File lib/schemard/metadata.rb, line 93
def initialize(output_file)
  @output_file = output_file
end

Public Instance Methods

save(table_name, position) click to toggle source
# File lib/schemard/metadata.rb, line 102
def save(table_name, position)
  hash = YAML.load_file(@output_file) || {}
  hash["tables"] = {} unless hash.has_key?("tables")
  hash["tables"] = {} unless hash["tables"].is_a?(Hash)
  hash["tables"][table_name] = {} unless hash["tables"][table_name]
  hash["tables"][table_name] = {} unless hash["tables"][table_name].is_a?(Hash)
  hash["tables"][table_name]["position_top"] = position["top"].to_s
  hash["tables"][table_name]["position_left"] = position["left"].to_s
  File.write(@output_file, YAML.dump(hash))
end
save_all(tables) click to toggle source
# File lib/schemard/metadata.rb, line 96
def save_all(tables)
  hash = tables.each_with_object({}) do |t, hash|
    hash[t.name] = { "position_top" => t.position["top"], "position_left" => t.position["left"] }
  end
  File.write(@output_file, YAML.dump({ "tables" => hash }))
end