Sha256: 1396a0dfc725018f9ccf648df85c484c696f84679441f4a7f796a805d8582906

Contents?: true

Size: 1001 Bytes

Versions: 20

Compression:

Stored size: 1001 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Extensions #:nodoc:
    module Hash #:nodoc:
      module Accessors #:nodoc:

        # Remove a set of attributes from a hash. If the attributes are
        # contained in an array it will remove it from the array, otherwise it
        # will delete the child attribute completely.
        def remove(key, attrs)
          elements = self[key]
          if elements
            key.singular? ? self[key] = nil : elements.delete(attrs)
          end
        end

        # Inserts new attributes into the hash. If the elements are present in
        # the hash it will update them, otherwise it will add the new
        # attributes into the hash as either a child hash or child array of
        # hashes.
        def insert(key, attrs)
          elements = self[key]
          if elements
            elements.update(attrs)
          else
            self[key] = key.singular? ? attrs : [attrs]
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mongoid-1.0.6 lib/mongoid/extensions/hash/accessors.rb
mongoid-1.0.5 lib/mongoid/extensions/hash/accessors.rb
mongoid-1.0.4 lib/mongoid/extensions/hash/accessors.rb
mongoid-1.0.3 lib/mongoid/extensions/hash/accessors.rb
mongoid-1.0.2 lib/mongoid/extensions/hash/accessors.rb
mongoid-1.0.1 lib/mongoid/extensions/hash/accessors.rb
mongoid-1.0.0 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.12.0 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.11.9 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.11.8 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.11.7 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.11.6 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.11.5 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.11.4 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.11.3 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.11.2 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.11.1 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.11.0 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.10.6 lib/mongoid/extensions/hash/accessors.rb
mongoid-0.10.5 lib/mongoid/extensions/hash/accessors.rb