Skip to content

Commit

Permalink
Address the rest of offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 3, 2025
1 parent 1b7b900 commit 230de4d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
43 changes: 31 additions & 12 deletions lib/rom/sql/function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
#
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
#
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions lib/rom/types/values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 230de4d

Please sign in to comment.