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.



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

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

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

Instance Method Details

#schema_pathObject



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

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

#sequences_pathObject



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

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

#sql_dumpsObject



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

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



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

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

#valid?Boolean

Returns:

  • (Boolean)


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

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