portrayal 0.3.1 → 0.4.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: 577a51dc874a79a5cb7aece4157c2d802005f3fa9c3daba4b807db522c7cd7ae
4
- data.tar.gz: b30f1ea6a9438ba5b4574a68935602fce1dd0a447d15dce4227d0a67a10b2e87
3
+ metadata.gz: 44f125ec13de164e28a515a3a4cbdfa98047d645aae03bf818cc184983ecb679
4
+ data.tar.gz: fab0eb7aa3fad16c833d547a2d405fdcbc34aa2160633e60ff4ad43420135c49
5
5
  SHA512:
6
- metadata.gz: a02d197cb3c56e88afcda74a58d5d7034ef4739de707380c05b7a1a76c95e8ae1c8aa9341fde97d8efa69e6b5fcc00df429b2ada5e1b18f5dc9c2c51cc73504a
7
- data.tar.gz: 4c6f5e4d359551e7420dd4331192f857f8a4518ab679b8052f36c6854a34a100a97bd4af98358589dcd08144cff9ddda071f6b2bd4602dc7495d2fc8467c6994
6
+ metadata.gz: 46af6c3b3918144effcdf07bd6a15bb1dac898a99569183cc2129310e75bd38f035432f7ced725d2ad583d1a09b65f26ad304c08fcf29f46800a086b09aef44f
7
+ data.tar.gz: b5564653b81c34921d10f62979c38c8dbc1f6e06ad4c396c20aaa0e3a1f09f28b738425ac508c1d9556a4b2b77e0c83dcb0a39b3bc91102ec59b87cd09bf420f
data/CHANGELOG.md CHANGED
@@ -2,11 +2,15 @@ This project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.4.0 - 2020-05-16
6
+
7
+ * Portrayal schema is deep-duped to subclasses. [[commit]](https://github.com/scottscheapflights/portrayal/commit/f346483a379ce9fbdece72cde8b0844f2d22b1cd)
8
+
5
9
  ## 0.3.1 - 2020-05-11
6
10
 
7
- * Fix the issue introduced in 0.3.0 where `==` and `eql?` were always treating rhs as another portrayal class.
11
+ * Fix the issue introduced in 0.3.0 where `==` and `eql?` were always treating rhs as another portrayal class. [[commit]](https://github.com/scottscheapflights/portrayal/commit/f6ec8f373c6582f7e8d8f872d289222e4a58f8f6)
8
12
 
9
- ## 0.3.0 - 2020-05-09
13
+ ## 0.3.0 - 2020-05-09 (yanked)
10
14
 
11
15
  * No longer compare classes in `==`, use `eql?` for that. [[commit]](https://github.com/scottscheapflights/portrayal/commit/9c5a37e4fb91e35d23b22e208344452930452af7)
12
16
  * Define a protected writer for every keyword - useful when applying changes after `dup`/`clone`. [[commit]](https://github.com/scottscheapflights/portrayal/commit/1c0fa6c6357a09760dae39165e864238d231a08e)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- portrayal (0.3.1)
4
+ portrayal (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -8,7 +8,7 @@ Inspired by:
8
8
  - Piotr Solnica's [virtus](https://github.com/solnic/virtus)
9
9
  - Everything [Michel Martens](https://github.com/soveran)
10
10
 
11
- Portrayal is a minimalist gem (~115 loc, no dependencies) for building struct-like classes. It provides a small yet powerful step up from plain ruby with its one and only `keyword` method.
11
+ Portrayal is a minimalist gem (~130 loc, no dependencies) for building struct-like classes. It provides a small yet powerful step up from plain ruby with its one and only `keyword` method.
12
12
 
13
13
  ```ruby
14
14
  class Person < MySuperClass
@@ -2,13 +2,9 @@ module Portrayal
2
2
  class Schema
3
3
  attr_reader :schema
4
4
 
5
- def initialize
6
- @schema = {}
7
- @equality_defined = false
8
- end
9
-
10
- def keywords; @schema.keys end
11
- def [](name); @schema[name] end
5
+ def initialize; @schema = {} end
6
+ def keywords; @schema.keys end
7
+ def [](name); @schema[name] end
12
8
 
13
9
  def attributes(object)
14
10
  Hash[object.class.portrayal.keywords.map { |k| [k, object.send(k)] }]
@@ -39,6 +35,15 @@ module Portrayal
39
35
  (value.is_a?(Proc) && !value.lambda?) ? :call : :return
40
36
  end
41
37
 
38
+ def initialize_dup(other)
39
+ super
40
+ @schema =
41
+ other.schema.map { |k, v|
42
+ default = v[:default] ? v[:default].map(&:dup) : v[:default]
43
+ [k, { optional: v[:optional], default: default }]
44
+ }.to_h
45
+ end
46
+
42
47
  def definition_of_initialize
43
48
  init_args = @schema.map { |name, config|
44
49
  config[:optional] ?
@@ -1,3 +1,3 @@
1
1
  module Portrayal
2
- VERSION = "0.3.1"
2
+ VERSION = '0.4.0'
3
3
  end
data/lib/portrayal.rb CHANGED
@@ -6,7 +6,13 @@ module Portrayal
6
6
 
7
7
  def keyword(name, optional: NULL, default: NULL, &block)
8
8
  unless respond_to?(:portrayal)
9
- class << self; attr_reader :portrayal end
9
+ class << self
10
+ attr_reader :portrayal
11
+ def inherited(base)
12
+ base.instance_variable_set('@portrayal', portrayal.dup)
13
+ end
14
+ end
15
+
10
16
  @portrayal = Schema.new
11
17
  class_eval(portrayal.definition_of_object_enhancements)
12
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: portrayal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxim Chernyak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-11 00:00:00.000000000 Z
11
+ date: 2020-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler