dry-struct 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8ad25e8537c7c9b1762fa73ff25103adddc4b45
4
- data.tar.gz: 1a2be7946a5fc0b70f9b40157ce8c0f6f57fcec0
3
+ metadata.gz: 01b27ade8be3b7f1fcadc7a426f65fc114494396
4
+ data.tar.gz: 9d21cd9c9e666d761e068153b022ca65ab84c3f5
5
5
  SHA512:
6
- metadata.gz: 9d3aace8acda03bd17706d3b1e3b0ad14584639b8783cee401e2e91ee30f91a55130d99bac7b8994b6eb980ef15b42c772b346387dfb807b6933a0bd67b7c5d3
7
- data.tar.gz: b36ba76069268bf7f849de3a38102072229f99264d967df36a63dba09ffc90e394a9d034e8369ca0bad0486284d0cdab62e0146a7382bd27177c9ce2dcf56c1e
6
+ metadata.gz: f099db81c4e68cb0963b2225d5c156a8b417cfe9e7f43721b2e94f2b7ec8f1f72d646f486e7610a1894135efd7ce47e722a26dd96287b3ed226383262f38ff92
7
+ data.tar.gz: c59d33760418278b7be4155a5f7510f87b962ee1f0ba8defcbad41438a5d609d0d916c238259cf54185b8262e4f2e4ca33cf88759cd4d61a3a190e2b1cd36773
@@ -5,10 +5,9 @@ bundler_args: --without benchmarks tools
5
5
  script:
6
6
  - bundle exec rake spec
7
7
  rvm:
8
- - 2.0
9
8
  - 2.1
10
9
  - 2.2
11
- - 2.3.0
10
+ - 2.3.1
12
11
  - rbx-2
13
12
  - jruby-9000
14
13
  - ruby-head
