dry-struct 1.0.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +208 -82
- data/LICENSE +17 -17
- data/README.md +16 -12
- data/dry-struct.gemspec +26 -28
- data/lib/dry-struct.rb +3 -1
- data/lib/dry/struct.rb +55 -34
- data/lib/dry/struct/class_interface.rb +135 -72
- data/lib/dry/struct/compiler.rb +22 -0
- data/lib/dry/struct/constructor.rb +4 -24
- data/lib/dry/struct/errors.rb +13 -3
- data/lib/dry/struct/extensions.rb +3 -1
- data/lib/dry/struct/extensions/pretty_print.rb +7 -5
- data/lib/dry/struct/hashify.rb +6 -6
- data/lib/dry/struct/printer.rb +6 -1
- data/lib/dry/struct/struct_builder.rb +47 -24
- data/lib/dry/struct/sum.rb +5 -2
- data/lib/dry/struct/value.rb +13 -4
- data/lib/dry/struct/version.rb +3 -1
- metadata +33 -59
- data/.gitignore +0 -12
- data/.rspec +0 -2
- data/.travis.yml +0 -29
- data/.yardopts +0 -4
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -26
- data/Rakefile +0 -10
- data/benchmarks/basic.rb +0 -57
- data/benchmarks/constrained.rb +0 -37
- data/benchmarks/profile_instantiation.rb +0 -19
- data/benchmarks/setup.rb +0 -11
- data/bin/console +0 -12
- data/bin/setup +0 -7
- data/log/.gitkeep +0 -0
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
dist: trusty
|
3
|
-
sudo: required
|
4
|
-
bundler_args: --without benchmarks tools
|
5
|
-
script:
|
6
|
-
- bundle exec rake spec
|
7
|
-
after_success:
|
8
|
-
- '[ -d coverage ] && bundle exec codeclimate-test-reporter'
|
9
|
-
rvm:
|
10
|
-
- 2.4.5
|
11
|
-
- 2.5.5
|
12
|
-
- 2.6.3
|
13
|
-
- jruby-9.2.7.0
|
14
|
-
- truffleruby
|
15
|
-
env:
|
16
|
-
global:
|
17
|
-
- COVERAGE=true
|
18
|
-
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
19
|
-
matrix:
|
20
|
-
allow_failures:
|
21
|
-
- rvm: truffleruby
|
22
|
-
notifications:
|
23
|
-
email: false
|
24
|
-
webhooks:
|
25
|
-
urls:
|
26
|
-
- https://webhooks.gitter.im/e/19098b4253a72c9796db
|
27
|
-
on_success: change # options: [always|never|change] default: always
|
28
|
-
on_failure: always # options: [always|never|change] default: always
|
29
|
-
on_start: false # default: false
|
data/.yardopts
DELETED
data/CONTRIBUTING.md
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# Issue Guidelines
|
2
|
-
|
3
|
-
## Reporting bugs
|
4
|
-
|
5
|
-
If you found a bug, report an issue and describe what's the expected behavior versus what actually happens. If the bug causes a crash, attach a full backtrace. If possible, a reproduction script showing the problem is highly appreciated.
|
6
|
-
|
7
|
-
## Reporting feature requests
|
8
|
-
|
9
|
-
Report a feature request **only after discourseing it first on [discourse.dry-rb.org](https://discourse.dry-rb.org)** where it was accepted. Please provide a concise description of the feature, don't link to a discourseion thread, and instead summarize what was discourseed.
|
10
|
-
|
11
|
-
## Reporting questions, support requests, ideas, concerns etc.
|
12
|
-
|
13
|
-
**PLEASE DON'T** - use [discourse.dry-rb.org](https://discourse.dry-rb.org) instead.
|
14
|
-
|
15
|
-
# Pull Request Guidelines
|
16
|
-
|
17
|
-
A Pull Request will only be accepted if it addresses a specific issue that was reported previously, or fixes typos, mistakes in documentation etc.
|
18
|
-
|
19
|
-
Other requirements:
|
20
|
-
|
21
|
-
1) Do not open a pull request if you can't provide tests along with it. If you have problems writing tests, ask for help in the related issue.
|
22
|
-
2) Follow the style conventions of the surrounding code. In most cases, this is standard ruby style.
|
23
|
-
3) Add API documentation if it's a new feature
|
24
|
-
4) Update API documentation if it changes an existing feature
|
25
|
-
5) Bonus points for sending a PR to [github.com/dry-rb/dry-rb.org](github.com/dry-rb/dry-rb.org) which updates user documentation and guides
|
26
|
-
|
27
|
-
# Asking for help
|
28
|
-
|
29
|
-
If these guidelines aren't helpful, and you're stuck, please post a message on [discourse.dry-rb.org](https://discourse.dry-rb.org).
|
data/Gemfile
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
|
-
|
5
|
-
gemspec
|
6
|
-
|
7
|
-
group :test do
|
8
|
-
gem 'codeclimate-test-reporter', platform: :mri, require: false
|
9
|
-
gem 'simplecov', require: false
|
10
|
-
gem 'warning'
|
11
|
-
end
|
12
|
-
|
13
|
-
group :tools do
|
14
|
-
gem 'pry'
|
15
|
-
gem 'pry-byebug', platform: :mri
|
16
|
-
end
|
17
|
-
|
18
|
-
group :benchmarks do
|
19
|
-
gem 'sqlite3'
|
20
|
-
gem 'activerecord'
|
21
|
-
gem 'benchmark-ips'
|
22
|
-
gem 'virtus'
|
23
|
-
gem 'fast_attributes'
|
24
|
-
gem 'attrio'
|
25
|
-
gem 'hotch'
|
26
|
-
end
|
data/Rakefile
DELETED
data/benchmarks/basic.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'dry/struct'
|
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 DryStructUser < Dry::Struct
|
45
|
-
attributes(name: 'strict.string', age: 'params.integer')
|
46
|
-
end
|
47
|
-
|
48
|
-
puts DryStructUser.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-struct') { DryStructUser.new(name: 'Jane', age: '21') }
|
55
|
-
|
56
|
-
x.compare!
|
57
|
-
end
|
data/benchmarks/constrained.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'dry/struct'
|
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
|
21
|
-
end
|
22
|
-
|
23
|
-
class DryStructUser < Dry::Struct
|
24
|
-
attribute :id, Types::Params::Integer
|
25
|
-
attribute :name, Types::Strict::String.constrained(size: 3..64)
|
26
|
-
attribute :age, Types::Params::Integer.constrained(gt: 18)
|
27
|
-
end
|
28
|
-
|
29
|
-
puts ARUser.new(id: 1, name: 'Jane', age: '21').inspect
|
30
|
-
puts DryStructUser.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-struct') { DryStructUser.new(id: 1, name: 'Jane', age: '21') }
|
35
|
-
|
36
|
-
x.compare!
|
37
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require_relative 'setup'
|
2
|
-
|
3
|
-
ATTR_NAMES = [:attr0, :attr1, :attr2, :attr3, :attr4, :attr5, :attr6, :attr7, :attr8, :attr9]
|
4
|
-
|
5
|
-
class Integers < Dry::Struct
|
6
|
-
ATTR_NAMES.each do |name|
|
7
|
-
attribute? name, 'coercible.integer'
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
integers = {attr0: 0, attr1: 1, attr2: 2, attr3: 3, attr4: 4, attr5: 5, attr6: 6, attr7: 7, attr8: 8, attr9: 9}
|
12
|
-
|
13
|
-
require 'pry-byebug'
|
14
|
-
|
15
|
-
profile do
|
16
|
-
1_000_000.times do
|
17
|
-
Integers.new(integers)
|
18
|
-
end
|
19
|
-
end
|
data/benchmarks/setup.rb
DELETED
data/bin/console
DELETED
data/bin/setup
DELETED
data/log/.gitkeep
DELETED
File without changes
|