dry-types 0.6.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: db688f074a70acff2e5acd2b23ad2dd14d5292fe
4
+ data.tar.gz: e148638d952426127fd886ee25bad640cf8d7839
5
+ SHA512:
6
+ metadata.gz: 3e1dc84f874a91638488e15eff1dbd0f97a3ee6b25cd0ecf7deab7300441382f9b05912830cab13570ced7840e5030aec17175fd6cfee6ce27c12b386ba4bcf9
7
+ data.tar.gz: 6eaf193a169e9a4e951657dbae09272098ee369ccc9c6e08b730d9d486e9ee94c71ea05e59b14cd3925919ebe0a480402f8e12f35037cfa5a21392754d2854cc
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require ./spec/spec_helper
@@ -0,0 +1,30 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ bundler_args: --without benchmarks tools
5
+ script:
6
+ - bundle exec rake spec
7
+ rvm:
8
+ - 2.0
9
+ - 2.1
10
+ - 2.2
11
+ - 2.3.0
12
+ - rbx-2
13
+ - jruby-9000
14
+ - ruby-head
15
+ - jruby-head
16
+ env:
17
+ global:
18
+ - JRUBY_OPTS='--dev -J-Xmx1024M'
19
+ matrix:
20
+ allow_failures:
21
+ - rvm: ruby-head
22
+ - rvm: jruby-head
23
+ notifications:
24
+ email: false
25
+ webhooks:
26
+ urls:
27
+ - https://webhooks.gitter.im/e/19098b4253a72c9796db
28
+ on_success: change # options: [always|never|change] default: always
29
+ on_failure: always # options: [always|never|change] default: always
30
+ on_start: false # default: false
@@ -0,0 +1,169 @@
1
+ # v0.6.0 2016-03-16
2
+
3
+ Renamed from `dry-data` to `dry-types` and:
4
+
5
+ ## Added
6
+
7
+ * `Dry::Types.module` which returns a namespace for inclusion which has all
8
+ built-in types defined as constants (solnic)
9
+ * `Hash#schema` supports default values now (solnic)
10
+ * `Hash#symbolized` passes through keys that are already symbols (solnic)
11
+ * `Struct.new` uses an empty hash by default as input (solnic)
12
+ * `Struct.constructor_type` macro can be used to change attributes constructor (solnic)
13
+ * `default` accepts a block now for dynamic values (solnic)
14
+ * `Types.register_class` accepts a second arg which is the name of the class'
15
+ constructor method, defaults to `:new` (solnic)
16
+
17
+ ## Fixed
18
+
19
+ * `Struct` will simply pass-through the input if it is already a struct (solnic)
20
+ * `default` will raise if a value violates constraints (solnic)
21
+ * Evaluating a default value tries to use type's constructor which makes it work
22
+ with types that may coerce an input into nil (solnic)
23
+ * `enum` works just fine with integer-values (solnic)
24
+ * `enum` + `default` works just fine (solnic)
25
+ * `Optional` no longer responds to `primitive` as it makes no sense since there's
26
+ no single primitive for an optional value (solnic)
27
+ * `Optional` passes-through a value which is already a maybe (solnic)
28
+
29
+ ## Changed
30
+
31
+ * `Dry::Types::Definition` is now the base type definition object (solnic)
32
+ * `Dry::Types::Constructor` is now a type definition with a constructor function (solnic)
33
+
34
+ [Compare v0.5.1...v0.6.0](https://github.com/dryrb/dry-types/compare/v0.5.1...v0.6.0)
35
+
36
+ # v0.5.1 2016-01-11
37
+
38
+ ## Added
39
+
40
+ * `Dry::Data::Type#safe` for types which can skip constructor when primitive does
41
+ not match input's class (solnic)
42
+ * `form.array` and `form.hash` safe types (solnic)
43
+
44
+ [Compare v0.5.0...v0.5.1](https://github.com/dryrb/dry-types/compare/v0.5.0...v0.5.1)
45
+
46
+ # v0.5.0 2016-01-11
47
+
48
+ ## Added
49
+
50
+ * `Type#default` interface for defining a type with a default value (solnic)
51
+
52
+ ## Changed
53
+
54
+ * [BREAKING] `Dry::Data::Type.new` accepts constructor and *options* now (solnic)
55
+ * Renamed `Dry::Data::Type::{Enum,Constrained}` => `Dry::Data::{Enum,Constrained}` (solnic)
56
+ * `dry-logic` is now a dependency for constrained types (solnic)
57
+ * Constrained types are now always available (solnic)
58
+ * `strict.*` category uses constrained types with `:type?` predicate (solnic)
59
+ * `SumType#call` no longer needs to rescue from `TypeError` (solnic)
60
+
61
+ ## Fixed
62
+
63
+ * `attribute` raises proper error when type definition is missing (solnic)
64
+
65
+ [Compare v0.4.2...v0.5.0](https://github.com/dryrb/dry-types/compare/v0.4.2...v0.5.0)
66
+
67
+ # v0.4.2 2015-12-27
68
+
69
+ ## Added
70
+
71
+ * Support for arrays in type compiler (solnic)
72
+
73
+ ## Changed
74
+
75
+ * Array member uses type objects now rather than just their constructors (solnic)
76
+
77
+ [Compare v0.4.1...v0.4.2](https://github.com/dryrb/dry-types/compare/v0.4.1...v0.4.2)
78
+
79
+ # v0.4.0 2015-12-11
80
+
81
+ ## Added
82
+
83
+ * Support for sum-types with constraint type (solnic)
84
+ * `Dry::Data::Type#optional` for defining optional types (solnic)
85
+
86
+ ## Changed
87
+
88
+ * `Dry::Data['optional']` was **removed** in favor of `Dry::Data::Type#optional` (solnic)
89
+
90
+ [Compare v0.3.2...v0.4.0](https://github.com/dryrb/dry-types/compare/v0.3.2...v0.4.0)
91
+
92
+ # v0.3.2 2015-12-10
93
+
94
+ ## Added
95
+
96
+ * `Dry::Data::Value` which works like a struct but is a value object with equalizer (solnic)
97
+
98
+ ## Fixed
99
+
100
+ * Added missing require for `dry-equalizer` (solnic)
101
+
102
+ [Compare v0.3.1...v0.3.2](https://github.com/dryrb/dry-types/compare/v0.3.1...v0.3.2)
103
+
104
+ # v0.3.1 2015-12-09
105
+
106
+ ## Changed
107
+
108
+ * Removed require of constrained type and make it optional (solnic)
109
+
110
+ [Compare v0.3.0...v0.3.1](https://github.com/dryrb/dry-types/compare/v0.3.0...v0.3.1)
111
+
112
+ # v0.3.0 2015-12-09
113
+
114
+ ## Added
115
+
116
+ * `Type#constrained` interface for defining constrained types (solnic)
117
+ * `Dry::Data` can be configured with a type namespace (solnic)
118
+ * `Dry::Data.finalize` can be used to define types as constants under configured namespace (solnic)
119
+ * `Dry::Data::Type#enum` for defining an enum from a specific type (solnic)
120
+ * New types: `symbol` and `class` along with their `strict` versions (solnic)
121
+
122
+ [Compare v0.2.1...v0.3.0](https://github.com/dryrb/dry-types/compare/v0.2.1...v0.3.0)
123
+
124
+ # v0.2.1 2015-11-30
125
+
126
+ ## Added
127
+
128
+ * Type compiler supports nested hashes now (solnic)
129
+
130
+ ## Fixed
131
+
132
+ * `form.bool` sum is using correct right-side `form.false` type (solnic)
133
+
134
+ ## Changed
135
+
136
+ * Improved structure of the ast (solnic)
137
+
138
+ [Compare v0.2.0...v0.2.1](https://github.com/dryrb/dry-types/compare/v0.2.0...v0.2.1)
139
+
140
+ # v0.2.0 2015-11-29
141
+
142
+ ## Added
143
+
144
+ * `form.nil` which coerces empty strings to `nil` (solnic)
145
+ * `bool` sum-type (true | false) (solnic)
146
+ * Type compiler supports sum-types now (solnic)
147
+
148
+ ## Changed
149
+
150
+ * Constructing optional types uses the new `Dry::Data["optional"]` built-in type (solnic)
151
+
152
+ [Compare v0.1.0...v0.2.0](https://github.com/dryrb/dry-types/compare/v0.1.0...v0.2.0)
153
+
154
+ # v0.1.0 2015-11-27
155
+
156
+ ## Added
157
+
158
+ * `form.*` coercible types (solnic)
159
+ * `Type::Hash#strict` for defining hashes with a strict schema (solnic)
160
+ * `Type::Hash#symbolized` for defining hashes that will symbolize keys (solnic)
161
+ * `Dry::Data.register_class` short-cut interface for registering a class and
162
+ setting its `.new` method as the constructor (solnic)
163
+ * `Dry::Data::Compiler` for building a type from a simple ast (solnic)
164
+
165
+ [Compare v0.0.1...HEAD](https://github.com/dryrb/dry-types/compare/v0.0.1...HEAD)
166
+
167
+ # v0.0.1 2015-10-05
168
+
169
+ First public release
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem "codeclimate-test-reporter", platform: :rbx, require: false
7
+ end
8
+
9
+ group :tools do
10
+ gem 'byebug', platform: :mri
11
+ end
12
+
13
+ group :benchmarks do
14
+ gem 'sqlite3'
15
+ gem 'activerecord'
16
+ gem 'benchmark-ips'
17
+ gem 'virtus'
18
+ gem 'fast_attributes'
19
+ gem 'attrio'
20
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013-2014 Piotr Solnica
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ [gem]: https://rubygems.org/gems/dry-types
2
+ [travis]: https://travis-ci.org/dry-rb/dry-types
3
+ [gemnasium]: https://gemnasium.com/dry-rb/dry-types
4
+ [codeclimate]: https://codeclimate.com/github/dry-rb/dry-types
5
+ [coveralls]: https://coveralls.io/r/dry-rb/dry-types
6
+ [inchpages]: http://inch-ci.org/github/dry-rb/dry-types
7
+
8
+ # dry-types [![Join the chat at https://gitter.im/dry-rb/chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dry-rb/chat)
9
+
10
+ [![Gem Version](https://badge.fury.io/rb/dry-types.svg)][gem]
11
+ [![Build Status](https://travis-ci.org/dry-rb/dry-types.svg?branch=master)][travis]
12
+ [![Dependency Status](https://gemnasium.com/dry-rb/dry-types.svg)][gemnasium]
13
+ [![Code Climate](https://codeclimate.com/github/dry-rb/dry-types/badges/gpa.svg)][codeclimate]
14
+ [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-types/badges/coverage.svg)][codeclimate]
15
+ [![Inline docs](http://inch-ci.org/github/dry-rb/dry-types.svg?branch=master)][inchpages]
16
+
17
+ ## Links
18
+
19
+ * [Documentation](http://dry-rb.org/gems/dry-types)
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dry-rb/dry-types.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,57 @@
1
+ require 'dry/types'
2
+ require 'virtus'
3
+ require 'fast_attributes'
4
+ require 'attrio'
5
+ require 'ostruct'
6
+
7
+ require 'benchmark/ips'
8
+
9
+ class VirtusUser
10
+ include Virtus.model
11
+
12
+ attribute :name, String
13
+ attribute :age, Integer
14
+ end
15
+
16
+ class FastUser
17
+ extend FastAttributes
18
+
19
+ define_attributes initialize: true, attributes: true do
20
+ attribute :name, String
21
+ attribute :age, Integer
22
+ end
23
+ end
24
+
25
+ class AttrioUser
26
+ include Attrio
27
+
28
+ define_attributes do
29
+ attr :name, String
30
+ attr :age, Integer
31
+ end
32
+
33
+ def initialize(attributes = {})
34
+ self.attributes = attributes
35
+ end
36
+
37
+ def attributes=(attributes = {})
38
+ attributes.each do |attr,value|
39
+ self.send("#{attr}=", value) if self.respond_to?("#{attr}=")
40
+ end
41
+ end
42
+ end
43
+
44
+ class DryTypesUser < Dry::Types::Struct
45
+ attributes(name: 'string', age: 'form.int')
46
+ end
47
+
48
+ puts DryTypesUser.new(name: 'Jane', age: '21').inspect
49
+
50
+ Benchmark.ips do |x|
51
+ x.report('virtus') { VirtusUser.new(name: 'Jane', age: '21') }
52
+ x.report('fast_attributes') { FastUser.new(name: 'Jane', age: '21') }
53
+ x.report('attrio') { AttrioUser.new(name: 'Jane', age: '21') }
54
+ x.report('dry-types') { DryTypesUser.new(name: 'Jane', age: '21') }
55
+
56
+ x.compare!
57
+ end
@@ -0,0 +1,37 @@
1
+ require 'dry/types'
2
+
3
+ require 'active_record'
4
+ require 'benchmark/ips'
5
+
6
+ ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
7
+
8
+ ActiveRecord::Schema.define do
9
+ create_table :users do |table|
10
+ table.column :name, :string
11
+ table.column :age, :integer
12
+ end
13
+ end
14
+
15
+ class ARUser < ActiveRecord::Base
16
+ self.table_name = :users
17
+ end
18
+
19
+ module Types
20
+ include Dry::Types.module
21
+ end
22
+
23
+ class DryTypesUser < Dry::Types::Struct
24
+ attribute :id, Types::Form::Int
25
+ attribute :name, Types::Strict::String.constrained(size: 3..64)
26
+ attribute :age, Types::Form::Int.constrained(gt: 18)
27
+ end
28
+
29
+ puts ARUser.new(id: 1, name: 'Jane', age: '21').inspect
30
+ puts DryTypesUser.new(id: 1, name: 'Jane', age: '21').inspect
31
+
32
+ Benchmark.ips do |x|
33
+ x.report('active record') { ARUser.new(id: 1, name: 'Jane', age: '21') }
34
+ x.report('dry-types') { DryTypesUser.new(id: 1, name: 'Jane', age: '21') }
35
+
36
+ x.compare!
37
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dry/types"
5
+
6
+ module Types
7
+ include Dry::Types.module
8
+ end
9
+
10
+ # You can add fixtures and/or initialization code here to make experimenting
11
+ # with your gem easier. You can also use a different console, if you like.
12
+
13
+ # (If you use this, don't forget to add pry to your Gemfile!)
14
+ # require "pry"
15
+ # Pry.start
16
+
17
+ require "irb"
18
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dry/types/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dry-types"
8
+ spec.version = Dry::Types::VERSION.dup
9
+ spec.authors = ["Piotr Solnica"]
10
+ spec.email = ["piotr.solnica@gmail.com"]
11
+ spec.license = 'MIT'
12
+
13
+ spec.summary = 'Type system for Ruby supporting coercions, constraints and complex types like structs, value objects, enums etc.'
14
+ spec.description = spec.summary
15
+ spec.homepage = "https://github.com/dryrb/dry-types"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency 'thread_safe', '~> 0.3'
31
+ spec.add_runtime_dependency 'dry-container', '~> 0.2'
32
+ spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
33
+ spec.add_runtime_dependency 'dry-configurable', '~> 0.1'
34
+ spec.add_runtime_dependency 'dry-logic', '~> 0.2', '>= 0.2.0'
35
+ spec.add_runtime_dependency 'inflecto', '~> 0.0.0', '>= 0.0.2'
36
+ spec.add_runtime_dependency 'kleisli', '~> 0.2'
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.7"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.3"
41
+ end