memorydb 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/memorydb/base.rb +2 -1
  2. data/lib/memorydb/db.rb +4 -8
  3. metadata +2 -34
data/lib/memorydb/base.rb CHANGED
@@ -40,7 +40,8 @@ module MemoryDb
40
40
  def model_or_hash_as_attrs(model_or_hash)
41
41
  if model_or_hash
42
42
  if model_or_hash.is_a?(Hash)
43
- model_or_hash
43
+ verify_attributes!(model_or_hash)
44
+ model_klass.new(model_or_hash).attributes
44
45
  elsif model_or_hash.is_a?(model_klass)
45
46
  model_or_hash.attributes
46
47
  else
data/lib/memorydb/db.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'multi_json'
2
1
  require 'memorydb/base'
3
2
  require 'memorydb/cursor'
4
3
 
@@ -33,10 +32,9 @@ module MemoryDb
33
32
  @primary_key = options[:primary_key]
34
33
  end
35
34
 
36
- def create!(attrs={})
35
+ def create!(given={})
37
36
  _id = id
38
- attrs = model_or_hash_as_attrs(attrs)
39
- verify_attributes!(attrs)
37
+ attrs = model_or_hash_as_attrs(given)
40
38
  attributes = attrs.merge(primary_key => _id)
41
39
  store!(_id, attributes)
42
40
  model_klass.new(attributes)
@@ -189,13 +187,11 @@ module MemoryDb
189
187
  end
190
188
 
191
189
  def all_models
192
- @store.values.map do |raw_record|
193
- model_klass.new(MultiJson.load(raw_record)).attributes
194
- end
190
+ @store.values
195
191
  end
196
192
 
197
193
  def store!(id, attributes)
198
- @store[id] = MultiJson.dump(attributes)
194
+ @store[id] = attributes
199
195
  end
200
196
 
201
197
  def remove_model!(model)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memorydb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,40 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-30 00:00:00.000000000 Z
12
+ date: 2013-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: multi_json
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 1.7.6
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 1.7.6
30
- - !ruby/object:Gem::Dependency
31
- name: multi_json
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: 1.5.0
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 1.5.0
46
14
  - !ruby/object:Gem::Dependency
47
15
  name: rake
48
16
  requirement: !ruby/object:Gem::Requirement