Class: YamlDb::Load
- Inherits:
-
SerializationHelper::Load
- Object
- SerializationHelper::Load
- YamlDb::Load
- Defined in:
- lib/yaml_db.rb
Constant Summary
Constants inherited from SerializationHelper::Load
SerializationHelper::Load::CLEAR, SerializationHelper::Load::GREEN
Class Method Summary collapse
Methods inherited from SerializationHelper::Load
load, load_records, load_table, reset_pk_sequence!, truncate_table
Class Method Details
.load_documents(io, truncate = true) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/yaml_db.rb', line 60 def self.load_documents(io, truncate = true) YAML.load_documents(io) do |ydoc| not_exists_tables = [] ydoc.keys.each do |table_name| next if ydoc[table_name].nil? if ActiveRecord::Base.connection.table_exists?(table_name) load_table(table_name, ydoc[table_name], truncate) else not_exists_tables << table_name end end if not_exists_tables.any? red_color = "\e[31m" default_color = "\e[0m" #CLEAR = "\e[0m" #BOLD = "\e[1m" #RED = "\e[31m" #GREEN = "\e[32m" #YELLOW = "\e[33m" #BLUE = "\e[34m" puts "#{red_color}Synch data field because tables: #{not_exists_tables.join(",")} are not exists #{default_color}" end end end |