Sha256: bf867d340bec46b4d93acf459be3023b86a11dcff6923e4904171acacfaa95d3

Contents?: true

Size: 838 Bytes

Versions: 2

Compression:

Stored size: 838 Bytes

Contents

module Mobility
  module Backend
    class Sequel::Column::QueryMethods < Backend::Sequel::QueryMethods
      def initialize(attributes, **)
        super
        attributes_extractor = @attributes_extractor

        %w[exclude or where].each do |method_name|
          define_method method_name do |*conds, &block|
            if keys = attributes_extractor.call(conds.first)
              cond = conds.first.dup
              keys.each { |attr| cond[Column.column_name_for(attr)] = cond.delete(attr) }
              super(cond, &block)
            else
              super(*conds, &block)
            end
          end
        end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mobility-0.1.20 lib/mobility/backend/sequel/column/query_methods.rb
mobility-0.1.19 lib/mobility/backend/sequel/column/query_methods.rb