Sha256: 462e5627a1b1d1546f6126cd01416127f8cd197b4ff607004bfdfb0424a32850

Contents?: true

Size: 519 Bytes

Versions: 6

Compression:

Stored size: 519 Bytes

Contents

module Hobo

  class WhereFragment

    def initialize(sql, *params)
      @sql = params.empty? ? sql : ActiveRecord::Base.send(:sanitize_sql, [sql] + params)
    end

    def &(rhs)
      # If either is nil, just return the other
      if self.to_sql && rhs.to_sql
        WhereFragment.new("(#{to_sql}) and (#{rhs.to_sql})")
      else
        self.to_sql || rhs.to_sql
      end
    end

    def |(rhs)
      WhereFragment.new("(#{to_sql}) or (#{rhs.to_sql})")
    end

    def to_sql
      @sql
    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hobo-0.6.3 hobo_files/plugin/lib/hobo/where_fragment.rb
hobo-0.7.1 hobo_files/plugin/lib/hobo/where_fragment.rb
hobo-0.6.2 hobo_files/plugin/lib/hobo/where_fragment.rb
hobo-0.6.4 hobo_files/plugin/lib/hobo/where_fragment.rb
hobo-0.7.0 hobo_files/plugin/lib/hobo/where_fragment.rb
hobo-0.7.2 hobo_files/plugin/lib/hobo/where_fragment.rb