@@ -0,0 +1,17 @@
1
+ # v0.1.0 2016-09-21
2
+
3
+ ## Added
4
+
5
+ * `:strict_with_defaults` constructor type (backus)
6
+
7
+ ## Changed
8
+
9
+ * [BREAKING] `:strict` was renamed to `:permissive` as it ignores missing keys (backus)
10
+ * [BREAKING] `:strict` now raises on unexpected keys (backus)
11
+ * Structs no longer auto-register themselves in the types container as they implement `Type` interface and we don't have to wrap them in `Type::Definition` (flash-gordon)
12
+
13
+ [Compare v0.0.1...v0.1.0](https://github.com/dry-rb/dry-struct/compare/v0.0.1...v0.1.0)
14
+
15
+ # v0.0.1 2016-07-17
16
+
17
+ Initial release of code imported from dry-types
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :test do
6
- gem 'codeclimate-test-reporter', platform: :rbx, require: false
6
+ gem 'codeclimate-test-reporter', platform: :mri, require: false
7
7
  end
8
8
 
9
9
  group :tools do
data/README.md CHANGED
@@ -1,6 +1,20 @@
1
+ [gem]: https://rubygems.org/gems/dry-struct
2
+ [travis]: https://travis-ci.org/dry-rb/dry-struct
3
+ [gemnasium]: https://gemnasium.com/dry-rb/dry-struct
4
+ [codeclimate]: https://codeclimate.com/github/dry-rb/dry-struct
5
+ [coveralls]: https://coveralls.io/r/dry-rb/dry-struct
6
+ [inchpages]: http://inch-ci.org/github/dry-rb/dry-struct
7
+
1
8
  # dry-struct [![Join the chat at https://gitter.im/dry-rb/chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dry-rb/chat)
2
9
 
3
- WIP extraction from dry-types
10
+ [![Gem Version](https://badge.fury.io/rb/dry-struct.svg)][gem]
11
+ [![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
+ [![Code Climate](https://codeclimate.com/github/dry-rb/dry-struct/badges/gpa.svg)][codeclimate]
14
+ [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-struct/badges/coverage.svg)][codeclimate]
15
+ [![Inline docs](http://inch-ci.org/github/dry-rb/dry-struct.svg?branch=master)][inchpages]
16
+
17
+ WIP extraction from dry-struct
4
18
 
5
19
  ## Development
6
20
 
@@ -1,15 +1,19 @@
1
1
  # coding: utf-8
2
2
 
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'dry/struct/version'
6
+
3
7
  Gem::Specification.new do |spec|
4
8
  spec.name = 'dry-struct'
5
- spec.version = '0.0.1'
9
+ spec.version = Dry::Struct::VERSION
6
10
  spec.authors = ['Piotr Solnica']
7
11
  spec.email = ['piotr.solnica@gmail.com']
8
12
  spec.license = 'MIT'
9
13
 
10
14
  spec.summary = 'Typed structs and value objects.'
11
15
  spec.description = spec.summary
12
- spec.homepage = 'https://github.com/dryrb/dry-struct'
16
+ spec.homepage = 'https://github.com/dry-rb/dry-struct'
13
17
 
14
18
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
15
19
  # delete this section to allow pushing this gem to any host.
@@ -26,8 +30,7 @@ Gem::Specification.new do |spec|
26
30
 
27
31
  spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
28
32
  spec.add_runtime_dependency 'dry-configurable', '~> 0.1'
29
- spec.add_runtime_dependency 'dry-logic', '~> 0.2', '>= 0.2.3'
30
- spec.add_runtime_dependency 'dry-types', '~> 0.8', '>= 0.8.1'
33
+ spec.add_runtime_dependency 'dry-types', '~> 0.9', '>= 0.9.0'
31
34
  spec.add_runtime_dependency 'ice_nine', '~> 0.11'
32
35
 
33
36
  spec.add_development_dependency 'bundler', '~> 1.6'
@@ -10,6 +10,8 @@ module Dry
10
10
  class Struct
11
11
  extend ClassInterface
12
12
 
13
+ constructor_type(:permissive)
14
+
13
15
  def initialize(attributes)
14
16
  attributes.each { |key, value| instance_variable_set("@#{key}", value) }
15
17
  end
@@ -1,3 +1,5 @@
1
+ require 'dry/struct/errors'
2
+
1
3
  module Dry
2
4
  class Struct
3
5
  module ClassInterface
@@ -11,16 +13,20 @@ module Dry
11
13
 
12
14
  protected :constructor=, :equalizer=, :constructor_type=
13
15
 
16
+ def self.extended(base)
17
+ base.instance_variable_set(:@schema, {})
18
+ end
19
+
14
20
  def inherited(klass)
15
21
  super
16
22
 
23
+ klass.instance_variable_set(:@schema, {})
17
24
  klass.equalizer = Equalizer.new(*schema.keys)
18
25
  klass.constructor_type = constructor_type
19
26
  klass.send(:include, klass.equalizer)
20
27
 
21
28
  unless klass == Value
22
29
  klass.constructor = Types['coercible.hash']
23
- Types.register(Types.identifier(klass), klass)
24
30
  end
25
31
 
26
32
  klass.attributes({}) unless equal?(Struct)
@@ -47,7 +53,7 @@ module Dry
47
53
  def check_schema_duplication(new_schema)
48
54
  shared_keys = new_schema.keys & schema.keys
49
55
 
50
- fail Types::RepeatedAttributeError, shared_keys.first if shared_keys.any?
56
+ raise RepeatedAttributeError, shared_keys.first if shared_keys.any?
51
57
  end
52
58
  private :check_schema_duplication
53
59
 
@@ -70,7 +76,7 @@ module Dry
70
76
  else
71
77
  super(constructor[attributes])
72
78
  end
73
- rescue Types::SchemaError, Types::SchemaKeyError => error
79
+ rescue Types::SchemaError, Types::MissingKeyError, Types::UnknownKeysError => error
74
80
  raise Struct::Error, "[#{self}.new] #{error}"
75
81
  end
76
82
  alias_method :call, :new
@@ -89,8 +95,16 @@ module Dry
89
95
  block_given? ? yield(failure) : failure
90
96
  end
91
97
 
92
- def maybe?
93
- false
98
+ def success(*args)
99
+ result(Types::Result::Success, *args)
100
+ end
101
+
102
+ def failure(*args)
103
+ result(Types::Result::Failure, *args)
104
+ end
105
+
106
+ def result(klass, *args)
107
+ klass.new(*args)
94
108
  end
95
109
 
96
110
  def default?
@@ -100,6 +114,14 @@ module Dry
100
114
  def valid?(value)
101
115
  self === value
102
116
  end
117
+
118
+ def constrained?
119
+ false
120
+ end
121
+
122
+ def primitive
123
+ self
124
+ end
103
125
  end
104
126
  end
105
127
  end
@@ -1,7 +1,5 @@
1
1
  require 'ice_nine'
2
2
 
3
- require 'dry/struct'
4
-
5
3
  module Dry
6
4
  class Struct
7
5
  class Value < self
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  class Struct
3
- VERSION = '0.0.1'.freeze
3
+ VERSION = '0.1.0'.freeze
4
4
  end
5
5
  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.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-17 00:00:00.000000000 Z
11
+ date: 2016-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-equalizer
@@ -38,46 +38,26 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.1'
41
- - !ruby/object:Gem::Dependency
42
- name: dry-logic
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0.2'
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: 0.2.3
51
- type: :runtime
52
- prerelease: false
53
- version_requirements: !ruby/object:Gem::Requirement
54
- requirements:
55
- - - "~>"
56
- - !ruby/object:Gem::Version
57
- version: '0.2'
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: 0.2.3
61
41
  - !ruby/object:Gem::Dependency
62
42
  name: dry-types
63
43
  requirement: !ruby/object:Gem::Requirement
64
44
  requirements:
65
45
  - - "~>"
66
46
  - !ruby/object:Gem::Version
67
- version: '0.8'
47
+ version: '0.9'
68
48
  - - ">="
69
49
  - !ruby/object:Gem::Version
70
- version: 0.8.1
50
+ version: 0.9.0
71
51
  type: :runtime
72
52
  prerelease: false
73
53
  version_requirements: !ruby/object:Gem::Requirement
74
54
  requirements:
75
55
  - - "~>"
76
56
  - !ruby/object:Gem::Version
77
- version: '0.8'
57
+ version: '0.9'
78
58
  - - ">="
79
59
  - !ruby/object:Gem::Version
80
- version: 0.8.1
60
+ version: 0.9.0
81
61
  - !ruby/object:Gem::Dependency
82
62
  name: ice_nine
83
63
  requirement: !ruby/object:Gem::Requirement
@@ -144,6 +124,7 @@ files:
144
124
  - ".gitignore"
145
125
  - ".rspec"
146
126
  - ".travis.yml"
127
+ - CHANGELOG.md
147
128
  - Gemfile
148
129
  - LICENSE
149
130
  - README.md
@@ -160,7 +141,7 @@ files:
160
141
  - lib/dry/struct/hashify.rb
161
142
  - lib/dry/struct/value.rb
162
143
  - lib/dry/struct/version.rb
163
- homepage: https://github.com/dryrb/dry-struct
144
+ homepage: https://github.com/dry-rb/dry-struct
164
145
  licenses:
165
146
  - MIT
166
147
  metadata:
@@ -181,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
162
  version: '0'
182
163
  requirements: []
183
164
  rubyforge_project:
184
- rubygems_version: 2.6.3
165
+ rubygems_version: 2.6.6
185
166
  signing_key:
186
167
  specification_version: 4
187
168
  summary: Typed structs and value objects.