mingo 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a82ed0600a4ee83980d691f776c4f8b4ba30cc4
4
- data.tar.gz: 25db64f34e268e97617dffffdd8d76bd70487044
3
+ metadata.gz: 0036923d82b82e64e030d6300cec95f78054ec51
4
+ data.tar.gz: 86d47c3cf07f078abbb2f662cfefb27b478f0fa9
5
5
  SHA512:
6
- metadata.gz: 8399c8e92978a32037da38aa2ce922d3b738694128416ff93efb6058eb0b8e8d82e000315b8a9bb6e0bcaf1e2836296a9f9744270f928f6fa53379e9055ceb06
7
- data.tar.gz: 76e205c01d84dd127078f0d934ec922ea8913fc73de8a8caf88da5dd111853b0f95eb62c74e09a229f5e473be30a7affb0aa1fe107acfcf575f5e75c0283ede7
6
+ metadata.gz: 7d00d70b34d4807748b7863a55c7ae244bfc68275ab51c6e0c333bd704b3d5c010235866dd0141839c860202eeb76466bd8668c9dd0b5f54f67f7f08efca7135
7
+ data.tar.gz: e051ec40e4d63b542f86bf892d6b9cc8fbdf1bf13841f2a939b8bdf9894566c566c43d52c96ecb3f06b24b9a7c4cd0d97f06ae3075712bfd4205ae1836a75c7c
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Mislav Marohnić
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -12,9 +12,10 @@ BSON::ObjectId.class_eval do
12
12
  end
13
13
  end
14
14
 
15
- class Mingo < Hash
15
+ class Mingo
16
16
  include ActiveModel::Conversion
17
17
  extend ActiveModel::Translation
18
+ extend ActiveModel::Naming
18
19
 
19
20
  autoload :Properties, 'mingo/properties'
20
21
  autoload :Cursor, 'mingo/cursor'
@@ -52,7 +53,7 @@ class Mingo < Hash
52
53
  end
53
54
 
54
55
  def ==(other)
55
- other.is_a?(self.class) and other.id == self.id
56
+ other.is_a?(Mingo) && other.id == self.id
56
57
  end
57
58
 
58
59
  def cache_key
@@ -40,6 +40,7 @@ class Mingo
40
40
  def reload
41
41
  doc = self.class.first(id, :transformer => nil)
42
42
  replace doc
43
+ self
43
44
  end
44
45
 
45
46
  def destroy
@@ -41,6 +41,11 @@ class Mingo
41
41
  end
42
42
  end
43
43
 
44
+ def initialize(*)
45
+ super
46
+ @_data = {}
47
+ end
48
+
44
49
  def inspect
45
50
  str = "<##{self.class.to_s}"
46
51
  str << self.class.properties.map { |p| " #{p}=#{self.send(p).inspect}" }.join('')
@@ -48,19 +53,25 @@ class Mingo
48
53
  end
49
54
 
50
55
  def [](field, &block)
51
- super(field.to_s, &block)
56
+ @_data.send(:[], field, &block)
52
57
  end
53
58
 
54
59
  def []=(field, value)
55
- super(field.to_s, value)
60
+ @_data[field] = value
56
61
  end
57
62
 
58
63
  def to_hash
59
- Hash.new.replace(self)
64
+ @_data.dup
60
65
  end
61
66
 
62
- # keys are already strings
63
- def stringify_keys!() self end
64
- def stringify_keys() stringify_keys!.dup end
67
+ def merge!(other)
68
+ @_data.merge!(other.to_hash)
69
+ self
70
+ end
71
+
72
+ def replace(other)
73
+ @_data.replace(other.to_hash)
74
+ self
75
+ end
65
76
  end
66
77
  end
@@ -9,13 +9,13 @@ class Mingo
9
9
  end
10
10
 
11
11
  def updated_at
12
- self[:updated_at] || created_at
12
+ self['updated_at'] || created_at
13
13
  end
14
14
 
15
15
  protected
16
16
 
17
17
  def touch_updated_timestamp
18
- self[:updated_at] = Time.now if changed?
18
+ self['updated_at'] = Time.now if changed?
19
19
  end
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mingo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mislav Marohnić
@@ -36,6 +36,7 @@ executables: []
36
36
  extensions: []
37
37
  extra_rdoc_files: []
38
38
  files:
39
+ - LICENSE
39
40
  - Rakefile
40
41
  - lib/mingo.rb
41
42
  - lib/mingo/callbacks.rb
@@ -49,7 +50,8 @@ files:
49
50
  - lib/mingo/timestamps.rb
50
51
  - spec/mingo_spec.rb
51
52
  homepage: http://github.com/mislav/mingo
52
- licenses: []
53
+ licenses:
54
+ - MIT
53
55
  metadata: {}
54
56
  post_install_message:
55
57
  rdoc_options: []