lib/redgraph/graph.rb in redgraph-0.1.3 vs lib/redgraph/graph.rb in redgraph-0.1.4
- old
+ new
@@ -8,12 +8,16 @@
include NodeMethods
include EdgeMethods
attr_accessor :connection, :graph_name
- def initialize(graph, redis_options = {})
- @graph_name = graph
+ # @example Graph.new("foobar", url: "redis://localhost:6379/0", logger: Logger.new(STDOUT))
+ # @param graph_name [String] Name of the graph
+ # @param redis_options [Hash] Redis client options
+ #
+ def initialize(graph_name, redis_options = {})
+ @graph_name = graph_name
@connection = Redis.new(redis_options)
@module_version = module_version
raise ServerError unless @module_version
end
@@ -33,31 +37,31 @@
# Catch exception if the graph was already deleted
return nil if e.message =~ /ERR Invalid graph operation on empty key/
raise e
end
- # Returns an array of existing graphs
+ # @return [Array] Existing graph names
#
def list
@connection.call("GRAPH.LIST")
end
- # Returns an array of existing labels
+ # @return [Array] Existing labels
#
def labels
result = _query("CALL db.labels()")
result.resultset.map(&:values).flatten
end
- # Returns an array of existing properties
+ # @return [Array] Existing properties
#
def properties
result = _query("CALL db.propertyKeys()")
result.resultset.map(&:values).flatten
end
- # Returns an array of existing relationship types
+ # @return [Array] Existing relationship types
#
def relationship_types
result = _query("CALL db.relationshipTypes()")
result.resultset.map(&:values).flatten
end
@@ -65,20 +69,29 @@
# You can run custom cypher queries
def query(cmd)
_query(cmd).rows
end
+ # @param id [Integer] label id
+ # @return [String, nil] label
+ #
def get_label(id)
@labels ||= labels
@labels[id] || (@labels = labels)[id]
end
+ # @param id [Integer] property id
+ # @return [String, nil] property
+ #
def get_property(id)
@properties ||= properties
@properties[id] || (@properties = properties)[id]
end
+ # @param id [Integer] relationship type id
+ # @return [String, nil] relationship type
+ #
def get_relationship_type(id)
@relationship_types ||= relationship_types
@relationship_types[id] || (@relationship_types = relationship_types)[id]
end
@@ -86,23 +99,7 @@
def _query(cmd)
data = @connection.call("GRAPH.QUERY", graph_name, cmd, "--compact")
QueryResponse.new(data, self)
end
-
- def quote_hash(hash)
- "{" +
- hash.map {|k,v| "#{k}:#{escape_value(v)}" }.join(", ") +
- "}"
- end
-
- def escape_value(x)
- case x
- when Integer then x
- when NilClass then "''"
- else
- '"' + x.gsub('"', '\"') + '"'
- end
- end
-
end
end