Class: LazyList
- Inherits:
-
Object
show all
- Defined in:
- lib/filament/util/lazy_list.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*entries) ⇒ LazyList
Returns a new instance of LazyList.
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/filament/util/lazy_list.rb', line 4
def initialize(*entries)
raise "resolver must be set by subclass." if @resolver.nil?
@unresolved = []
@resolved = []
entries.each do |entry|
include(entry)
end
end
|
Instance Attribute Details
#resolver ⇒ Object
Returns the value of attribute resolver.
2
3
4
|
# File 'lib/filament/util/lazy_list.rb', line 2
def resolver
@resolver
end
|
Instance Method Details
#collect(&block) ⇒ Object
64
65
66
67
|
# File 'lib/filament/util/lazy_list.rb', line 64
def collect(&block)
resolve
@resolved.collect(&block)
end
|
#each(&block) ⇒ Object
58
59
60
61
62
|
# File 'lib/filament/util/lazy_list.rb', line 58
def each(&block)
resolve
@resolved.each(&block)
return nil
end
|
#empty? ⇒ Boolean
36
37
38
|
# File 'lib/filament/util/lazy_list.rb', line 36
def empty?
return length == 0
end
|
#entry_resolved?(entry_name) ⇒ Boolean
40
41
42
|
# File 'lib/filament/util/lazy_list.rb', line 40
def entry_resolved?(entry_name)
return !entry_name.is_a?(String)
end
|
#include(*entry_names) ⇒ Object
Also known as:
<<
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/filament/util/lazy_list.rb', line 15
def include(*entry_names)
entry_names.each do |entry_name|
if entry_name.respond_to?(:to_ary)
self.include(*entry_name.to_ary)
else
if entry_resolved?(entry_name)
@resolved << entry_name
else
@unresolved << entry_name
end
end
end
return self
end
|
#length ⇒ Object
Also known as:
size
31
32
33
|
# File 'lib/filament/util/lazy_list.rb', line 31
def length
return @unresolved.size + @resolved.size
end
|
#resolve ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/filament/util/lazy_list.rb', line 48
def resolve
until @unresolved.empty?
entry_name = @unresolved.pop
entry = resolve_entry(entry_name)
raise "entry '#{entry_name}' could not be resolved" if entry.nil?
@resolved << entry
end
end
|
#resolve_entry(entry_name) ⇒ Object
44
45
46
|
# File 'lib/filament/util/lazy_list.rb', line 44
def resolve_entry(entry_name)
return @resolver.resolve(entry_name)
end
|
#to_a ⇒ Object
Also known as:
to_ary
69
70
71
72
|
# File 'lib/filament/util/lazy_list.rb', line 69
def to_a
resolve
return @resolved.clone
end
|