queryable_pstore 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/csv_importer.rb +4 -2
- data/lib/queryable_pstore.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed900a27718914479aaea9502f5d7dcb01aa4aa6
|
4
|
+
data.tar.gz: c2b26e0ef5b614f96b9534fe00e3026b3b3bf87a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b614f00f32213a2a8d2ff2c89706c4b0b624538321713680e4c3c6440e8d1ac1be30b04dc73b02dbb98b32bcd0b03580601906f3921a2cefdc9bb39151dd5372
|
7
|
+
data.tar.gz: 20a6a804585c402dd6b8c46568ed68ca6a73aa07bc6c839490f8a4d7690371079464713b44210c2102ac4b5812908bb7c52df7780e1782ae2cf333e39054bd1b
|
data/lib/csv_importer.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require 'pry'
|
2
1
|
class CSVImporter
|
2
|
+
CURRENT_DIRECTORY = "./".freeze
|
3
|
+
|
3
4
|
attr_reader :original_headers, :headers_and_type
|
4
5
|
|
5
6
|
def import_csv(filename, opts = {})
|
@@ -22,8 +23,9 @@ class CSVImporter
|
|
22
23
|
|
23
24
|
def create_pstore(csv, opts = {}, filename = SecureRandom.uuid)
|
24
25
|
csv_converters = opts.fetch(:convert, []).map { |conversion| CSVConverter.new(conversion) }
|
26
|
+
file_save_location = opts[:save_to_location] || CURRENT_DIRECTORY
|
25
27
|
|
26
|
-
store = QueryablePStore.new("#{filename}.pstore")
|
28
|
+
store = QueryablePStore.new("#{file_save_location}#{filename}.pstore")
|
27
29
|
store.transaction do
|
28
30
|
csv.each do |row|
|
29
31
|
store[SecureRandom.uuid] = csv_converters.inject(row.to_h) { |hash, converter| converter.convert(hash) }
|
data/lib/queryable_pstore.rb
CHANGED
@@ -2,6 +2,7 @@ require 'pstore'
|
|
2
2
|
require 'ostruct'
|
3
3
|
require 'securerandom'
|
4
4
|
require 'csv'
|
5
|
+
require 'fileutils'
|
5
6
|
|
6
7
|
require_relative 'query'
|
7
8
|
require_relative 'csv_converter'
|
@@ -28,6 +29,7 @@ class QueryablePStore < PStore
|
|
28
29
|
def_delegator :@csv_importer, :headers_and_type
|
29
30
|
|
30
31
|
def initialize(store_name)
|
32
|
+
FileUtils.mkdir_p(File.dirname(store_name)) # create the directory if it doesn't exist where we are saving the file
|
31
33
|
super(store_name)
|
32
34
|
@queries = []
|
33
35
|
end
|