Module: Liszt

Defined in:
lib/liszt.rb,
lib/liszt/version.rb,
lib/liszt/redis_list.rb,
lib/liszt/instantizeable.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods, Instantizeable Classes: RedisList

Constant Summary collapse

VERSION =
"0.0.7"

Instance Method Summary collapse

Instance Method Details

#acts_as_liszt(options = {}) ⇒ Object

Set up a scoped ordering for this model.

Liszt currently only supports one type of ranking per model. It also doesn't currently support re-sorting lists when a scope changes. The assumption is that attributes used as scopes won't change after creation.

The other major limitation at the moment is that scopes can't be nil. If a record has nil for a scope value, its associated list will never have any items in it.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :scope (Symbol, Array)

    The attribute or attributes to use as list constraints.

  • :conditions (Hash)

    Any extra constraints to impose.

  • :sort_by (Proc)

    A lambda to pass into initialize_list! the first time an item is added to an uninitialized list. It has the same semantics as Enumerable#sort_by.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/liszt.rb', line 25

def acts_as_liszt(options = {})
  extend Instantizeable
  extend ClassMethods
  include InstanceMethods

  # Make "instantized" versions of the class methods.
  ClassMethods.instance_methods.each do |method|
    instantize method
  end

  options.reverse_merge! :conditions => {}, :scope => []

  @liszt_conditions = options[:conditions]
  @liszt_scope = Array(options[:scope]).sort_by(&:to_s)
  @liszt_query = nil
  @liszt_sort_by = options[:sort_by]
  @liszt_append_new_items = options[:append_new_items]
end