Sha256: f9ea03400115bf36b4d7decfb329c8b1566abb3837d8ee5cb15e008e656dc7ae

Contents?: true

Size: 1.67 KB

Versions: 14

Compression:

Stored size: 1.67 KB

Contents

# encoding: utf-8
module Mongoid
  module Config

    # Encapsulates logic for setting options.
    module Options

      # Get the defaults or initialize a new empty hash.
      #
      # @example Get the defaults.
      #   options.defaults
      #
      # @return [ Hash ] The default options.
      #
      # @since 2.3.0
      def defaults
        @defaults ||= {}
      end

      # Define a configuration option with a default.
      #
      # @example Define the option.
      #   Options.option(:persist_in_safe_mode, :default => true)
      #
      # @param [ Symbol ] name The name of the configuration option.
      # @param [ Hash ] options Extras for the option.
      #
      # @option options [ Object ] :default The default value.
      #
      # @since 2.0.0.rc.1
      def option(name, options = {})
        defaults[name] = settings[name] = options[:default]

        class_eval <<-RUBY
          def #{name}
            settings[#{name.inspect}]
          end

          def #{name}=(value)
            settings[#{name.inspect}] = value
          end

          def #{name}?
            #{name}
          end
        RUBY
      end

      # Reset the configuration options to the defaults.
      #
      # @example Reset the configuration options.
      #   config.reset
      #
      # @return [ Hash ] The defaults.
      #
      # @since 2.3.0
      def reset
        settings.replace(defaults)
      end

      # Get the settings or initialize a new empty hash.
      #
      # @example Get the settings.
      #   options.settings
      #
      # @return [ Hash ] The setting options.
      #
      # @since 2.3.0
      def settings
        @settings ||= {}
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongoid-4.0.2/lib/mongoid/config/options.rb
mongoid-5.0.0.rc0 lib/mongoid/config/options.rb
mongoid-5.0.0.beta lib/mongoid/config/options.rb
mongoid-4.0.2 lib/mongoid/config/options.rb
mongoid-4.0.1 lib/mongoid/config/options.rb
mongoid-4.0.0 lib/mongoid/config/options.rb
mongoid-4.0.0.rc2 lib/mongoid/config/options.rb
mongoid-4.0.0.rc1 lib/mongoid/config/options.rb
mongoid-4.0.0.beta2 lib/mongoid/config/options.rb
mongoid-4.0.0.beta1 lib/mongoid/config/options.rb
mongoid-4.0.0.alpha2 lib/mongoid/config/options.rb
mongoid-4.0.0.alpha1 lib/mongoid/config/options.rb
sepastian-mongoid-rails4-4.0.1.alpha lib/mongoid/config/options.rb
sepastian-mongoid-rails4-4.0.0.alpha lib/mongoid/config/options.rb