Sha256: a955ae17319d4654ce4327731fe361f6193d5d2f3c703bb081c1d82aa37744f4

Contents?: true

Size: 1.3 KB

Versions: 14

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

unless Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 2 || Rails::VERSION::MAJOR > 5
  require 'thredded/rails_lt_5_2_arel_case_node.rb'
end

if Rails::VERSION::MAJOR == 4
  # Make `pluck` compatible with Arel.
  require 'active_record/relation'
  ActiveRecord::Relation.prepend(Module.new do
    def pluck(*column_names)
      super(*column_names.map do |n|
        if n.is_a?(Arel::Node)
          Arel.sql(n.to_sql)
        elsif n.is_a?(Arel::Attributes::Attribute)
          n.name
        else
          n
        end
      end)
    end
  end)
end

module Thredded
  module ArelCompat
    module_function

    # @param [#connection] engine
    # @param [Arel::Nodes::Node] a integer node
    # @param [Arel::Nodes::Node] b integer node
    # @return [Arel::Nodes::Node] a / b
    def integer_division(engine, a, b)
      if engine.connection.adapter_name =~ /mysql|mariadb/i
        Arel::Nodes::InfixOperation.new('DIV', a, b)
      else
        Arel::Nodes::Division.new(a, b)
      end
    end

    if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 2 || Rails::VERSION::MAJOR > 5
      def true_value(_engine)
        true
      end
    else
      def true_value(engine)
        engine.connection.adapter_name =~ /sqlite|mysql|mariadb/i ? 1 : true
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
thredded-0.16.14 lib/thredded/arel_compat.rb
thredded-0.16.13 lib/thredded/arel_compat.rb
thredded-0.16.12 lib/thredded/arel_compat.rb
thredded-0.16.11 lib/thredded/arel_compat.rb
thredded-0.16.10 lib/thredded/arel_compat.rb
thredded-0.16.9 lib/thredded/arel_compat.rb
thredded-0.16.8 lib/thredded/arel_compat.rb
thredded-0.16.7 lib/thredded/arel_compat.rb
thredded-0.16.6 lib/thredded/arel_compat.rb
thredded-0.16.5 lib/thredded/arel_compat.rb
thredded-0.16.4 lib/thredded/arel_compat.rb
thredded-0.16.3 lib/thredded/arel_compat.rb
thredded-0.16.1 lib/thredded/arel_compat.rb
thredded-0.16.0 lib/thredded/arel_compat.rb