Class: Perron::DataSource
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Perron::DataSource
show all
- Includes:
- Enumerable, ClassMethods
- Defined in:
- lib/perron/data_source.rb,
lib/perron/data_source/item.rb,
lib/perron/data_source/proxy.rb,
lib/perron/data_source/class_methods.rb,
lib/perron/data_source/helper_context.rb
Defined Under Namespace
Modules: ClassMethods
Classes: Proxy
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(identifier) ⇒ DataSource
Returns a new instance of DataSource.
15
16
17
18
19
20
21
|
# File 'lib/perron/data_source.rb', line 15
def initialize(identifier)
@identifier = identifier
@file_path = self.class.path_for!(identifier)
@records = records
super(records)
end
|
Class Method Details
.all ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/perron/data_source.rb', line 23
def self.all
identifier = name.to_s.split("::").drop(2).map { it.underscore }.join("/")
identifier = name.demodulize.underscore if identifier.empty?
return cached(identifier) if Perron.configuration.cache_data_sources
new(identifier)
end
|
.cached(identifier) ⇒ Object
32
33
34
35
|
# File 'lib/perron/data_source.rb', line 32
def self.cached(identifier)
@_data_sources ||= {}
@_data_sources[identifier] ||= new(identifier)
end
|
Instance Method Details
#[](index) ⇒ Object
47
|
# File 'lib/perron/data_source.rb', line 47
def [](index) = @records[index]
|
#count ⇒ Object
39
|
# File 'lib/perron/data_source.rb', line 39
def count = @records.count
|
#each(&block) ⇒ Object
37
|
# File 'lib/perron/data_source.rb', line 37
def each(&block) = @records.each(&block)
|
#first(n = nil) ⇒ Object
41
42
43
|
# File 'lib/perron/data_source.rb', line 41
def first(n = nil)
n ? @records.first(n) : @records.first
end
|
#last ⇒ Object
45
|
# File 'lib/perron/data_source.rb', line 45
def last = @records.last
|
#size ⇒ Object
Also known as:
length
49
|
# File 'lib/perron/data_source.rb', line 49
def size = @records.size
|