Class: Listalicious::ActiveRecordExtensions::OrderableConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/listalicious.rb

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ OrderableConfiguration

Returns a new instance of OrderableConfiguration.



47
48
49
# File 'lib/listalicious.rb', line 47

def initialize(target)
  @target = target
end

Instance Method Details

#default(*args) ⇒ Object

Provide the default sort field, optionally a direction, and additional options.

Supported options

:stable

Will force appending the default sort to the end of all sort requests. Default is false.

Example

default :first_name (direction defaults to :asc)
default :first_name, :stable => true
default :first_name, :desc, :stable => true


81
82
83
84
85
86
87
# File 'lib/listalicious.rb', line 81

def default(*args)
  options = args.extract_options!
  field = args.shift
  direction = args.shift || :asc

  @target.default_order = {:field => field, :direction => direction, :options => options}
end

#except(*args) ⇒ Object

Provide fields that are not to be orderable, with the default list being all fields.

Note: If only or except aren’t called from within the configuration block, all fields will be orderable.

Example

except :id, :password


67
68
69
# File 'lib/listalicious.rb', line 67

def except(*args)
  @target.orderable_fields - args
end

#only(*args) ⇒ Object

Provide fields that are orderable in the configuration block.

Note: If only or except aren’t called from within the configuration block, all fields will be orderable.

Example

only :last_name, :email_address


57
58
59
# File 'lib/listalicious.rb', line 57

def only(*args)
  @target.orderable_fields = args
end