dto_schema 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e5c58baab04f8cdf46c9772682dd02c47de4f6d1ab30d8104d8b19d2978060b6
4
+ data.tar.gz: acc3fa9351ce74f4eed4667c8baf183e0f0d616ea0152c9ac7d22d4ae9be1c54
5
+ SHA512:
6
+ metadata.gz: feaf6f8e2f9f78315f67cefb874c5b269989229b4de33bfea5f910b291edaddf37ff6b1a2f91cf0c032087291cbaf2ab1beb469b7ab2c10153f99fd5399b9449
7
+ data.tar.gz: 9d4296c13f3b8542fa81bddf160906405a2c8e9fa1fc1c2a812656ac685c5cd540d8e1f5c67ddf76109fff0757517028cb4fb8d437f5d159559eac8627fea217
data/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Stepan Anokhin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Ruby DTO-Schema
2
+
3
+ DTO-Schema is a small Ruby library to validate simple data.
4
+
5
+ ## What is validated?
6
+
7
+ A notion of `Simple Data` could be defined as follows:
8
+ * `nil` is a simple data
9
+ * `String` is a simple data
10
+ * `Numeric` is a simple data
11
+ * Boolean is a simple data
12
+ * `Array` of simple data is a simple data
13
+ * `Hash` with symbolic keys and simple-data values is a simple data
14
+
15
+ ## Example
16
+
17
+ Define a schema:
18
+ ```ruby
19
+ require 'dto_schema'
20
+
21
+ schema = DTO::Schema.new do
22
+ object :tag do
23
+ required :name, String, check: [:not_empty]
24
+ required :value, String, check: [:not_empty]
25
+ end
26
+
27
+ object :post do
28
+ required :title, String, check: [:not_empty]
29
+ required :body, String, check: [:not_empty]
30
+ optional :tags, list[:tag]
31
+ end
32
+
33
+ check :not_empty do |value|
34
+ next "Cannot be empty" if value.empty?
35
+ end
36
+ end
37
+ ```
38
+
39
+ And then use it to validate data:
40
+ ```ruby
41
+ require 'json'
42
+
43
+ data = JSON.parse('{"title": 42, "tags":[42, {"name":"", "value":"foo"}]}', symbolize_names: true)
44
+ p schema.post.validate data
45
+ ```
46
+
47
+ And result will be:
48
+ ```
49
+ {:title=>["Must be a String"], :body=>["Cannot be null"], :tags=>{0=>["Must be object"], 1=>{:name=>["Cannot be empty"]}}}
50
+ ```
51
+
@@ -0,0 +1,16 @@
1
+ lib = File.expand_path("../lib/", __FILE__)
2
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
3
+ require "dto_schema/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'dto_schema'
7
+ s.version = DTOSchema::VERSION
8
+ s.date = '2019-10-28'
9
+ s.description = "A small library to validate simple data."
10
+ s.summary = s.description
11
+ s.authors = ["Stepan Anokhin"]
12
+ s.email = 'stepan.anokhin@gmail.com'
13
+ s.files = %w(dto_schema.gemspec) + Dir["*.md", "lib/**/*.rb"]
14
+ s.homepage = 'https://github.com/stepan-anokhin/dto-schema'
15
+ s.license = 'MIT'
16
+ end
@@ -0,0 +1,3 @@
1
+ module DTOSchema
2
+ VERSION = "0.0.0"
3
+ end
data/lib/dto_schema.rb ADDED
@@ -0,0 +1,5 @@
1
+ module DTOSchema
2
+ class Schema
3
+
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dto_schema
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Stepan Anokhin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A small library to validate simple data.
14
+ email: stepan.anokhin@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE.md
20
+ - README.md
21
+ - dto_schema.gemspec
22
+ - lib/dto_schema.rb
23
+ - lib/dto_schema/version.rb
24
+ homepage: https://github.com/stepan-anokhin/dto-schema
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubygems_version: 3.0.3
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: A small library to validate simple data.
47
+ test_files: []