Class: ROM::CSV::Repository

Inherits:
Repository
  • Object
show all
Defined in:
lib/rom/csv/repository.rb

Overview

CSV repository interface

API:

  • public

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Repository

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Expect a path to a single csv file which will be registered by rom to the given name or :default as the repository.

Uses CSV.table which passes the following csv options:

  • headers: true

  • converters: numeric

  • header_converters: :symbol

Parameters:

  • path to csv

See Also:

  • CSV.table

API:

  • private



55
56
57
58
# File 'lib/rom/csv/repository.rb', line 55

def initialize(path)
  @datasets = {}
  @connection = ::CSV.table(path).by_row!
end

Instance Method Details

#[](name) ⇒ Dataset

Return dataset with the given name

Parameters:

  • dataset name

Returns:

API:

  • public



66
67
68
# File 'lib/rom/csv/repository.rb', line 66

def [](name)
  datasets[name]
end

#dataset(name) ⇒ Dataset

Register a dataset in the repository

If dataset already exists it will be returned

Parameters:

  • dataset name

Returns:

API:

  • public



78
79
80
# File 'lib/rom/csv/repository.rb', line 78

def dataset(name)
  datasets[name] = Dataset.new(connection)
end

#dataset?(name) ⇒ Boolean

Check if dataset exists

Parameters:

  • dataset name

Returns:

API:

  • public



87
88
89
# File 'lib/rom/csv/repository.rb', line 87

def dataset?(name)
  datasets.key?(name)
end