Module: LexoRanker::RankableMethods::Base::ClassMethods
- Defined in:
- lib/lexoranker/rankable_methods/base.rb
Instance Attribute Summary collapse
-
#rankable_column ⇒ String
readonly
The column to hold the rank value.
-
#rankable_default_insert_pos ⇒ Symbol
readonly
Default insert position for newly rank-created elements.
-
#rankable_ranker ⇒ Class
readonly
The ranker to use.
-
#rankable_scope ⇒ String
readonly
The scope of the rankings.
Instance Method Summary collapse
-
#create_ranked(attributes, position: nil) {|instance| ... } ⇒ Object
Create a new instance of the rankable class with a ranking at ‘position`.
-
#rankable_by(field: :rank, scope_by: nil, ranker: LexoRanker::Ranker.new, default_insert_pos: :bottom) ⇒ void
(also: #rankable)
Method to set up the rankable column and add the rankable scope and validations to the class including Rankable.
Instance Attribute Details
#rankable_column ⇒ String (readonly)
The column to hold the rank value
14 15 16 |
# File 'lib/lexoranker/rankable_methods/base.rb', line 14 def rankable_column @rankable_column end |
#rankable_default_insert_pos ⇒ Symbol (readonly)
Default insert position for newly rank-created elements
26 27 28 |
# File 'lib/lexoranker/rankable_methods/base.rb', line 26 def rankable_default_insert_pos @rankable_default_insert_pos end |
#rankable_ranker ⇒ Class (readonly)
The ranker to use
22 23 24 |
# File 'lib/lexoranker/rankable_methods/base.rb', line 22 def rankable_ranker @rankable_ranker end |
#rankable_scope ⇒ String (readonly)
The scope of the rankings
18 19 20 |
# File 'lib/lexoranker/rankable_methods/base.rb', line 18 def rankable_scope @rankable_scope end |
Instance Method Details
#create_ranked(attributes, position: nil) {|instance| ... } ⇒ Object
Create a new instance of the rankable class with a ranking at ‘position`.
57 58 |
# File 'lib/lexoranker/rankable_methods/base.rb', line 57 def create_ranked(attributes, position: nil, &block) end |
#rankable_by(field: :rank, scope_by: nil, ranker: LexoRanker::Ranker.new, default_insert_pos: :bottom) ⇒ void Also known as: rankable
This method returns an undefined value.
Method to set up the rankable column and add the rankable scope and validations to the class including Rankable
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lexoranker/rankable_methods/base.rb', line 35 def rankable_by(field: :rank, scope_by: nil, ranker: LexoRanker::Ranker.new, default_insert_pos: :bottom) unless i[top bottom].include?(default_insert_pos) raise ArgumentError, "#{default_insert_pos} is not a valid default_insert_position. Must be one of [:top, :bottom]" end @rankable_column = field @rankable_scope = scope_by @rankable_ranker = ranker @rankable_default_insert_pos = default_insert_pos set_ranked_scope(field) set_ranked_validations(field, @rankable_scope) end |