domain_model 0.1.0 → 0.1.1
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.
- data/README.md +9 -27
- data/lib/domain_model.rb +2 -1
- data/lib/domain_model/version.rb +1 -1
- data/spec/model_spec.rb +11 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,35 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# Sanctum
|
2
2
|
|
3
|
-
|
3
|
+
Sanctum provides a minimal set of utilties for declaring object attributes with optional type and validation support.
|
4
4
|
|
5
|
-
|
5
|
+
Features
|
6
6
|
|
7
|
-
|
7
|
+
* Sanctum produces objects that look like totally normal ruby objects, not specialized "framework" objects (like descendents of ActiveRecord::Base or ActiveModel::Base)
|
8
|
+
* Sanctum allows you to declare the type of
|
8
9
|
|
9
|
-
|
10
|
+
## Background
|
10
11
|
|
11
|
-
And then execute:
|
12
12
|
|
13
|
-
|
13
|
+
## Development
|
14
14
|
|
15
|
-
|
15
|
+
To run the tests (assuming you have already run `gem install bundler`):
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
## Tests
|
20
|
-
|
21
|
-
Run the tests:
|
22
|
-
|
23
|
-
rake test
|
24
|
-
|
25
|
-
## Usage
|
26
|
-
|
27
|
-
TODO: Write usage instructions here
|
28
|
-
|
29
|
-
## Contributing
|
30
|
-
|
31
|
-
1. Fork it
|
32
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
-
5. Create new Pull Request
|
17
|
+
bundle install && bundle exec rake
|
data/lib/domain_model.rb
CHANGED
@@ -98,13 +98,14 @@ module DomainModel
|
|
98
98
|
def deserialize(type, primitive)
|
99
99
|
case
|
100
100
|
when type <= DomainModel
|
101
|
+
primitive ||= {}
|
101
102
|
primitive.each do |k, v|
|
102
103
|
field = type.fields.find { |f| f.name.to_s == k.to_s }
|
103
104
|
|
104
105
|
next unless field && field.monotype
|
105
106
|
|
106
107
|
if field.collection?
|
107
|
-
primitive[k] = v.map { |e| deserialize(field.monotype, e) }
|
108
|
+
primitive[k] = (v || []).map { |e| deserialize(field.monotype, e) }
|
108
109
|
else
|
109
110
|
primitive[k] = deserialize(field.monotype, v)
|
110
111
|
end
|
data/lib/domain_model/version.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -152,7 +152,7 @@ describe DomainModel do
|
|
152
152
|
client = Client.new("name" => "Rafer")
|
153
153
|
expect(client.name).to eq("Rafer")
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
it "accepts collection fields" do
|
157
157
|
client = Client.new(:children => ["child"])
|
158
158
|
expect(client.children).to eq(["child"])
|
@@ -441,6 +441,16 @@ describe DomainModel do
|
|
441
441
|
|
442
442
|
expect(children).to eq([Child.new(:field => "VALUE")])
|
443
443
|
end
|
444
|
+
|
445
|
+
it "correctly deserializes a nil child" do
|
446
|
+
define { field :child, :type => Child }
|
447
|
+
expect { Client.from_primitive(:child => nil) }.not_to raise_error
|
448
|
+
end
|
449
|
+
|
450
|
+
it "correctly deserializes a nil child collection" do
|
451
|
+
define { field :children, :type => Child, :collection => true }
|
452
|
+
expect { Client.from_primitive(:children => nil) }.not_to raise_error
|
453
|
+
end
|
444
454
|
end
|
445
455
|
|
446
456
|
def define(&block)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: domain_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|