Class: Array
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing ⇒ Object
Also known as:
method_missing_without_prop_pipe
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/ext/array_ext.rb', line 50
def method_missing_with_prop_pipe(name, *args, &block)
if graph_item_array?
map! do |e|
begin
e.send name, *args, &block
rescue NoMethodError
nil
end
end.compact!
else
method_missing_without_prop_pipe name, *args, &block
end
end
|
Instance Attribute Details
#should_pass_through_whole ⇒ Object
2
3
4
|
# File 'lib/ext/array_ext.rb', line 2
def should_pass_through_whole
@should_pass_through_whole
end
|
Instance Method Details
#edge_array? ⇒ Boolean
28
29
30
|
# File 'lib/ext/array_ext.rb', line 28
def edge_array?
all?{|e| e.is_a? RedGrape::Edge}
end
|
#graph_item_array? ⇒ Boolean
32
33
34
|
# File 'lib/ext/array_ext.rb', line 32
def graph_item_array?
vertex_array? or edge_array?
end
|
#method_missing_with_prop_pipe(name, *args, &block) ⇒ Object
Also known as:
method_missing
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/ext/array_ext.rb', line 37
def method_missing_with_prop_pipe(name, *args, &block)
if graph_item_array?
map! do |e|
begin
e.send name, *args, &block
rescue NoMethodError
nil
end
end.compact!
else
method_missing_without_prop_pipe name, *args, &block
end
end
|
#normalize_for_graph ⇒ Object
18
19
20
21
22
|
# File 'lib/ext/array_ext.rb', line 18
def normalize_for_graph
reject! {|e| e.nil? or (e.respond_to?(:empty?) and e.empty?)}
flatten!
self
end
|
#pass_through(pipe, context) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/ext/array_ext.rb', line 4
def pass_through(pipe, context)
if @should_pass_through_whole
super
else
loops = context.loops
map! do |e|
context.loops = loops
pipe.pass e, context
end
context.loops = loops
normalize_for_graph
end
end
|
#vertex_array? ⇒ Boolean
24
25
26
|
# File 'lib/ext/array_ext.rb', line 24
def vertex_array?
all?{|e| e.is_a? RedGrape::Vertex}
end
|