Class: Listalicious::ActiveRecordExtensions::OrderableConfiguration
- Inherits:
-
Object
- Object
- Listalicious::ActiveRecordExtensions::OrderableConfiguration
- Defined in:
- lib/listalicious.rb
Instance Method Summary collapse
-
#default(*args) ⇒ Object
Provide the default sort field, optionally a direction, and additional options.
-
#except(*args) ⇒ Object
Provide fields that are not to be orderable, with the default list being all fields.
-
#initialize(target) ⇒ OrderableConfiguration
constructor
A new instance of OrderableConfiguration.
-
#only(*args) ⇒ Object
Provide fields that are orderable in the configuration block.
Constructor Details
#initialize(target) ⇒ OrderableConfiguration
Returns a new instance of OrderableConfiguration.
92 93 94 |
# File 'lib/listalicious.rb', line 92 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
126 127 128 129 130 131 132 |
# File 'lib/listalicious.rb', line 126 def default(*args) = args. field = args.shift direction = args.shift || :asc @target.default_order = {:field => field, :direction => direction, :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
112 113 114 |
# File 'lib/listalicious.rb', line 112 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
102 103 104 |
# File 'lib/listalicious.rb', line 102 def only(*args) @target.orderable_fields = args end |