Class: DataDepo::Query
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/data_depo/query.rb
Instance Method Summary
collapse
Constructor Details
#initialize(name = nil, path = []) ⇒ Query
Returns a new instance of Query.
9
10
11
12
|
# File 'lib/data_depo/query.rb', line 9
def initialize(name=nil, path=[])
@name = name
@path = path
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/data_depo/query.rb', line 33
def method_missing(name, *args, &block)
loader = DataDepo.current_loader.new(@path)
unless loader.files.empty?
a = ArrayData.gen(@name, loader.load)
return a.respond_to?(name) ? a.__send__(name, *args, &block) : super
end
super
end
|
Instance Method Details
#[](*keys) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/data_depo/query.rb', line 14
def [](*keys)
raise if keys.empty?
@name ||= keys.first
path = (@path || []) | keys
self.class.new(@name, path)
end
|
#each(&block) ⇒ Object
22
23
24
25
|
# File 'lib/data_depo/query.rb', line 22
def each(&block)
data = DataDepo.current_loader.new(@path).load
data.each(&block)
end
|
#files ⇒ Object
27
28
29
30
|
# File 'lib/data_depo/query.rb', line 27
def files
loader = DataDepo.current_loader.new(@path)
loader.files
end
|