primalize 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/primalize/single.rb +44 -2
- data/lib/primalize/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51c3c4afd61ecadabd34115a60a030766d9b747a24451c8779eb4fea7178d9fa
|
4
|
+
data.tar.gz: f3f27c2aa92aa557232c93dabe053a8e32cae44468b78ff43b0cb6d5719d9615
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae6af8099e18bd65b052b0d484df3862bba22dfc890e809adce82be0edb3daa3435804af0109e4b4d7829a8741de215e0817e0e7bbfcdf414be0fac911be3ca7
|
7
|
+
data.tar.gz: 72354d3fa52bd3dfa0704c8237f5e12924fe5ee430171b60902ee86a0f74619782008ecb59c74ebf0ba38ca973dbb0f963ac6e85f391e5b93e07037cdc3cfac7
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Primalize
|
2
2
|
|
3
|
+
[![Join the chat at https://gitter.im/jgaskins/primalize](https://badges.gitter.im/jgaskins/primalize.svg)](https://gitter.im/jgaskins/primalize?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
|
+
|
3
5
|
Primalize lets you de-evolve your objects into primitive values for serialization. The primary use case is to serialize them into JSON, but once it's in its primitive state, it can be converted into other formats such as XML or CSV.
|
4
6
|
|
5
7
|
Primalizers support type checking by letting you specify the types of the resulting properties:
|
data/lib/primalize/single.rb
CHANGED
@@ -81,6 +81,14 @@ module Primalize
|
|
81
81
|
Any.new(types, &coerce)
|
82
82
|
end
|
83
83
|
|
84
|
+
def all *types, &coerce
|
85
|
+
All.new(types, &coerce)
|
86
|
+
end
|
87
|
+
|
88
|
+
def match matcher, &coercion
|
89
|
+
Match.new(matcher, &coercion)
|
90
|
+
end
|
91
|
+
|
84
92
|
def primalize primalizer, &coerce
|
85
93
|
Primalizer.new(primalizer, &coerce)
|
86
94
|
end
|
@@ -292,9 +300,9 @@ module Primalize
|
|
292
300
|
return @coercion.call(hash)
|
293
301
|
end
|
294
302
|
|
295
|
-
if hash.respond_to? :
|
303
|
+
if hash.respond_to? :each_with_object
|
296
304
|
hash.each_with_object({}) do |(key, value), h|
|
297
|
-
|
305
|
+
type = @types[key]
|
298
306
|
|
299
307
|
h[key] = if type.respond_to? :coerce
|
300
308
|
type.coerce(value)
|
@@ -400,5 +408,39 @@ module Primalize
|
|
400
408
|
"any#{@types.empty? ? nil : params}"
|
401
409
|
end
|
402
410
|
end
|
411
|
+
|
412
|
+
class All
|
413
|
+
include Type
|
414
|
+
|
415
|
+
def initialize types, &coercion
|
416
|
+
@types = types
|
417
|
+
@coercion = coercion
|
418
|
+
end
|
419
|
+
|
420
|
+
def === value
|
421
|
+
@types.all? { |type| type === value }
|
422
|
+
end
|
423
|
+
|
424
|
+
def inspect
|
425
|
+
"all(#{@types.map(&:inspect).join(', ')})"
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
class Match
|
430
|
+
include Type
|
431
|
+
|
432
|
+
def initialize matcher, &coercion
|
433
|
+
@matcher = matcher
|
434
|
+
@coercion = coercion
|
435
|
+
end
|
436
|
+
|
437
|
+
def === value
|
438
|
+
@matcher === value
|
439
|
+
end
|
440
|
+
|
441
|
+
def inspect
|
442
|
+
"match(#{@matcher.inspect})"
|
443
|
+
end
|
444
|
+
end
|
403
445
|
end
|
404
446
|
end
|
data/lib/primalize/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: primalize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Gaskins
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|