Class: CustomSort::MagicNew
- Inherits:
-
Object
- Object
- CustomSort::MagicNew
- Defined in:
- lib/custom_sort/magic_new.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Enumerable, Relation
Instance Attribute Summary collapse
-
#label ⇒ Object
Returns the value of attribute label.
-
#options ⇒ Object
Returns the value of attribute options.
-
#query_name ⇒ Object
Returns the value of attribute query_name.
-
#recency_key ⇒ Object
Returns the value of attribute recency_key.
-
#recent ⇒ Object
Returns the value of attribute recent.
-
#sort_order ⇒ Object
Returns the value of attribute sort_order.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(query_name:, **options) ⇒ MagicNew
constructor
A new instance of MagicNew.
Constructor Details
#initialize(query_name:, **options) ⇒ MagicNew
Returns a new instance of MagicNew.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/custom_sort/magic_new.rb', line 7 def initialize(query_name:, **) @query_name = query_name @options = @recent = [:recent] == false ? false : true @recency_key = [:recency_key] ? [:recency_key].to_i : 2 @label = [:label] ? [:label] : nil @label = @label.nil? ? CustomSort::LABELS[0].to_s : @label @sort_order = [:sort_order] ? (["asc","desc"].include?([:sort_order].downcase) ? [:sort_order] : "desc") : "desc" end |
Instance Attribute Details
#label ⇒ Object
Returns the value of attribute label.
5 6 7 |
# File 'lib/custom_sort/magic_new.rb', line 5 def label @label end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/custom_sort/magic_new.rb', line 5 def @options end |
#query_name ⇒ Object
Returns the value of attribute query_name.
5 6 7 |
# File 'lib/custom_sort/magic_new.rb', line 5 def query_name @query_name end |
#recency_key ⇒ Object
Returns the value of attribute recency_key.
5 6 7 |
# File 'lib/custom_sort/magic_new.rb', line 5 def recency_key @recency_key end |
#recent ⇒ Object
Returns the value of attribute recent.
5 6 7 |
# File 'lib/custom_sort/magic_new.rb', line 5 def recent @recent end |
#sort_order ⇒ Object
Returns the value of attribute sort_order.
5 6 7 |
# File 'lib/custom_sort/magic_new.rb', line 5 def sort_order @sort_order end |
Class Method Details
.validate_period(period, permit) ⇒ Object
20 21 22 23 |
# File 'lib/custom_sort/magic_new.rb', line 20 def self.validate_period(period, permit) permitted_periods = ((permit || CustomSort::FIELDS).map(&:to_sym) & CustomSort::FIELDS).map(&:to_s) raise ArgumentError, "Unpermitted period" unless permitted_periods.include?(period.to_s) end |