Class: Authorize::Graph::Graph
- Inherits:
-
Redis::Set
- Object
- Redis::Base
- Redis::Set
- Authorize::Graph::Graph
- Defined in:
- lib/authorize/graph/graph.rb
Overview
A binary property graph. Vertices and Edges have an arbitrary set of named properties. Reference: www.nist.gov/dads/HTML/graph.html
Direct Known Subclasses
Constant Summary
Constants inherited from Redis::Base
Redis::Base::NAMESPACE_SEPARATOR
Instance Attribute Summary collapse
Attributes inherited from Redis::Base
Class Method Summary collapse
Instance Method Summary collapse
-
#edge(name, *args) ⇒ Object
Create an edge on this graph with the given name and additional properties.
- #edges ⇒ Object
- #traverse(start = Vertex.load(sort_by{rand}.first)) ⇒ Object
-
#vertex(name, *args) ⇒ Object
Create an vertex on this graph with the given name and additional properties.
-
#vertex_by_name(name) ⇒ Object
Load the existing vertex in this graph with the given name.
- #vertices ⇒ Object
Methods inherited from Redis::Set
#<<, #__getobj__, #add, #delete, #first, #include?, #sample, #valid?
Methods inherited from Redis::Base
#==, #__getobj__, #_dump, _load, connection, connection_base?, connection_manager, #db, #destroy, #eql?, #exists?, generate_key, #hash, index, load, load_all, #logger, #method_missing, new, next_counter, #reload, #respond_to?, subordinate_key, #subordinate_key, #to_yaml, #valid?
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Authorize::Redis::Base
Instance Attribute Details
#edge_namespace ⇒ Object
14 15 16 |
# File 'lib/authorize/graph/graph.rb', line 14 def edge_namespace @edge_namespace ||= subordinate_key('_edges') end |
#vertex_namespace ⇒ Object
18 19 20 |
# File 'lib/authorize/graph/graph.rb', line 18 def vertex_namespace @vertex_namespace ||= subordinate_key('_vertices') end |
Class Method Details
.exists?(id) ⇒ Boolean
8 9 10 |
# File 'lib/authorize/graph/graph.rb', line 8 def self.exists?(id) db.keys(subordinate_key(id, '*')).any? end |
Instance Method Details
#edge(name, *args) ⇒ Object
Create an edge on this graph with the given name and additional properties.
38 39 40 41 42 |
# File 'lib/authorize/graph/graph.rb', line 38 def edge(name, *args) name ||= self.class.next_counter(edge_namespace) key = self.class.subordinate_key(edge_namespace, name) Edge.new(key, *args) end |
#edges ⇒ Object
22 23 24 |
# File 'lib/authorize/graph/graph.rb', line 22 def edges Edge.load_all(edge_namespace) end |
#traverse(start = Vertex.load(sort_by{rand}.first)) ⇒ Object
50 51 52 |
# File 'lib/authorize/graph/graph.rb', line 50 def traverse(start = Vertex.load(sort_by{rand}.first)) Traverser.traverse(start) end |
#vertex(name, *args) ⇒ Object
Create an vertex on this graph with the given name and additional properties.
31 32 33 34 35 |
# File 'lib/authorize/graph/graph.rb', line 31 def vertex(name, *args) name ||= self.class.next_counter(vertex_namespace) key = self.class.subordinate_key(vertex_namespace, name) Vertex.new(key, *args) end |