lib/hari/node/queries/relation.rb in hari-0.0.3 vs lib/hari/node/queries/relation.rb in hari-0.0.4
- old
+ new
@@ -10,10 +10,12 @@
include Relation::Step
include Relation::Runnable
attr_reader :parent, :direction, :relation, :level, :options
+ alias :name :relation
+
def initialize(parent, direction, relation, *args)
@parent, @direction, @relation = parent, direction, relation
@level = parent.level + 1
@options = {}
args.extract_options!.each { |k, v| send k, v }
@@ -24,28 +26,26 @@
def backend
options[:backend]
end
def calculate_limit
- options[:limit] ? (options[:limit].to_i - 1) : -1
+ options[:limit] || -1
end
- %w(limit from step).each do |method|
+ %w(limit step).each do |method|
define_method method do |value|
options[method.to_sym] = value
self
end
end
- # TODO for later, filter by node type
- def types(*types)
- options[:types] = types
+ def from(score, direction = nil)
+ direction ||= :up
+ options[:from] = { score: score, direction: direction.to_s }
self
end
- alias :type :types
-
%w(nodes_ids relations_ids nodes).each do |result_type|
define_method result_type do
options[:result_type] = result_type.to_sym
self
end
@@ -57,9 +57,15 @@
end
alias :nids :nodes_ids
alias :rel_ids :relations_ids
alias :rids :relations_ids
+
+ def type(name)
+ fail 'type not supported for chained queries' if level > 1
+
+ Type.new self, name
+ end
def count
options[:result_type] = :count
result
end