Class: Filterameter::SortDeclaration
- Inherits:
-
Object
- Object
- Filterameter::SortDeclaration
- Defined in:
- lib/filterameter/sort_declaration.rb
Overview
# Sort Declaration
Class SortDeclaration captures the sort declaration within the controller. A sort declaration is also generated from a FilterDeclaration when it is ‘sortable?`.
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parameter_name ⇒ Object
readonly
Returns the value of attribute parameter_name.
Instance Method Summary collapse
-
#initialize(parameter_name, options) ⇒ SortDeclaration
constructor
A new instance of SortDeclaration.
- #nested? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(parameter_name, options) ⇒ SortDeclaration
Returns a new instance of SortDeclaration.
11 12 13 14 15 16 17 |
# File 'lib/filterameter/sort_declaration.rb', line 11 def initialize(parameter_name, ) @parameter_name = parameter_name.to_s () @name = .fetch(:name, parameter_name).to_s @association = Array.wrap([:association]).presence end |
Instance Attribute Details
#association ⇒ Object (readonly)
Returns the value of attribute association.
9 10 11 |
# File 'lib/filterameter/sort_declaration.rb', line 9 def association @association end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/filterameter/sort_declaration.rb', line 9 def name @name end |
#parameter_name ⇒ Object (readonly)
Returns the value of attribute parameter_name.
9 10 11 |
# File 'lib/filterameter/sort_declaration.rb', line 9 def parameter_name @parameter_name end |
Instance Method Details
#nested? ⇒ Boolean
19 20 21 |
# File 'lib/filterameter/sort_declaration.rb', line 19 def nested? !@association.nil? end |
#to_s ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/filterameter/sort_declaration.rb', line 23 def to_s = {} [:name] = ":#{@name}" if @parameter_name != @name [:association] = @association if nested? (["sort :#{@parameter_name}"] + .map { |k, v| "#{k}: #{v}" }) .join(', ') end |