Module: Liszt
- Defined in:
- lib/liszt.rb,
lib/liszt/railtie.rb,
lib/liszt/version.rb,
lib/liszt/redis_list.rb,
lib/liszt/instantizeable.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods, Instantizeable Classes: Railtie, RedisList
Constant Summary collapse
- VERSION =
"0.1.2"
Class Attribute Summary collapse
-
.redis ⇒ Object
Returns the value of attribute redis.
Class Method Summary collapse
Instance Method Summary collapse
-
#acts_as_liszt(options = {}) ⇒ Object
Set up a scoped ordering for this model.
Class Attribute Details
.redis ⇒ Object
Returns the value of attribute redis.
10 11 12 |
# File 'lib/liszt.rb', line 10 def redis @redis end |
Class Method Details
.merge_id_lists(canonical, modified, append = false) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/liszt.rb', line 12 def merge_id_lists(canonical, modified, append = false) if append (modified + (canonical - modified)) & canonical else ((canonical - modified) + modified) & canonical end end |
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.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/liszt.rb', line 38 def acts_as_liszt( = {}) extend Instantizeable extend ClassMethods include InstanceMethods # Make "instantized" versions of the class methods. ClassMethods.instance_methods.each do |method| instantize method end .reverse_merge! :conditions => {}, :scope => [] @liszt_conditions = [:conditions] @liszt_scope = Array([:scope]).sort_by(&:to_s) @liszt_query = nil @liszt_sort_by = [:sort_by] @liszt_append_new_items = [:append_new_items] end |