dry-struct 0.5.0 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f15a9185e2b7ee171f632db8fc95c29aafa567d4936fe3e8681b073af810f76
4
- data.tar.gz: eec2908a47ad4e549a454bf6890dbb2402f689222810ffeab52b64958ff0caff
3
+ metadata.gz: 61dba90344018c1b2a9cbb58de0a235438958fbbdd5ed3c3effcd075eeae9055
4
+ data.tar.gz: dd79a872121c6fd07c2cc3635651e11e5073f50b29dca40e041d2bd9ba614458
5
5
  SHA512:
6
- metadata.gz: f743fe48c3651573fecbf46fa0c81cd4cd2327774ae903bcd1bea60dc98b09dc6c63acbcca506c8021c383a8b6ce9d74725956c94cca976b22d1a5800d34913b
7
- data.tar.gz: 6f898126cac3c667d60ac352de8fbaacfb24aa417136881f315858c22d337868a3544894d9caea1da6fe9c3cb705c2c45702f0c1228ddbc7bd43d8a44d8256dc
6
+ metadata.gz: ee05a93c33c0dfe02b373cb57cb06fee2c1740c80260ef977ebbf9b182279229705a693c59044e449064472b8f980d9141424575495330bd09b263f6ab47c12b
7
+ data.tar.gz: 5391764853bbdf1effb65dbc83b7c17c9142fd2b29c877c5eb280b2fbd83b06f65d835251b0126ed62afb0b9f28dc86bbf174b07a362ce797cecd3bd46bba269
@@ -1,3 +1,23 @@
1
+ # v0.5.1 2018-08-11
2
+
3
+ ## Fixed
4
+
5
+ * Constant resolution is now restricted to the current module when structs are automatically defined using the block syntax. This shouldn't break any existing code (piktur)
6
+
7
+ ## Added
8
+
9
+ * Pretty print extension (ojab)
10
+ ```ruby
11
+ Dry::Struct.load_extensions(:pretty_print)
12
+ PP.pp(user)
13
+ #<Test::User
14
+ name="Jane",
15
+ age=21,
16
+ address=#<Test::Address city="NYC", zipcode="123">>
17
+ ```
18
+
19
+ [Compare v0.5.0...v0.5.1](https://github.com/dry-rb/dry-struct/compare/v0.5.0...v0.5.1)
20
+
1
21
  # v0.5.0 2018-05-03
2
22
 
3
23
  ## BREAKING CHANGES
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  [gem]: https://rubygems.org/gems/dry-struct
2
2
  [travis]: https://travis-ci.org/dry-rb/dry-struct
3
- [gemnasium]: https://gemnasium.com/dry-rb/dry-struct
4
3
  [codeclimate]: https://codeclimate.com/github/dry-rb/dry-struct
5
4
  [coveralls]: https://coveralls.io/r/dry-rb/dry-struct
6
5
  [inchpages]: http://inch-ci.org/github/dry-rb/dry-struct
@@ -9,7 +8,6 @@
9
8
 
10
9
  [![Gem Version](https://badge.fury.io/rb/dry-struct.svg)][gem]
11
10
  [![Build Status](https://travis-ci.org/dry-rb/dry-struct.svg?branch=master)][travis]
12
- [![Dependency Status](https://gemnasium.com/dry-rb/dry-struct.svg)][gemnasium]
13
11
  [![Code Climate](https://codeclimate.com/github/dry-rb/dry-struct/badges/gpa.svg)][codeclimate]
14
12
  [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-struct/badges/coverage.svg)][codeclimate]
15
13
  [![Inline docs](http://inch-ci.org/github/dry-rb/dry-struct.svg?branch=master)][inchpages]
@@ -1,5 +1,6 @@
1
1
  require 'dry-types'
2
2
  require 'dry-equalizer'
3
+ require 'dry/core/extensions'
3
4
  require 'dry/core/constants'
4
5
 
5
6
  require 'dry/struct/version'
@@ -81,6 +82,7 @@ module Dry
81
82
  # refactoring.title #=> 'Refactoring'
82
83
  # refactoring.subtitle #=> 'Improving the Design of Existing Code'
83
84
  class Struct
85
+ extend Dry::Core::Extensions
84
86
  include Dry::Core::Constants
85
87
  extend ClassInterface
86
88
 
@@ -120,9 +122,7 @@ module Dry
120
122
  # rom_n_roda[:title] #=> 'Web Development with ROM and Roda'
121
123
  # rom_n_roda[:subtitle] #=> nil
122
124
  def [](name)
123
- @attributes.fetch(name)
124
- rescue KeyError
125
- raise MissingAttributeError.new(name)
125
+ @attributes.fetch(name) { raise MissingAttributeError.new(name) }
126
126
  end
127
127
 
128
128
  # Converts the {Dry::Struct} to a hash with keys representing
@@ -184,3 +184,4 @@ module Dry
184
184
  end
185
185
 
186
186
  require 'dry/struct/value'
187
+ require 'dry/struct/extensions'
@@ -0,0 +1,3 @@
1
+ Dry::Struct.register_extension(:pretty_print) do
2
+ require 'dry/struct/extensions/pretty_print'
3
+ end
@@ -0,0 +1,20 @@
1
+ require 'pp'
2
+
3
+ module Dry
4
+ class Struct
5
+ def pretty_print(pp)
6
+ klass = self.class
7
+ pp.group(1, "#<#{ klass.name || klass.inspect }", '>') do
8
+ pp.seplist(@attributes.keys, proc { pp.text ',' }) do |column_name|
9
+ column_value = @attributes[column_name]
10
+ pp.breakable ' '
11
+ pp.group(1) do
12
+ pp.text column_name
13
+ pp.text '='
14
+ pp.pp column_value
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -60,7 +60,7 @@ module Dry
60
60
  raise(
61
61
  Struct::Error,
62
62
  "Can't create nested attribute - `#{struct}::#{name}` already defined"
63
- ) if struct.const_defined?(name)
63
+ ) if struct.const_defined?(name, false)
64
64
  end
65
65
 
66
66
  def visit_constrained(node)
@@ -1,6 +1,6 @@
1
1
  module Dry
2
2
  class Struct
3
3
  # @private
4
- VERSION = '0.5.0'.freeze
4
+ VERSION = '0.5.1'.freeze
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-03 00:00:00.000000000 Z
11
+ date: 2018-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-equalizer
@@ -155,6 +155,8 @@ files:
155
155
  - lib/dry/struct/class_interface.rb
156
156
  - lib/dry/struct/constructor.rb
157
157
  - lib/dry/struct/errors.rb
158
+ - lib/dry/struct/extensions.rb
159
+ - lib/dry/struct/extensions/pretty_print.rb
158
160
  - lib/dry/struct/hashify.rb
159
161
  - lib/dry/struct/struct_builder.rb
160
162
  - lib/dry/struct/sum.rb