Class: NextPage::Sort::NameEvaluator
- Inherits:
-
Object
- Object
- NextPage::Sort::NameEvaluator
- Defined in:
- lib/next_page/sort/name_evaluator.rb
Overview
Name Evaluator
Determines if a name represents an attribute or a scope, provides mapping if the scope requires a prefix or suffix. Scope is checked first, allowing it to override an attribute of the same name. For scopes, method directional_scope? checks to see if the scope is a class method that accepts one parameter; if so, then the scope will be invoked with the direction.
Instance Attribute Summary collapse
-
#scope_name ⇒ Object
readonly
Returns the value of attribute scope_name.
Instance Method Summary collapse
-
#directional_scope? ⇒ Boolean
true when scope is class method with one parameter.
-
#initialize(model, name) ⇒ NameEvaluator
constructor
A new instance of NameEvaluator.
- #scope? ⇒ Boolean
- #valid_attribute_name? ⇒ Boolean
Constructor Details
#initialize(model, name) ⇒ NameEvaluator
Returns a new instance of NameEvaluator.
14 15 16 17 18 |
# File 'lib/next_page/sort/name_evaluator.rb', line 14 def initialize(model, name) @model = model @name = name.to_s evaluate_for_scope end |
Instance Attribute Details
#scope_name ⇒ Object (readonly)
Returns the value of attribute scope_name.
12 13 14 |
# File 'lib/next_page/sort/name_evaluator.rb', line 12 def scope_name @scope_name end |
Instance Method Details
#directional_scope? ⇒ Boolean
true when scope is class method with one parameter
25 26 27 28 29 |
# File 'lib/next_page/sort/name_evaluator.rb', line 25 def directional_scope? return false unless scope? @model.method(@scope_name).arity == 1 end |
#scope? ⇒ Boolean
20 21 22 |
# File 'lib/next_page/sort/name_evaluator.rb', line 20 def scope? @scope_name.present? end |
#valid_attribute_name? ⇒ Boolean
31 32 33 |
# File 'lib/next_page/sort/name_evaluator.rb', line 31 def valid_attribute_name? @model.attribute_names.include?(@name) end |