Class: Authorize::Graph::Vertex
- Inherits:
-
Redis::Hash
- Object
- Redis::Base
- Redis::Hash
- Authorize::Graph::Vertex
- Defined in:
- lib/authorize/graph/vertex.rb
Constant Summary
Constants inherited from Redis::Base
Redis::Base::NAMESPACE_SEPARATOR
Instance Attribute Summary
Attributes inherited from Redis::Base
Class Method Summary collapse
Instance Method Summary collapse
- #adjacencies ⇒ Object (also: #neighbors)
- #destroy ⇒ Object
-
#inbound_edges ⇒ Object
This index is required for efficient backlinking, such as when deleting a vertex.
-
#initialize(properties = {}) ⇒ Vertex
constructor
A new instance of Vertex.
- #outbound_edges ⇒ Object (also: #edges)
-
#visit(edge) {|_self| ... } ⇒ Object
Visit this vertex via the given edge.
Methods inherited from Redis::Hash
#__getobj__, #get, #merge, #set, #valid?
Methods inherited from Redis::Base
#==, #__getobj__, #_dump, _load, connection, connection_base?, connection_manager, #db, #eql?, #exists?, generate_key, #hash, index, load, #logger, #method_missing, new, next_counter, #reload, #respond_to?, subordinate_key, #subordinate_key, #to_yaml, #valid?
Constructor Details
#initialize(properties = {}) ⇒ Vertex
Returns a new instance of Vertex.
16 17 18 19 20 21 |
# File 'lib/authorize/graph/vertex.rb', line 16 def initialize(properties = {}) super() # Because a degenerate vertex can have neither properties nor edges, we must store a marker to indicate existence self.class.db.set(subordinate_key('_'), nil) merge(properties) if properties.any? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Authorize::Redis::Base
Class Method Details
.exists?(id) ⇒ Boolean
4 5 6 |
# File 'lib/authorize/graph/vertex.rb', line 4 def self.exists?(id) super(subordinate_key(id, '_')) end |
.load_all(namespace = name) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/authorize/graph/vertex.rb', line 8 def self.load_all(namespace = name) redis_glob = subordinate_key(namespace, '*', '_') re = Regexp.new(subordinate_key(namespace, ".+(?=#{NAMESPACE_SEPARATOR})")) keys = db.keys(redis_glob) keys = keys.map{|m| m.slice(re)} keys.map{|id| load(id)} end |
Instance Method Details
#adjacencies ⇒ Object Also known as: neighbors
32 33 34 |
# File 'lib/authorize/graph/vertex.rb', line 32 def adjacencies outbound_edges.map(&:to) end |
#destroy ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/authorize/graph/vertex.rb', line 23 def destroy outbound_edges.each{|e| e.destroy} outbound_edges.destroy inbound_edges.each{|e| e.destroy} inbound_edges.destroy self.class.db.del(subordinate_key('_')) super end |
#inbound_edges ⇒ Object
This index is required for efficient backlinking, such as when deleting a vertex.
43 44 45 |
# File 'lib/authorize/graph/vertex.rb', line 43 def inbound_edges @inbound_edges || Redis::ModelSet.new(subordinate_key('inbound_edge_ids'), Edge) end |
#outbound_edges ⇒ Object Also known as: edges
37 38 39 |
# File 'lib/authorize/graph/vertex.rb', line 37 def outbound_edges @edges || Redis::ModelSet.new(subordinate_key('edge_ids'), Edge) end |
#visit(edge) {|_self| ... } ⇒ Object
Visit this vertex via the given edge
48 49 50 |
# File 'lib/authorize/graph/vertex.rb', line 48 def visit(edge, &block) yield self end |