structish 0.2.4 → 0.3.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
  SHA256:
3
- metadata.gz: fe83835231060abe23b9427547d10a67fb5f6c5575f1f0ba3650346902dd5385
4
- data.tar.gz: 9fdb570ed7d576fea0b453b1f3c81c08285c75493816e8dc689e8949b4b6ec4c
3
+ metadata.gz: b6d2ba1a7e8fe1d6239b90627d5be7a5ffabae2ec8ed55f075d6794d5bcc387c
4
+ data.tar.gz: 11bcd0b789e9cf61dea899a3d2eb397e36eee39474054da8580ea4fe1c19a261
5
5
  SHA512:
6
- metadata.gz: 2877855214b7f57d302f3c8c3fd6f4594b49e35077c00a48108c948f6ba2b0be0ad40e332a6766978bf511c6a3bb71c58969e762506ed7dd31f7c015de9c5007
7
- data.tar.gz: 4076538cb93f7fe0aeaf39a94f84da386023a40060a936bd13cdbf75848580e94ecc6925f2d1f66430658d50556e7b4e3888de08d43b57097fd45c9ecc5e715d
6
+ metadata.gz: c8445eb56faec25e23b09ab4ad2040b3906f313b3e948f27554ba209a200f1e15de6e4fe7a6d32ca5ba2aed0adbaa7a395263ea4a50c964125e4d85b6273d0bb
7
+ data.tar.gz: 16abf2097b0755ad04fd0783cf9a420cd384cfe82ec7336c182952cc5a272c047e3546923a6ceac2878f470c9ccbf2e4a96d001e9c304f514e467730935e5d82
@@ -6,7 +6,11 @@ module Structish
6
6
  def initialize(constructor)
7
7
  raise(ArgumentError, "Only array-like objects can be used as constructors for Structish::Array") unless constructor.class <= ::Array
8
8
  validate_structish(constructor)
9
- super(constructor)
9
+ if self.class.compact?
10
+ super(constructor.compact)
11
+ else
12
+ super(constructor)
13
+ end
10
14
  end
11
15
 
12
16
  def <<(entry)
@@ -9,6 +9,7 @@ module Structish
9
9
  constructor = self.class.symbolize? ? raw_constructor.symbolize_keys : raw_constructor
10
10
  hash = constructor.to_h
11
11
  validate_structish(hash)
12
+ hash = hash.compact if self.class.compact?
12
13
  super()
13
14
  update(hash)
14
15
  self.default = hash.default if hash.default
@@ -183,6 +183,14 @@ module Structish
183
183
 
184
184
  module ClassMethods
185
185
 
186
+ def compact(do_compact)
187
+ @compact = do_compact
188
+ end
189
+
190
+ def compact?
191
+ @compact
192
+ end
193
+
186
194
  def attribute_keys
187
195
  attributes.map { |attribute| attribute[:key] }
188
196
  end
@@ -1,3 +1,3 @@
1
1
  module Structish
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: structish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Blakemore
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-08 00:00:00.000000000 Z
11
+ date: 2021-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport