Class: Ransack::Context
- Inherits:
-
Object
- Object
- Ransack::Context
- Defined in:
- lib/ransack_abbreviator/ransack_extensions/context.rb
Instance Attribute Summary collapse
-
#decoder ⇒ Object
readonly
Returns the value of attribute decoder.
-
#encoder ⇒ Object
readonly
Returns the value of attribute encoder.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#decoder ⇒ Object (readonly)
Returns the value of attribute decoder.
6 7 8 |
# File 'lib/ransack_abbreviator/ransack_extensions/context.rb', line 6 def decoder @decoder end |
#encoder ⇒ Object (readonly)
Returns the value of attribute encoder.
6 7 8 |
# File 'lib/ransack_abbreviator/ransack_extensions/context.rb', line 6 def encoder @encoder end |
Class Method Details
.polymorphic_association_specified?(str) ⇒ Boolean
38 39 40 |
# File 'lib/ransack_abbreviator/ransack_extensions/context.rb', line 38 def self.polymorphic_association_specified?(str) str && str.match(/_of_([^_]+?)_type$/) end |
Instance Method Details
#get_associations_and_attribute(str, klass = @klass, associations = []) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ransack_abbreviator/ransack_extensions/context.rb', line 11 def get_associations_and_attribute(str, klass = @klass, associations = []) attr_name = nil if ransackable_attribute?(str, klass) attr_name = str elsif (segments = str.split(/_/)).size > 1 remainder = [] found_assoc = nil while !found_assoc && remainder.unshift(segments.pop) && segments.size > 0 do assoc, poly_class = unpolymorphize_association(segments.join('_')) if found_assoc = get_association(assoc, klass) attr_name = remainder.join('_') associations, attr_name = get_associations_and_attribute(attr_name, poly_class || found_assoc.klass, associations << found_assoc) end end end [associations, attr_name] end |