Sha256: deebf7373b528252d18d12ddc750da2e0c4978e9d5e636d2345e641458f5c948

Contents?: true

Size: 693 Bytes

Versions: 21

Compression:

Stored size: 693 Bytes

Contents

module SortField
  extend ActiveSupport::Concern

  module ClassMethods
    def sort_field(prefix = '')
      prefix = "#{prefix}_" unless prefix == ''

      if RocketCMS.mongoid?
        field "#{prefix}order".to_sym, type: Integer
        alias_method "#{prefix}sort", "#{prefix}order"
        scope "#{prefix}ordered".to_sym,  -> { asc("#{prefix}order".to_sym) }
        scope "#{prefix}sorted".to_sym,   -> { asc("#{prefix}order".to_sym) }
      end
      if RocketCMS.active_record?
        scope "#{prefix}ordered".to_sym,  -> { order("#{prefix}order".to_sym => :asc) }
        scope "#{prefix}sorted".to_sym,   -> { order("#{prefix}order".to_sym => :asc) }
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
ack_rocket_cms-0.9.2 app/models/concerns/sort_field.rb
ack_rocket_cms-0.9.1.3 app/models/concerns/sort_field.rb
ack_rocket_cms-0.9.1.2 app/models/concerns/sort_field.rb
ack_rocket_cms-0.9.1.1 app/models/concerns/sort_field.rb
ack_rocket_cms-0.9.1 app/models/concerns/sort_field.rb
ack_rocket_cms-0.9 app/models/concerns/sort_field.rb
ack_rocket_cms-0.8.2 app/models/concerns/sort_field.rb
ack_rocket_cms-0.8.0 app/models/concerns/sort_field.rb
ack_rocket_cms-0.7.7.1 app/models/concerns/sort_field.rb
ack_rocket_cms-0.7.7 app/models/concerns/sort_field.rb
ack_rocket_cms-0.7.6.4 app/models/concerns/sort_field.rb
ack_rocket_cms-0.7.6.3 app/models/concerns/sort_field.rb
ack_rocket_cms-0.7.6.2 app/models/concerns/sort_field.rb
ack_rocket_cms-0.7.6.1 app/models/concerns/sort_field.rb
ack_rocket_cms-0.7.6 app/models/concerns/sort_field.rb
ack_rocket_cms-0.7.5.2 app/models/concerns/sort_field.rb
ack_rocket_cms-0.7.5.1 app/models/concerns/sort_field.rb
ack_rocket_cms-0.7.5 app/models/concerns/sort_field.rb
ack_rocket_cms-0.7.4.1 app/models/concerns/sort_field.rb
ack_rocket_cms-0.7.4 app/models/concerns/sort_field.rb