Method: ActiveModel::AttributeFilters::ClassMethods#filter_attribute

Defined in:
lib/attribute-filters/dsl_sets.rb

#filter_attributeHash{String => AttributeSet<Symbol>} #filter_attribute(attribute_name) ⇒ AttributeSet<Symbol> #filter_attribute(attribute_name, *set_names) ⇒ nil #filter_attribute(associations) ⇒ nil #filter_attribute(associations, *set_names) ⇒ nil Also known as: the_attribute, attribute_to_set, filtered_attribute, filtered_attributes, filters_attribute, filters_attributes, its_attribute, has_attribute, has_the_attribute, has_filtered_attribute, has_filtered_attributes

Overloads:

  • #filter_attributeHash{String => AttributeSet<Symbol>}

    Gets all the defined attribute sets.

    Returns:

    • (Hash{String => AttributeSet<Symbol>})

      the collection of attribute set names indexed by attribute names

  • #filter_attribute(attribute_name) ⇒ AttributeSet<Symbol>

    Gets the names of all attribute sets that an attribute of the given name belongs to.

    Parameters:

    • attribute_name (Symbol, String)

      attribute name

    Returns:

    • (AttributeSet<Symbol>)

      the collection of attribute set names

  • #filter_attribute(attribute_name, *set_names) ⇒ nil

    Adds an attribute of the given name to attribute sets.

    Parameters:

    • attribute_name (Symbol, String)

      name of an attribute

    • set_names (Array<Symbol,String>)

      names of attribute sets to add the attribute to

    Returns:

    • (nil)
  • #filter_attribute(associations) ⇒ nil

    Adds an attribute of the given name to attribute sets.

    Parameters:

    • associations (Hash{Symbol,String => Array<Symbol,String>})

      hash containing attribute names and arrays of attribute set names

    Returns:

    • (nil)
  • #filter_attribute(associations, *set_names) ⇒ nil

    Creates one new set of attributes of the given names.

    Parameters:

    • associations (Hash{Symbol,String => String,Array<Symbol,String>})

      hash containing attribute names and arrays of attribute set name

    • set_names (Array<Symbol,String>)

      names of additional sets to assign attributes to

    Returns:

    • (nil)


365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/attribute-filters/dsl_sets.rb', line 365

def filter_attribute(*args)
  AFHelpers.check_wanted_methods(self)
  case args.size
  when 0
    attributes_to_sets
  when 1
    first_arg = args.first
    if first_arg.is_a?(Hash)
      first_arg.each_pair { |k, v| filter_attribute(k, v) }
      nil
    else
      r = __attributes_to_sets_map[first_arg.to_s]
      r.frozen? ? r : r.deep_dup
    end
  else
    first_arg = args.shift
    if first_arg.is_a?(Hash)
      first_arg.each_pair do |k, v|
        filter_attribute(k, v, args)
      end
    else
      first_arg = first_arg.to_s
      args.flatten.compact.each do |set_name|
        if set_name.is_a?(Hash) # annotation
          set_name.each_pair do |set_name_b, a_defs|
            af_attribute_set(set_name_b, first_arg => a_defs)
          end
        else
          af_attribute_set(set_name, first_arg)
        end
      end
    end
    nil
  end
end