Skip to content

Instantly share code, notes, and snippets.

@elskwid
Created December 19, 2014 18:46
Show Gist options
  • Save elskwid/a173a551afb086c0dafa to your computer and use it in GitHub Desktop.
Save elskwid/a173a551afb086c0dafa to your computer and use it in GitHub Desktop.
WIP ROM csv adapter
module ROM
module CSV
class Adapter < ROM::Adapter
def self.schemes
[:csv]
end
attr_reader :path, :basename
# CSVs are basically one relation per connection. Is there a way
# we could do multiples? Perhaps multiple repositories?
#
# What about CSV options, like header converters, sep, etc?
def initialize(uri)
super
@path = uri.path
# capture the basename to use when finding "relations"
@basename = File.basename(path, File.extname(path))
# Uses ::table which uses the following options:
# headers: true
# converters: numeric
# header_converters: :symbol
@connection = ::CSV.table(path)
end
def dataset?(name)
basename == name.to_s
end
def [](name)
connection if dataset?(name)
end
ROM::Adapter.register(self)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment