class QueryablePStore
Attributes
csv_importer[RW]
Public Class Methods
import_csv(filename, opts = {})
click to toggle source
# File lib/queryable_pstore.rb, line 13 def import_csv(filename, opts = {}) CSVImporter.new.import_csv(filename, opts) end
import_csv_from_string(string, opts = {})
click to toggle source
# File lib/queryable_pstore.rb, line 17 def import_csv_from_string(string, opts = {}) CSVImporter.new.import_csv_from_string(string, opts) end
new(store_name)
click to toggle source
Calls superclass method
# File lib/queryable_pstore.rb, line 31 def initialize(store_name) FileUtils.mkdir_p(File.dirname(store_name)) # create the directory if it doesn't exist where we are saving the file super(store_name) @queries = [] end
queryable_header(header)
click to toggle source
# File lib/queryable_pstore.rb, line 21 def queryable_header(header) CSVImporter.new.convert_header_to_methodable_name(header) end
Public Instance Methods
method_missing(method, argument = nil, &blk)
click to toggle source
# File lib/queryable_pstore.rb, line 43 def method_missing(method, argument = nil, &blk) attribute = method.to_s.split("_")[0..-2].join("_").to_sym modifier = method.to_s.split("_")[-1].to_sym query = Query.new(attribute, modifier, argument || blk) @queries << query if query.valid?(records) self end
records()
click to toggle source
# File lib/queryable_pstore.rb, line 37 def records transaction do roots.map { |root| fetch(root) } end end
results()
click to toggle source
# File lib/queryable_pstore.rb, line 52 def results answer = @queries.inject(records) { |records, queryable| queryable.filter(records) } @queries = [] answer rescue StandardError => e # In the event something bad happens, get us back to a good state without any queries hanging around @queries = [] raise e end