class SeedGimmick::SeedIO::Base

Constants

BASE_DATA_KEYS

Public Class Methods

new(seed_file) click to toggle source

@param seed_file [Pathname]

# File lib/seed_gimmick/seed_io/base.rb, line 17
def initialize(seed_file)
  @seed_file = seed_file
end

Public Instance Methods

[](key) click to toggle source

Data access with bracket.

# File lib/seed_gimmick/seed_io/base.rb, line 35
def [](key)
  raise ArgumentError unless BASE_DATA_KEYS.include?(key)
  public_send(key.to_sym)
end
dump_data(array_of_hashes) click to toggle source

Data dump to seed file. @param array_of_hashes [Array<Hash>] @return [Integer] number of dump data.

# File lib/seed_gimmick/seed_io/base.rb, line 30
def dump_data(array_of_hashes)
  raise NotImplementedError
end
load_data() click to toggle source

Data load from seed file. @note Need to return self or load data with Hash.

# File lib/seed_gimmick/seed_io/base.rb, line 23
def load_data
  raise NotImplementedError
end

Private Instance Methods

set_data(array_of_hashes) click to toggle source

Update accessible data from Array of Hashes. @param array_of_hashes [Array<Hash>] loaded data.

# File lib/seed_gimmick/seed_io/base.rb, line 43
def set_data(array_of_hashes)
  @values = array_of_hashes
  @metadata = {
    rows: @values.size,
  }
end
write_raw(data) click to toggle source
# File lib/seed_gimmick/seed_io/base.rb, line 50
def write_raw(data)
  seed_file.dirname.mkpath
  seed_file.open("w") {|f| f.write data }
end