mm_no_empties 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module MmNoEmpties
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/mm_no_empties.rb CHANGED
@@ -5,47 +5,45 @@ require 'mongo_mapper/plugins/keys/key'
5
5
  module MmNoEmpties
6
6
 
7
7
  extend ActiveSupport::Concern
8
-
9
- module InstanceMethods
10
-
11
- def attributes(include_all = false)
12
8
 
13
- HashWithIndifferentAccess.new.tap do |attrs|
14
- persistable_keys = if include_all
15
- keys
16
- else
17
- keys.select do |name, key|
18
- val = self[key.name]
19
- #key.type == ObjectId or # this is in the original :attributes implementation, but is seems safe to remove it as 'belongs_to: nil' if it's missing
20
- not (val.nil? or (val.respond_to?(:empty?) and val.empty?))
21
- end
22
- end
23
-
24
- persistable_keys.each do |name, key|
25
- value = key.set(self[key.name])
26
- attrs[name] = value
9
+ def attributes(include_all = false)
10
+
11
+ HashWithIndifferentAccess.new.tap do |attrs|
12
+ persistable_keys = if include_all
13
+ keys
14
+ else
15
+ keys.select do |name, key|
16
+ val = self[key.name]
17
+ #key.type == ObjectId or # this is in the original :attributes implementation, but is seems safe to remove it as 'belongs_to: nil' if it's missing
18
+ not (val.nil? or (val.respond_to?(:empty?) and val.empty?))
27
19
  end
20
+ end
21
+
22
+ persistable_keys.each do |name, key|
23
+ value = key.set(self[key.name])
24
+ attrs[name] = value
25
+ end
28
26
 
29
- embedded_associations.each do |association|
30
- if documents = instance_variable_get(association.ivar)
31
-
32
- val = if association.is_a?(MongoMapper::Plugins::Associations::OneAssociation)
33
- documents.to_mongo
34
- else
35
- documents.map { |document| document.to_mongo }
36
- end
37
-
38
- if include_all
39
- attrs[association.name] = val
40
- else
41
- attrs[association.name] = val unless val.nil? or (val.is_a?(Array) and val.empty?)
42
- end
27
+ embedded_associations.each do |association|
28
+ if documents = instance_variable_get(association.ivar)
29
+
30
+ val = if association.is_a?(MongoMapper::Plugins::Associations::OneAssociation)
31
+ documents.to_mongo
32
+ else
33
+ documents.map { |document| document.to_mongo }
34
+ end
43
35
 
36
+ if include_all
37
+ attrs[association.name] = val
38
+ else
39
+ attrs[association.name] = val unless val.nil? or (val.is_a?(Array) and val.empty?)
44
40
  end
41
+
45
42
  end
46
43
  end
47
44
  end
48
- alias :to_mongo :attributes
49
45
  end
46
+ alias :to_mongo :attributes
47
+
50
48
 
51
49
  end
@@ -16,8 +16,8 @@ Gem::Specification.new do |gem|
16
16
  gem.version = MmNoEmpties::VERSION
17
17
  gem.license = 'MIT'
18
18
 
19
- gem.add_development_dependency "rspec", "~> 2.7"
20
- gem.add_development_dependency "bson_ext", "~> 1.5.0"
21
- gem.add_dependency "mongo_mapper", "~> 0.10.1"
19
+ gem.add_development_dependency "rspec", ">= 2.7"
20
+ gem.add_development_dependency "bson_ext", ">= 1.5.0"
21
+ gem.add_dependency "mongo_mapper", ">= 0.10.1"
22
22
 
23
23
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jonathan Chambers
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-01-01 00:00:00 +00:00
17
+ date: 2012-03-03 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -23,7 +23,7 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ~>
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 2
@@ -37,7 +37,7 @@ dependencies:
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
39
39
  requirements:
40
- - - ~>
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  segments:
43
43
  - 1
@@ -52,7 +52,7 @@ dependencies:
52
52
  requirement: &id003 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
- - - ~>
55
+ - - ">="
56
56
  - !ruby/object:Gem::Version
57
57
  segments:
58
58
  - 0