lib/grumlin/repository.rb in grumlin-0.19.7 vs lib/grumlin/repository.rb in grumlin-0.20.0

- old
+ new

@@ -21,11 +21,11 @@ return_mode = validate_return_mode!(return_mode) postprocess_with = validate_postprocess_with!(postprocess_with) define_method name do |*args, query_params: {}, **params, &block| t = instance_exec(*args, **params, &query_block) - return t if self.class.empty_result?(t) + return t if t.nil? || (t.respond_to?(:empty?) && t.empty?) unless t.is_a?(Grumlin::Action) raise WrongQueryResult, "queries must return #{Grumlin::Action}, nil or an empty collection. Given: #{t.class}" end @@ -43,12 +43,24 @@ return send(postprocess_with, result) unless postprocess_with.nil? end end end + def default_vertex_properties(&block) + shortcut :addV, override: true do |*args| + super(*args).props(**block.call(*args)) # rubocop:disable Performance/RedundantBlockCall + end + end + + def default_edge_properties(&block) + shortcut :addE, override: true do |*args| + super(*args).props(**block.call(*args)) # rubocop:disable Performance/RedundantBlockCall + end + end + def validate_return_mode!(return_mode) - return return_mode if RETURN_MODES.key?(return_mode) + return return_mode if RETURN_MODES.include?(return_mode) raise ArgumentError, "unsupported return mode #{return_mode}. Supported modes: #{RETURN_MODES.keys}" end def validate_postprocess_with!(postprocess_with) @@ -57,12 +69,8 @@ return postprocess_with end raise ArgumentError, "postprocess_with must be a String, Symbol or a callable object, given: #{postprocess_with.class}" - end - - def empty_result?(result) - result.nil? || (result.respond_to?(:empty?) && result.empty?) end end end