mongoid 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,13 +40,14 @@ module Mongoid #:nodoc
40
40
  option :binding_defaults, :default => { :binding => false, :continue => true }
41
41
  option :embedded_object_id, :default => true
42
42
  option :include_root_in_json, :default => false
43
+ option :max_retries_on_connection_failure, :default => 0
43
44
  option :parameterize_keys, :default => true
44
45
  option :persist_in_safe_mode, :default => false
45
46
  option :preload_models, :default => true
46
47
  option :raise_not_found_error, :default => true
47
48
  option :skip_version_check, :default => false
48
49
  option :time_zone, :default => nil
49
- option :max_retries_on_connection_failure, :default => 0
50
+ option :use_utc, :default => false
50
51
 
51
52
  # Adds a new I18n locale file to the load path.
52
53
  #
@@ -114,6 +115,23 @@ module Mongoid #:nodoc
114
115
  configure_extras(options["databases"])
115
116
  end
116
117
 
118
+ # Load the settings from a compliant mongoid.yml file. This can be used for
119
+ # easy setup with frameworks other than Rails.
120
+ #
121
+ # @example Configure Mongoid.
122
+ # Mongoid.load!("/path/to/mongoid.yml")
123
+ #
124
+ # @param [ String ] path The path to the file.
125
+ #
126
+ # @since 2.0.1
127
+ def load!(path)
128
+ environment = defined?(Rails) ? Rails.env : ENV["RACK_ENV"]
129
+ settings = YAML.load(ERB.new(File.new(path).read).result)[environment]
130
+ if settings.present?
131
+ from_hash(settings)
132
+ end
133
+ end
134
+
117
135
  # Returns the logger, or defaults to Rails logger or stdout logger.
118
136
  #
119
137
  # @example Get the logger.
@@ -259,30 +277,6 @@ module Mongoid #:nodoc
259
277
  @slaves
260
278
  end
261
279
 
262
- # Sets whether the times returned from the database are in UTC or local time.
263
- # If you omit this setting, then times will be returned in
264
- # the local time zone.
265
- #
266
- # @example Set the use of UTC.
267
- # config.use_utc = true
268
- #
269
- # @param [ true, false ] value Whether to use UTC or not.
270
- #
271
- # @return [ true, false ] Are we using UTC?
272
- def use_utc=(value)
273
- @use_utc = value || false
274
- end
275
-
276
- # Returns whether times are return from the database in UTC. If
277
- # this setting is false, then times will be returned in the local time zone.
278
- #
279
- # @example Are we using UTC?
280
- # config.use_utc
281
- #
282
- # @return [ true, false ] True if UTC, false if not.
283
- attr_reader :use_utc
284
- alias :use_utc? :use_utc
285
-
286
280
  protected
287
281
 
288
282
  # Check if the database is valid and the correct version.
@@ -35,7 +35,6 @@ module Mongoid #:nodoc
35
35
  def field(name, options = {})
36
36
  access = name.to_s
37
37
  set_field(access, options)
38
- attr_protected name if options[:accessible] == false
39
38
  end
40
39
 
41
40
  # Return the fields for this class.
@@ -120,7 +119,11 @@ module Mongoid #:nodoc
120
119
  # @param [ Hash ] options The options.
121
120
  def create_accessors(name, meth, options = {})
122
121
  generated_field_methods.module_eval do
123
- define_method(meth) { read_attribute(name) }
122
+ if [ Time, DateTime ].include?(options[:type])
123
+ define_method(meth) { Time.get(read_attribute(name)) }
124
+ else
125
+ define_method(meth) { read_attribute(name) }
126
+ end
124
127
  define_method("#{meth}=") { |value| write_attribute(name, value) }
125
128
  define_method("#{meth}?") do
126
129
  attr = read_attribute(name)
@@ -112,13 +112,10 @@ module Mongoid # :nodoc:
112
112
  # attrs: The single document attributes to process.
113
113
  def process(attrs)
114
114
  return if reject?(attrs)
115
- if attrs[:id] or attrs['id'] or attrs['_id']
116
- id = attrs[:id] || attrs['id'] || attrs['_id']
115
+ if id = attrs[:id] || attrs["id"] || attrs["_id"]
117
116
  document = existing.find(convert_id(id))
118
117
  destroyable?(attrs) ? document.destroy : document.update_attributes(attrs)
119
118
  else
120
- # @todo: Durran: Tell the push not to save the base and call it
121
- # after all processing is done. This is related to #581.
122
119
  existing.push(metadata.klass.new(attrs)) unless destroyable?(attrs)
123
120
  end
124
121
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.0.0"
3
+ VERSION = "2.0.1"
4
4
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 0
8
- - 0
9
- version: 2.0.0
8
+ - 1
9
+ version: 2.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Durran Jordan
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-30 00:00:00 +02:00
17
+ date: 2011-04-06 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -70,8 +70,8 @@ dependencies:
70
70
  - !ruby/object:Gem::Version
71
71
  segments:
72
72
  - 1
73
- - 2
74
- version: "1.2"
73
+ - 3
74
+ version: "1.3"
75
75
  type: :runtime
76
76
  prerelease: false
77
77
  version_requirements: *id004
@@ -84,8 +84,8 @@ dependencies:
84
84
  - !ruby/object:Gem::Version
85
85
  segments:
86
86
  - 1
87
- - 2
88
- version: "1.2"
87
+ - 3
88
+ version: "1.3"
89
89
  type: :development
90
90
  prerelease: false
91
91
  version_requirements: *id005
@@ -379,7 +379,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
379
379
  requirements:
380
380
  - - ">="
381
381
  - !ruby/object:Gem::Version
382
- hash: 2548695650621036943
382
+ hash: -858318852006999862
383
383
  segments:
384
384
  - 0
385
385
  version: "0"