Sha256: c12c4408a440931f9ee3339c134c06a9fbe399bf8421abef036a397a7651729e

Contents?: true

Size: 1.28 KB

Versions: 14

Compression:

Stored size: 1.28 KB

Contents

module Arel
  module Nodes
    class Case < Arel::Nodes::Node
      include Arel::OrderPredications
      include Arel::Predications
      include Arel::AliasPredication

      attr_accessor :case, :conditions, :default

      def initialize expression = nil, default = nil
        @case = expression
        @conditions = []
        @default = default
      end

      def when condition, expression = nil
        @conditions << When.new(Nodes.build_quoted(condition), expression)
        self
      end

      def then expression
        @conditions.last.right = Nodes.build_quoted(expression)
        self
      end

      def else expression
        @default = Else.new Nodes.build_quoted(expression)
        self
      end

      def initialize_copy other
        super
        @case = @case.clone if @case
        @conditions = @conditions.map { |x| x.clone }
        @default = @default.clone if @default
      end

      def hash
        [@case, @conditions, @default].hash
      end

      def eql? other
        self.class == other.class &&
          self.case == other.case &&
          self.conditions == other.conditions &&
          self.default == other.default
      end
      alias :== :eql?
    end

    class When < Binary # :nodoc:
    end

    class Else < Unary # :nodoc:
    end
  end
end

Version data entries

14 entries across 14 versions & 4 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/arel-7.1.4/lib/arel/nodes/case.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/arel-7.1.4/lib/arel/nodes/case.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/arel-7.1.4/lib/arel/nodes/case.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/arel-7.1.4/lib/arel/nodes/case.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/arel-7.1.4/lib/arel/nodes/case.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/arel-7.1.4/lib/arel/nodes/case.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/arel-7.1.4/lib/arel/nodes/case.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/arel-7.1.4/lib/arel/nodes/case.rb
abaci-0.3.0 vendor/bundle/gems/arel-7.1.0/lib/arel/nodes/case.rb
arel-7.1.4 lib/arel/nodes/case.rb
arel-7.1.3 lib/arel/nodes/case.rb
arel-7.1.2 lib/arel/nodes/case.rb
arel-7.1.1 lib/arel/nodes/case.rb
arel-7.1.0 lib/arel/nodes/case.rb