Method: Ransack::Nodes::Condition#build_attribute

Defined in:
lib/ransack/nodes/condition.rb

#build_attribute(name = nil, ransacker_args = []) ⇒ Object

build_attribute

This method was originally called from Nodes::Grouping#new_condition
only, without arguments, without #valid? checking, to build a new
grouping condition.

After refactoring in 235eae3, it is now called from 2 places:

1. Nodes::Condition#attributes=, with +name+ argument passed or +name+
   and +ransacker_args+. Attributes are included only if #valid?.

2. Nodes::Grouping#new_condition without arguments. In this case, the
   #valid? conditional needs to be bypassed, otherwise nothing is
   built. The `name.nil?` conditional below currently does this.

TODO: Add test coverage for this behavior and ensure that `name.nil?`
isn't fixing issue #701 by introducing untested regressions.


149
150
151
152
153
154
155
156
157
# File 'lib/ransack/nodes/condition.rb', line 149

def build_attribute(name = nil, ransacker_args = [])
  Attribute.new(@context, name, ransacker_args).tap do |attribute|
    @context.bind(attribute, attribute.name)
    self.attributes << attribute if name.nil? || attribute.valid?
    if predicate && !negative?
      @context.lock_association(attribute.parent)
    end
  end
end