Class: Mobility::Backend::Sequel::Column::QueryMethods

Inherits:
QueryMethods show all
Defined in:
lib/mobility/backend/sequel/column/query_methods.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes, **options) ⇒ QueryMethods

Returns a new instance of QueryMethods.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mobility/backend/sequel/column/query_methods.rb', line 4

def initialize(attributes, **options)
  super
  attributes_extractor = @attributes_extractor

  define_method :_filter_or_exclude do |invert, clause, cond, &block|
    if keys = attributes_extractor.call(cond)
      cond = cond.dup
      keys.each { |attr| cond[Column.column_name_for(attr)] = cond.delete(attr) }
    end
    super(invert, clause, cond, &block)
  end

  attributes.each do |attribute|
    define_method :"first_by_#{attribute}" do |value|
      where(attribute.to_sym => value).first
    end
  end
end