Class: ROM::CSV::Gateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/rom/csv/gateway.rb

Overview

CSV gateway interface

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Gateway

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 gateway.

Uses CSV.table which passes the following csv options:

  • headers: true

  • converters: numeric

  • header_converters: :symbol

Parameters:

  • path (String)

    path to csv

  • options (Hash) (defaults to: {})

    options passed to CSV.table

See Also:

  • CSV.table


57
58
59
60
61
62
# File 'lib/rom/csv/gateway.rb', line 57

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

Instance Method Details

#[](name) ⇒ Dataset

Return dataset with the given name

Parameters:

  • name (String)

    dataset name

Returns:



70
71
72
# File 'lib/rom/csv/gateway.rb', line 70

def [](name)
  datasets[name]
end

#dataset(name) ⇒ Dataset

Register a dataset in the gateway

If dataset already exists it will be returned

Parameters:

  • name (String)

    dataset name

Returns:



82
83
84
# File 'lib/rom/csv/gateway.rb', line 82

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

#dataset?(name) ⇒ Boolean

Check if dataset exists

Parameters:

  • name (String)

    dataset name

Returns:

  • (Boolean)


91
92
93
# File 'lib/rom/csv/gateway.rb', line 91

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