Class: Pacer::Wrappers::ElementWrapper
- Inherits:
-
Object
- Object
- Pacer::Wrappers::ElementWrapper
- Extended by:
- Forwardable
- Includes:
- Comparable, Core::Graph::ElementRoute, Element, Routes::RouteOperations
- Defined in:
- lib/pacer/wrappers/element_wrapper.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.caches ⇒ Object
Returns the value of attribute caches.
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#graph ⇒ PacerGraph
readonly
For internal use only.
Class Method Summary collapse
- .add_extensions(exts) ⇒ Object
- .base_edge_wrapper ⇒ Object
- .base_vertex_wrapper ⇒ Object
- .clear_cache ⇒ Object
- .extensions ⇒ Object
- .lookup(graph) ⇒ Object
- .route_conditions(graph) ⇒ Object
- .wrap(element, exts) ⇒ Object
Instance Method Summary collapse
-
#<=>(other) ⇒ Fixnum
Sort objects semi arbitrarily based on #display_name.
-
#[](key) ⇒ Object
Convenience method to retrieve a property by name.
-
#[]=(key, value) ⇒ Object
Convenience method to set a property by name to the given value.
- #chain_route(args_hash) ⇒ Object
-
#element_id ⇒ Object
The id of the current element.
- #element_payload ⇒ Object
-
#from_graph?(g) ⇒ Boolean
Query whether the current node belongs to the given graph.
-
#initialize(graph, element) ⇒ ElementWrapper
constructor
A new instance of ElementWrapper.
-
#properties ⇒ Hash
Returns a hash of property values by name.
-
#properties=(props) ⇒ Object
Replace the element’s properties with the given hash.
- #property_keys ⇒ Object
- #reload ⇒ Object
-
#result(name = nil) ⇒ ElementWrapper
Specialize result to return self for elements.
Methods included from Core::Graph::ElementRoute
#build_index, #clone_into, #copy_into, #delete!, #e, #element_ids, #filter, #payload, #property?, #raw_property_maps, #subgraph, #typed_property, #v
Methods included from Routes::RouteOperations
#aggregate, #all, #as, #as_var, #at, #breadth_first, #compact, #count, #count_section, #counted, #custom_sort_section, #deepest, #difference_sections, #edges_route?, #fast_group_count, #flat_map, #frequency_counts, #frequency_groups, #gather_section, #group_count, #has?, #has_count?, #has_count_route, #identity, #inspect_class_name, #intersect_sections, #is, #is_not, #is_unique, #java_loop, #join, #left_difference_sections, #limit, #limit_section, #lookahead, #lookup_ids, #loop, #make_pairs, #map, #mixed_route?, #most_frequent, #neg_lookahead, #offset, #pages, #parallel, #process, #range, #reducer, #reject, #repeat, #right_difference_sections, #section, #select, #sort_section, #stream_sort, #stream_uniq, #uniq, #uniq_in_section, #unique?, #unique_path, #unjoin, #unless, #vertices_route?, #visitor, #where
Methods included from Routes::BulkOperations
Constructor Details
#initialize(graph, element) ⇒ ElementWrapper
Returns a new instance of ElementWrapper.
101 102 103 104 105 106 107 108 109 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 101 def initialize(graph, element) @graph = graph if element.is_a? ElementWrapper @element = element.element else @element = element end after_initialize end |
Class Attribute Details
.caches ⇒ Object
Returns the value of attribute caches.
10 11 12 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 10 def caches @caches end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
99 100 101 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 99 def element @element end |
#graph ⇒ PacerGraph (readonly)
For internal use only.
The graph the element belongs to.
Used to help prevent objects from different graphs from being accidentally associated, as well as to get graph-specific data for the element.
98 99 100 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 98 def graph @graph end |
Class Method Details
.add_extensions(exts) ⇒ Object
28 29 30 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 28 def add_extensions(exts) wrapper_for(extensions + exts.to_a) end |
.base_edge_wrapper ⇒ Object
16 17 18 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 16 def base_edge_wrapper EdgeWrapper end |
.base_vertex_wrapper ⇒ Object
12 13 14 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 12 def base_vertex_wrapper VertexWrapper end |
.clear_cache ⇒ Object
32 33 34 35 36 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 32 def clear_cache VertexWrapper.clear_cache EdgeWrapper.clear_cache caches.each { |c| c.clear_cache } if caches end |
.extensions ⇒ Object
24 25 26 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 24 def extensions @extensions ||= [] end |
.lookup(graph) ⇒ Object
43 44 45 46 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 43 def lookup(graph) return @lookup if defined? @lookup @lookup = extensions.inject({}, &reduce_extensions(graph, :lookup)) end |
.route_conditions(graph) ⇒ Object
38 39 40 41 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 38 def route_conditions(graph) return @route_conditions if defined? @route_conditions @route_conditions = extensions.inject({}, &reduce_extensions(graph, :route_conditions)) end |
.wrap(element, exts) ⇒ Object
20 21 22 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 20 def wrap(element, exts) wrapper_for(exts).new(element.graph, element.element) end |
Instance Method Details
#<=>(other) ⇒ Fixnum
Sort objects semi arbitrarily based on #display_name.
191 192 193 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 191 def <=>(other) display_name.to_s <=> other.display_name.to_s end |
#[](key) ⇒ Object
Convenience method to retrieve a property by name.
119 120 121 122 123 124 125 126 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 119 def [](key) if key.is_a? Array key.map { |k| self[k] } else value = element.getProperty(key.to_s) graph.decode_property(value) end end |
#[]=(key, value) ⇒ Object
Convenience method to set a property by name to the given value.
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 131 def []=(key, value) begin value = graph.encode_property(value) rescue Exception => e throw Pacer::ClientError.new "Unable to serialize #{ key }: #{ value.class }" end key = key.to_s if value.nil? element.removeProperty(key) else element.setProperty(key, value) end end |
#chain_route(args_hash) ⇒ Object
111 112 113 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 111 def chain_route(args_hash) Pacer::RouteBuilder.current.chain self, args_hash end |
#element_id ⇒ Object
The id of the current element
183 184 185 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 183 def element_id element.getId end |
#element_payload ⇒ Object
195 196 197 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 195 def element_payload element.payload if element.is_a? Pacer::Payload::Element end |
#from_graph?(g) ⇒ Boolean
Query whether the current node belongs to the given graph.
154 155 156 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 154 def from_graph?(g) g.blueprints_graph.equal? graph.blueprints_graph end |
#properties ⇒ Hash
Returns a hash of property values by name.
161 162 163 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 161 def properties Hash[element.getPropertyKeys.map { |name| [name, graph.decode_property(element.getProperty(name))] }] end |
#properties=(props) ⇒ Object
Replace the element’s properties with the given hash
168 169 170 171 172 173 174 175 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 168 def properties=(props) (element.getPropertyKeys - props.keys.collect { |k| k.to_s }).each do |key| element.removeProperty key end props.each do |key, value| self[key] = value end end |
#property_keys ⇒ Object
177 178 179 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 177 def property_keys getPropertyKeys end |
#reload ⇒ Object
199 200 201 202 203 204 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 199 def reload if element.respond_to? :reload element.reload end self end |
#result(name = nil) ⇒ ElementWrapper
Specialize result to return self for elements.
147 148 149 |
# File 'lib/pacer/wrappers/element_wrapper.rb', line 147 def result(name = nil) self end |