Sha256: 0c0e0e9cff01aba7d23225fd2f5a1e47377ad6867ef6c05e1c1ddb80a672250d

Contents?: true

Size: 1.29 KB

Versions: 188

Compression:

Stored size: 1.29 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Extensions #:nodoc:
    module Object #:nodoc:

      # This module contains reflection convenience methods.
      module Reflections
        extend ActiveSupport::Concern

        # Get the value for an instance variable or nil if it doesn't exist.
        #
        # @example Get the value for an instance var.
        #   document.ivar("person")
        #
        # @param [ String ] name The name of the variable.
        #
        # @return [ Object, nil ] The value or nil.
        #
        # @since 2.0.0.rc.1
        def ivar(name)
          if instance_variable_defined?("@#{name}")
            return instance_variable_get("@#{name}")
          else
            false
          end
        end

        # Remove the instance variable for the provided name.
        #
        # @example Remove the instance variable
        #   document.remove_ivar("person")
        #
        # @param [ String ] name The name of the variable.
        #
        # @return [ true, false ] If the variable was defined.
        #
        # @since 2.1.0
        def remove_ivar(name)
          if instance_variable_defined?("@#{name}")
            return remove_instance_variable("@#{name}")
          else
            false
          end
        end
      end
    end
  end
end

Version data entries

188 entries across 96 versions & 4 rubygems

Version Path
classiccms-0.6.4 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/extensions/object/reflections.rb
classiccms-0.6.4 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/object/reflections.rb
classiccms-0.6.4 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/extensions/object/reflections.rb
classiccms-0.6.3 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/extensions/object/reflections.rb
classiccms-0.6.3 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/extensions/object/reflections.rb
classiccms-0.6.3 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/object/reflections.rb
classiccms-0.6.2 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/extensions/object/reflections.rb
classiccms-0.6.2 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/object/reflections.rb
classiccms-0.6.2 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/extensions/object/reflections.rb
classiccms-0.6.1 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/extensions/object/reflections.rb
classiccms-0.6.1 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/extensions/object/reflections.rb
classiccms-0.6.1 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/object/reflections.rb
classiccms-0.6.0 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/object/reflections.rb
classiccms-0.6.0 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/extensions/object/reflections.rb
classiccms-0.6.0 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/extensions/object/reflections.rb
classiccms-0.5.17 vendor/bundle/gems/mongoid-2.4.7/lib/mongoid/extensions/object/reflections.rb
classiccms-0.5.17 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/extensions/object/reflections.rb
classiccms-0.5.17 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/extensions/object/reflections.rb
classiccms-0.5.16 vendor/bundle/gems/mongoid-2.4.10/lib/mongoid/extensions/object/reflections.rb
classiccms-0.5.16 vendor/bundle/gems/mongoid-2.4.9/lib/mongoid/extensions/object/reflections.rb