Sha256: c0bb9c1fac8108bc6ead61798ffe7ca9f337f87c6dde2f4cc66dcdcad4b9557e

Contents?: true

Size: 897 Bytes

Versions: 1

Compression:

Stored size: 897 Bytes

Contents

class ModelSet
  module Conditioned
    # Shared methods for dealing with conditions.
    attr_accessor :conditions
    
    def add_conditions!(*conditions)
      operator = conditions.shift if conditions.first.kind_of?(Symbol)
      operator ||= :and

      # Sanitize conditions.
      conditions.collect! do |condition|
        condition.kind_of?(Conditions) ? condition : Conditions.new( sanitize_condition(condition) )
      end

      if operator == :not
        # In this case, :not actually means :and :not.
        conditions = ~Conditions.new(:and, *conditions)
        operator   = :and
      end

      conditions << @conditions if @conditions
      @conditions = Conditions.new(operator, *conditions)

      clear_cache!
    end

    def invert!
      raise 'cannot invert without conditions' if @conditions.nil?
      @conditions = ~@conditions
      clear_cache!
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
model_set-1.0.0 lib/model_set/conditioned.rb