dry-struct 1.0.0 → 1.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.
data/.yardopts DELETED
@@ -1,4 +0,0 @@
1
- --title 'dry-struct'
2
- --markup markdown
3
- --readme README.md
4
- lib/**/*.rb
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
@@ -1,10 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
7
-
8
- require 'yard'
9
- require 'yard/rake/yardoc_task'
10
- YARD::Rake::YardocTask.new(:doc)
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
@@ -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
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'benchmark/ips'
4
- require 'hotch'
5
- ENV['HOTCH_VIEWER'] ||= 'open'
6
-
7
- require 'dry-struct'
8
-
9
- def profile(&block)
10
- Hotch(filter: 'Dry', &block)
11
- end
data/bin/console DELETED
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'dry/struct'
5
-
6
- require 'irb'
7
-
8
- module Types
9
- include Dry.Types
10
- end
11
-
12
- binding.irb
data/bin/setup DELETED
@@ -1,7 +0,0 @@
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
data/log/.gitkeep DELETED
File without changes