Class: DataKeeper::Loader::InflatedFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/data_keeper/loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dump, paths) ⇒ InflatedFiles

Returns a new instance of InflatedFiles.



156
157
158
159
160
# File 'lib/data_keeper/loader.rb', line 156

def initialize(dump, paths)
  @dump = dump
  @paths = paths
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



154
155
156
# File 'lib/data_keeper/loader.rb', line 154

def errors
  @errors
end

Instance Method Details

#schema_pathObject



171
172
173
# File 'lib/data_keeper/loader.rb', line 171

def schema_path
  @schema_path ||= @paths.find { |x| File.basename(x) == "schema.dump" }
end

#sequences_pathObject



179
180
181
# File 'lib/data_keeper/loader.rb', line 179

def sequences_path
  @sequences_path ||= @paths.find { |x| File.basename(x) == "sequences.dump" }
end

#sql_dumpsObject



183
184
185
186
187
188
189
190
# File 'lib/data_keeper/loader.rb', line 183

def sql_dumps
  @sql_dumps ||= @dump.sqls.map do |name, (table, _proc)|
    path = @paths.find { |x| File.basename(x) == "#{name}.csv" }
    next unless path

    [table, path]
  end.compact
end

#tables_pathObject



175
176
177
# File 'lib/data_keeper/loader.rb', line 175

def tables_path
  @tables_path ||= @paths.find { |x| File.basename(x) == "tables.dump" }
end

#valid?Boolean

Returns:

  • (Boolean)


162
163
164
165
166
167
168
169
# File 'lib/data_keeper/loader.rb', line 162

def valid?
  @errors = []

  validate("Schema file is missing") { !!schema_path } &&
    validate("Tables file is missing") { !!tables_path } &&
    validate("Not all sql custom dumps are present") { sql_dumps.size == @dump.sqls.keys.size } &&
    validate("Sequences file is missing") { !!sequences_path }
end