Created
December 19, 2014 18:46
WIP ROM csv adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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