Class: QueryablePStore
- Inherits:
-
PStore
- Object
- PStore
- QueryablePStore
show all
- Extended by:
- Forwardable
- Defined in:
- lib/queryable_pstore.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of QueryablePStore.
31
32
33
34
35
|
# File 'lib/queryable_pstore.rb', line 31
def initialize(store_name)
FileUtils.mkdir_p(File.dirname(store_name))
super(store_name)
@queries = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, argument = nil, &blk) ⇒ Object
43
44
45
46
47
48
49
50
|
# 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
|
Instance Attribute Details
#csv_importer ⇒ Object
Returns the value of attribute csv_importer.
27
28
29
|
# File 'lib/queryable_pstore.rb', line 27
def csv_importer
@csv_importer
end
|
Class Method Details
.import_csv(filename, opts = {}) ⇒ Object
13
14
15
|
# 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 = {}) ⇒ Object
17
18
19
|
# File 'lib/queryable_pstore.rb', line 17
def import_csv_from_string(string, opts = {})
CSVImporter.new.import_csv_from_string(string, opts)
end
|
21
22
23
|
# File 'lib/queryable_pstore.rb', line 21
def ()
CSVImporter.new.()
end
|
Instance Method Details
#records ⇒ Object
37
38
39
40
41
|
# File 'lib/queryable_pstore.rb', line 37
def records
transaction do
roots.map { |root| fetch(root) }
end
end
|
#results ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/queryable_pstore.rb', line 52
def results
answer = @queries.inject(records) { |records, queryable| queryable.filter(records) }
@queries = []
answer
rescue StandardError => e
@queries = []
raise e
end
|