Sha256: aea287008585f5623e3610d9f88f38ea6479a39cfe25290e4c36e239fa650cc8

Contents?: true

Size: 802 Bytes

Versions: 22

Compression:

Stored size: 802 Bytes

Contents

module Ransack
  module Nodes
    class Sort < Node
      include Bindable

      attr_reader :name, :dir
      i18n_word :asc, :desc

      class << self
        def extract(context, str)
          attr, direction = str.split(/\s+/,2)
          self.new(context).build(:name => attr, :dir => direction)
        end
      end

      def build(params)
        params.with_indifferent_access.each do |key, value|
          if key.match(/^(name|dir)$/)
            self.send("#{key}=", value)
          end
        end

        self
      end

      def valid?
        bound? && attr
      end

      def name=(name)
        @name = name
        context.bind(self, name) unless name.blank?
      end

      def dir=(dir)
        @dir = %w(asc desc).include?(dir) ? dir : 'asc'
      end

    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
ransack-1.0.0 lib/ransack/nodes/sort.rb
ransack-0.7.2 lib/ransack/nodes/sort.rb
ransack-0.7.1 lib/ransack/nodes/sort.rb
ransack_ffcrm-0.7.1 lib/ransack/nodes/sort.rb
ransack-0.7.0 lib/ransack/nodes/sort.rb
ransack_ffcrm-0.6.0 lib/ransack/nodes/sort.rb
ransack-0.6.0 lib/ransack/nodes/sort.rb
ransack-0.5.8 lib/ransack/nodes/sort.rb
ransack-0.5.7 lib/ransack/nodes/sort.rb
ransack-0.5.6 lib/ransack/nodes/sort.rb
ransack-0.5.5 lib/ransack/nodes/sort.rb
ransack-0.5.4 lib/ransack/nodes/sort.rb
ransack-0.5.3 lib/ransack/nodes/sort.rb
ransack-0.5.2 lib/ransack/nodes/sort.rb
ransack-0.5.1 lib/ransack/nodes/sort.rb
ransack-0.5.0 lib/ransack/nodes/sort.rb
ransack-0.4.2 lib/ransack/nodes/sort.rb
ransack-0.4.1 lib/ransack/nodes/sort.rb
ransack-0.4.0 lib/ransack/nodes/sort.rb
ransack-0.3.0 lib/ransack/nodes/sort.rb