Class: SchemaRD::Metadata::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/schemard/metadata.rb

Overview

Writer for metadata yaml

Instance Method Summary collapse

Constructor Details

#initialize(output_file) ⇒ Writer

Returns a new instance of Writer.



93
94
95
# File 'lib/schemard/metadata.rb', line 93

def initialize(output_file)
  @output_file = output_file
end

Instance Method Details

#save(table_name, position) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# 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) ⇒ Object



96
97
98
99
100
101
# 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