virtus_convert 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/virtus_convert.rb +2 -2
- data/lib/virtus_convert/array.rb +3 -2
- data/lib/virtus_convert/converter.rb +4 -4
- data/lib/virtus_convert/hash.rb +3 -2
- data/lib/virtus_convert/object.rb +2 -2
- data/lib/virtus_convert/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d169c58fab7f68eae28103ae48b7fb05eda7b03
|
4
|
+
data.tar.gz: 48712121c22430ffedc5cfcde4410b2b997b30a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc1bca115e7b6f41ff027ab4a5302d22604952d189099ea4b719ace54f5fe1fcd666654d4b53714dedb4734830db26225962ea646e9da6ade25109ae479c99a7
|
7
|
+
data.tar.gz: aad4c766318ea22dd8dae7accdf570ae0163d7f29fc61de4b05b13db794b8e08f84b8a474896506e27900f8f06a9457e345521ccb156e41d1f7267cce77d2816
|
data/lib/virtus_convert.rb
CHANGED
data/lib/virtus_convert/array.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module VirtusConvert
|
2
2
|
class Array
|
3
|
-
def initialize(array = [])
|
4
|
-
|
3
|
+
def initialize(array = [], options = {})
|
4
|
+
array.reject!{|item| item.nil?} if options[:reject_nils]
|
5
|
+
@array = array.map{|item| VirtusConvert.new(item, options)}
|
5
6
|
end
|
6
7
|
|
7
8
|
def to_hash
|
@@ -6,10 +6,10 @@ module VirtusConvert
|
|
6
6
|
|
7
7
|
class Converter
|
8
8
|
|
9
|
-
def initialize(unknown)
|
10
|
-
@root = VirtusConvert::Hash.new(unknown) if unknown.is_a? ::Hash
|
11
|
-
@root ||= VirtusConvert::Array.new(unknown) if unknown.is_a? ::Array
|
12
|
-
@root ||= VirtusConvert::Object.new(unknown)
|
9
|
+
def initialize(unknown, options = {})
|
10
|
+
@root = VirtusConvert::Hash.new(unknown, options) if unknown.is_a? ::Hash
|
11
|
+
@root ||= VirtusConvert::Array.new(unknown, options) if unknown.is_a? ::Array
|
12
|
+
@root ||= VirtusConvert::Object.new(unknown, options)
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_hash
|
data/lib/virtus_convert/hash.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module VirtusConvert
|
2
2
|
class Hash
|
3
|
-
def initialize(hash = {})
|
4
|
-
|
3
|
+
def initialize(hash = {}, options = {})
|
4
|
+
hash.reject!{|k, v| v.nil?} if options[:reject_nils]
|
5
|
+
@hash = hash.inject({}){|h,(k,v)| h[k] = VirtusConvert.new(v, options); h}
|
5
6
|
end
|
6
7
|
|
7
8
|
def to_hash
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module VirtusConvert
|
2
2
|
class Object
|
3
|
-
def initialize(object)
|
3
|
+
def initialize(object, options = {})
|
4
4
|
if object.respond_to?(:attributes)
|
5
|
-
@object = VirtusConvert.new(object.attributes)
|
5
|
+
@object = VirtusConvert.new(object.attributes, options)
|
6
6
|
else
|
7
7
|
@object = object
|
8
8
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: virtus_convert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Guest
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|