From 230de4dd2e708c9aca3e72994bf07c85ee39cbcc Mon Sep 17 00:00:00 2001 From: Nikita Shilnikov Date: Fri, 3 Jan 2025 12:52:18 +0100 Subject: [PATCH] Address the rest of offenses --- lib/rom/sql/function.rb | 43 +++++++++++++++++++++++++++++------------ lib/rom/types/values.rb | 6 ++---- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/lib/rom/sql/function.rb b/lib/rom/sql/function.rb index a8a17bc7..1d6afa1b 100644 --- a/lib/rom/sql/function.rb +++ b/lib/rom/sql/function.rb @@ -19,10 +19,10 @@ def frame_limit(value) when :start then 'UNBOUNDED PRECEDING' when :end then 'UNBOUNDED FOLLOWING' else - if value > 0 - "#{ value } FOLLOWING" + if value.positive? + "#{value} FOLLOWING" else - "#{ value.abs } PRECEDING" + "#{value.abs} PRECEDING" end end end @@ -34,13 +34,14 @@ def frame_limit(value) WINDOW_FRAMES = Hash.new do |cache, frame| type = frame.key?(:rows) ? 'ROWS' : 'RANGE' bounds = frame[:rows] || frame[:range] - cache[frame] = "#{ type } BETWEEN #{ frame_limit(bounds[0]) } AND #{ frame_limit(bounds[1]) }" + cache[frame] = + "#{type} BETWEEN #{frame_limit(bounds[0])} AND #{frame_limit(bounds[1])}" end WINDOW_FRAMES[nil] = nil - WINDOW_FRAMES[:all] = WINDOW_FRAMES[rows: [:start, :end]] - WINDOW_FRAMES[:rows] = WINDOW_FRAMES[rows: [:start, :current]] - WINDOW_FRAMES[{ range: :current }] = WINDOW_FRAMES[range: [:current, :current]] + WINDOW_FRAMES[:all] = WINDOW_FRAMES[rows: %i[start end]] + WINDOW_FRAMES[:rows] = WINDOW_FRAMES[rows: %i[start current]] + WINDOW_FRAMES[{ range: :current }] = WINDOW_FRAMES[range: %i[current current]] # Return a new attribute with an alias # @@ -88,10 +89,10 @@ def qualified_projection(table_alias = nil) end # @api private - def new(&block) + def new(&) case func when ::Sequel::SQL::Function - meta(func: ::Sequel::SQL::Function.new!(func.name, func.args.map(&block), func.opts)) + meta(func: ::Sequel::SQL::Function.new!(func.name, func.args.map(&), func.opts)) else meta(func: func) end @@ -125,7 +126,15 @@ def not(other) # # @example # users.select { [id, integer::row_number().over(partition: name, order: id).as(:row_no)] } - # users.select { [id, integer::row_number().over(partition: [first_name, last_name], order: id).as(:row_no)] } + # users.select { + # [ + # id, + # integer::row_number().over( + # partition: [first_name, last_name], + # order: id + # ).as(:row_no) + # ] + # } # # @example frame variants # # ROWS BETWEEN 3 PRECEDING AND CURRENT ROW @@ -167,7 +176,8 @@ def over(partition: nil, order: nil, frame: nil) # users.select { bool::cast(json_data.get_text('activated')).as(:activated) } # # @param [ROM::SQL::Attribute] expr Expression to be cast - # @param [String] db_type Target database type (usually can be inferred from the target data type) + # @param [String] db_type + # Target database type (usually can be inferred from the target data type) # # @return [ROM::SQL::Attribute] # @@ -214,7 +224,7 @@ def case(mapping) def filter(condition = Undefined, &block) if block conditions = schema.restriction(&block) - conditions = conditions & condition unless condition.equal?(Undefined) + conditions &= condition unless condition.equal?(Undefined) else conditions = condition end @@ -258,6 +268,15 @@ def func meta[:func] end + # @api private + def respond_to_missing?(meth, _include_private = false) + if func + func.respond_to?(meth) || super + else + true + end + end + # @api private def method_missing(meth, *args) if func diff --git a/lib/rom/types/values.rb b/lib/rom/types/values.rb index 2b122efe..2113495b 100644 --- a/lib/rom/types/values.rb +++ b/lib/rom/types/values.rb @@ -5,11 +5,9 @@ module ROM module Types module Values - class TreePath < ::Struct.new(:value, :separator) - DEFAULT_SEPARATOR = '.' - + class TreePath < ::Struct.new(:value, :separator) # rubocop:disable Style/StructInheritance # @api public - def self.new(value, separator = DEFAULT_SEPARATOR) + def self.new(value, separator = '.') super end