lib/accepts_nested_ids.rb
def map_nested_id_associations(*args)
        args.inject([]) do |array, arg|
          if arg.is_a?(Hash)
            attr        = arg.keys.first
            ids_attr    = get_ids_attr(attr)
            class_name  = arg[attr]
          else
            attr        = arg
            ids_attr    = get_ids_attr(attr)
            class_name  = arg.to_s.classify
          end
          array << NestedIdAssociation.new(attr, ids_attr, class_name)
          array
        end
      end
# Map module args into array of NestedIdAssociation objects with supporting properties
#
# @example
#   accepts_nested_ids_for :documents, included_users: "User"
#   =>
#   [
#     { attr: :documents:, ids_attr: "document_ids", class_name: "Document"},
#     { attr: :included_users, ids_attr: "included_user_ids", class_name: "User" }
#   ]
#
# @param args [Array]
# @return [Array]
Map module args into array of NestedIdAssociation objects with supporting properties
Map module args into array of NestedIdAssociation objects with supporting properties
def map_nested_id_associations(*args)
        args.inject([]) do |array, arg|
          if arg.is_a?(Hash)
            attr        = arg.keys.first
            ids_attr    = get_ids_attr(attr)
            class_name  = arg[attr]
          else
            attr        = arg
            ids_attr    = get_ids_attr(attr)
            class_name  = arg.to_s.classify
          end
          array << NestedIdAssociation.new(attr, ids_attr, class_name)
          array
        end
      end
def map_nested_id_associations ( * args ) args . inject ( [ ] ) do | array , arg | if arg . is_a? ( Hash ) attr = arg . keys . first ids_attr = get_ids_attr ( attr ) class_name = arg [ attr ] else attr = arg ids_attr = get_ids_attr ( attr ) class_name = arg . to_s . classify end array << NestedIdAssociation . new ( attr , ids_attr , class_name ) array end end
Map module args into array of NestedIdAssociation objects with supporting properties
Map module args into array of NestedIdAssociation objects with supporting properties
None
Array
args
None
example
accepts_nested_ids_for :documents, included_users: "User" => [ { attr: :documents:, ids_attr: "document_ids", class_name: "Document"}, { attr: :included_users, ids_attr: "included_user_ids", class_name: "User" } ]
accepts_nested_ids_for : documents included_users : " User " = > [ { attr : : documents : ids_attr : " document_ids " class_name : " Document " } { attr : : included_users ids_attr : " included_user_ids " class_name : " User " } ]