Class: Sequel::SeekPagination::OrderedColumn

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel/extensions/seek_pagination.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(set, order, value) ⇒ OrderedColumn

Returns a new instance of OrderedColumn.



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/sequel/extensions/seek_pagination.rb', line 171

def initialize(set, order, value)
  @set = set
  @value = value
  @name, @direction, @nulls =
    case order
    when Sequel::SQL::OrderedExpression
      direction = order.descending ? :desc : :asc
      nulls = order.nulls || default_nulls_option(direction)
      [order.expression, direction, nulls]
    else
      [order, :asc, :last]
    end

  @not_null = set.not_null.include?(@name)
end

Instance Attribute Details

#directionObject (readonly)

Returns the value of attribute direction.



169
170
171
# File 'lib/sequel/extensions/seek_pagination.rb', line 169

def direction
  @direction
end

#nameObject (readonly)

Returns the value of attribute name.



169
170
171
# File 'lib/sequel/extensions/seek_pagination.rb', line 169

def name
  @name
end

#not_nullObject (readonly)

Returns the value of attribute not_null.



169
170
171
# File 'lib/sequel/extensions/seek_pagination.rb', line 169

def not_null
  @not_null
end

#nullsObject (readonly)

Returns the value of attribute nulls.



169
170
171
# File 'lib/sequel/extensions/seek_pagination.rb', line 169

def nulls
  @nulls
end

#valueObject (readonly)

Returns the value of attribute value.



169
170
171
# File 'lib/sequel/extensions/seek_pagination.rb', line 169

def value
  @value
end

Instance Method Details

#eq_filterObject



191
192
193
# File 'lib/sequel/extensions/seek_pagination.rb', line 191

def eq_filter
  {name => value}
end

#inequality_condition(allow_equal:) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/sequel/extensions/seek_pagination.rb', line 199

def inequality_condition(allow_equal:)
  nulls_upcoming = !not_null && nulls == :last

  if value.nil?
    if nulls_upcoming && allow_equal
      null_filter
    elsif !nulls_upcoming && !allow_equal
      Sequel.~(null_filter)
    else
      # No condition necessary.
      nil
    end
  else
    # Value is not null.
    filter = Sequel.virtual_row { |o| o.__send__(inequality_method(allow_equal), name, value) }

    if nulls_upcoming
      Sequel.|(filter, null_filter)
    else
      filter
    end
  end
end

#inequality_method(allow_equal) ⇒ Object



223
224
225
226
227
228
229
# File 'lib/sequel/extensions/seek_pagination.rb', line 223

def inequality_method(allow_equal)
  case direction
  when :asc  then allow_equal ? :>= : :>
  when :desc then allow_equal ? :<= : :<
  else raise "Bad direction: #{direction.inspect}"
  end
end

#null_filterObject



195
196
197
# File 'lib/sequel/extensions/seek_pagination.rb', line 195

def null_filter
  {name => nil}
end

#nulls_option_is_default?Boolean

Returns:

  • (Boolean)


187
188
189
# File 'lib/sequel/extensions/seek_pagination.rb', line 187

def nulls_option_is_default?
  nulls == default_nulls_option(direction)
end