entity_schema 0.1.0 → 0.1.1
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 +4 -4
- data/.travis.yml +0 -2
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +15 -1
- data/README.md +56 -36
- data/entity_schema.gemspec +6 -3
- data/lib/entity_schema/fields/abstract.rb +2 -0
- data/lib/entity_schema/fields/builders/abstract.rb +2 -0
- data/lib/entity_schema/version.rb +1 -1
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 175e615c64727f0402ec59b48af5500e84138f10c545f1da46463329d877e538
|
4
|
+
data.tar.gz: 7333bf377c6e6027565d2ff7a1dbf0083f56043db6529e6127df3f7519bd972a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20945880185e2307906a80acc9b20ab28e0b3510fcb984c0dd40f7e569166d7d1b8608df5393c645fe046f556f645ff4954ac720b14b183d1da7a31f7065aeb6
|
7
|
+
data.tar.gz: acaefb4a8fbe2d7cfd450e03354938a5022604822a3553e083434ac6041a5a46c8a9d44b018be073758226608a8a3fec3563478f57406598e7f630ffb95c1941
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [0.1.1]
|
8
|
+
### Added (development-only)
|
9
|
+
+ SimpleCov
|
10
|
+
+ CodeCov
|
11
|
+
|
7
12
|
## [0.1.0]
|
8
13
|
### Added
|
9
14
|
+ All base functionality with main specs (141 example)
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
entity_schema (0.1.
|
4
|
+
entity_schema (0.1.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -9,8 +9,13 @@ GEM
|
|
9
9
|
byebug (10.0.2)
|
10
10
|
childprocess (0.9.0)
|
11
11
|
ffi (~> 1.0, >= 1.0.11)
|
12
|
+
codecov (0.1.10)
|
13
|
+
json
|
14
|
+
simplecov
|
15
|
+
url
|
12
16
|
coderay (1.1.2)
|
13
17
|
diff-lcs (1.3)
|
18
|
+
docile (1.3.1)
|
14
19
|
ffi (1.9.25)
|
15
20
|
formatador (0.2.5)
|
16
21
|
guard (2.14.2)
|
@@ -32,6 +37,7 @@ GEM
|
|
32
37
|
guard-compat (~> 1.1)
|
33
38
|
rspec (>= 2.99.0, < 4.0)
|
34
39
|
iniparse (1.4.4)
|
40
|
+
json (2.1.0)
|
35
41
|
listen (3.1.5)
|
36
42
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
37
43
|
rb-inotify (~> 0.9, >= 0.9.7)
|
@@ -70,7 +76,13 @@ GEM
|
|
70
76
|
rspec-support (3.8.0)
|
71
77
|
ruby_dep (1.5.0)
|
72
78
|
shellany (0.0.1)
|
79
|
+
simplecov (0.16.1)
|
80
|
+
docile (~> 1.1)
|
81
|
+
json (>= 1.8, < 3)
|
82
|
+
simplecov-html (~> 0.10.0)
|
83
|
+
simplecov-html (0.10.2)
|
73
84
|
thor (0.20.0)
|
85
|
+
url (0.3.2)
|
74
86
|
|
75
87
|
PLATFORMS
|
76
88
|
ruby
|
@@ -78,6 +90,7 @@ PLATFORMS
|
|
78
90
|
DEPENDENCIES
|
79
91
|
bundler (~> 1.16)
|
80
92
|
byebug
|
93
|
+
codecov
|
81
94
|
entity_schema!
|
82
95
|
guard
|
83
96
|
guard-bundler
|
@@ -87,6 +100,7 @@ DEPENDENCIES
|
|
87
100
|
pry-byebug
|
88
101
|
rake (~> 10.0)
|
89
102
|
rspec (~> 3.0)
|
103
|
+
simplecov
|
90
104
|
|
91
105
|
BUNDLED WITH
|
92
106
|
1.16.3
|
data/README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# EntitySchema
|
2
|
-
|
2
|
+
[](https://badge.fury.io/rb/entity_schema)
|
3
|
+
[](https://travis-ci.org/CaptainPhilipp/entity_schema)
|
4
|
+
[](https://codecov.io/gh/CaptainPhilipp/entity_schema)
|
3
5
|
|
4
|
-
|
6
|
+
Class-level DSL for mapping Hash with object-like structure to Object (as Entity), and then return it into Hash.
|
5
7
|
|
6
|
-
#### Describe entity structure:
|
7
8
|
```ruby
|
8
9
|
class Product
|
9
10
|
property :id
|
@@ -16,12 +17,29 @@ class Product
|
|
16
17
|
|
17
18
|
object :size, map_to: Values::Size
|
18
19
|
|
19
|
-
belongs_to :color,
|
20
|
-
has_many :seasons,
|
20
|
+
belongs_to :color, map_to: Color, pk: :color_uid, fk: :uid
|
21
|
+
has_many :seasons, map_to: Season
|
21
22
|
end
|
22
23
|
```
|
23
24
|
|
24
|
-
|
25
|
+
## Motivation
|
26
|
+
|
27
|
+
When you work with plain hashes (`Sequel`, `ROM`, `json`/`xml`-sourced data, etc), and want to describe some ___entities___ or ___value objects___ (DDD patterns).
|
28
|
+
|
29
|
+
Ok, if `ROM`, why not `ROM::Struct`?
|
30
|
+
|
31
|
+
If you using `ROM` with it's `ROM::Struct`, you may encounter some things that do not satisfy some needs: private attributes, value object mapping, may be something other.
|
32
|
+
|
33
|
+
## Installation
|
34
|
+
|
35
|
+
in Gemfile add
|
36
|
+
```
|
37
|
+
gem 'entity_schema'
|
38
|
+
```
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
|
42
|
+
### Create entity from hash:
|
25
43
|
```ruby
|
26
44
|
raw_hash = {
|
27
45
|
id: 42,
|
@@ -51,20 +69,20 @@ product.color_uid # => nil
|
|
51
69
|
|
52
70
|
#### Return entity to hash:
|
53
71
|
```ruby
|
54
|
-
product.to_h
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
72
|
+
product.to_h # =>
|
73
|
+
{
|
74
|
+
id: 42,
|
75
|
+
title: 'Perfect product',
|
76
|
+
enabled: true,
|
77
|
+
is_new: false,
|
78
|
+
is_sale: false,
|
79
|
+
is_bestseller: true,
|
80
|
+
created_at: '2018-08-16 20:17:55 UTC',
|
81
|
+
updated_at: '2018-08-16 20:17:55 UTC',
|
82
|
+
size: { ... size params ... },
|
83
|
+
color_uid: nil,
|
84
|
+
seasons: [{ ... seasons params ... }, {...}, ...]
|
85
|
+
}
|
68
86
|
```
|
69
87
|
|
70
88
|
## Validations, and coercions
|
@@ -73,42 +91,44 @@ No. Entity assumes that given data already validated and coerced.
|
|
73
91
|
|
74
92
|
## DSL
|
75
93
|
|
76
|
-
|
94
|
+
### `property`
|
77
95
|
|
78
|
-
|
96
|
+
_TODO: description_
|
79
97
|
|
80
|
-
|
98
|
+
### `property?`
|
81
99
|
|
82
|
-
|
100
|
+
_TODO: description_
|
83
101
|
|
84
|
-
|
102
|
+
### `timestamps`
|
85
103
|
|
86
|
-
|
104
|
+
_Not implemented_
|
105
|
+
|
106
|
+
Just sugar, same as:
|
87
107
|
```ruby
|
88
108
|
property :created_at, **opts
|
89
109
|
property :updated_at, **opts
|
90
110
|
```
|
91
111
|
|
92
|
-
|
112
|
+
### `object`
|
93
113
|
|
94
|
-
|
114
|
+
_TODO: description_
|
95
115
|
|
96
|
-
|
116
|
+
### `collection`
|
97
117
|
|
98
|
-
|
118
|
+
_TODO: description_
|
99
119
|
|
100
|
-
|
120
|
+
### `has_one`
|
101
121
|
|
102
|
-
|
122
|
+
Just alias for `object`
|
103
123
|
|
104
|
-
|
124
|
+
### `has_many`
|
105
125
|
|
106
126
|
Just alias for `collection`
|
107
127
|
|
108
|
-
|
128
|
+
### `belongs_to`
|
109
129
|
|
110
|
-
|
130
|
+
_TODO: description_
|
111
131
|
|
112
132
|
## Instance methods
|
113
133
|
|
114
|
-
|
134
|
+
_TODO: description_
|
data/entity_schema.gemspec
CHANGED
@@ -12,8 +12,8 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.email = ['ph-s@mail.ru']
|
13
13
|
|
14
14
|
spec.summary = 'DSL for describe Entities'
|
15
|
-
spec.description = 'DSL for describe
|
16
|
-
'
|
15
|
+
spec.description = 'Simple DSL for describe schema of mapping Hash to entity Object, ' \
|
16
|
+
'and then vice-versa'
|
17
17
|
spec.homepage = 'https://github.com/CaptainPhilipp/entity_schema'
|
18
18
|
spec.license = 'MIT'
|
19
19
|
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
24
24
|
else
|
25
25
|
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
26
|
-
|
26
|
+
'public gem pushes.'
|
27
27
|
end
|
28
28
|
|
29
29
|
# Specify which files should be added to the gem when it is released.
|
@@ -43,6 +43,9 @@ Gem::Specification.new do |spec|
|
|
43
43
|
spec.add_development_dependency 'rake', '~> 10.0'
|
44
44
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
45
45
|
|
46
|
+
spec.add_development_dependency 'codecov'
|
47
|
+
spec.add_development_dependency 'simplecov'
|
48
|
+
|
46
49
|
spec.add_development_dependency 'guard'
|
47
50
|
spec.add_development_dependency 'guard-bundler'
|
48
51
|
spec.add_development_dependency 'guard-rspec'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: entity_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Captain Philipp
|
@@ -108,6 +108,34 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: codecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
- !ruby/object:Gem::Dependency
|
112
140
|
name: guard
|
113
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,8 +178,8 @@ dependencies:
|
|
150
178
|
- - ">="
|
151
179
|
- !ruby/object:Gem::Version
|
152
180
|
version: '0'
|
153
|
-
description: DSL for describe
|
154
|
-
|
181
|
+
description: Simple DSL for describe schema of mapping Hash to entity Object, and
|
182
|
+
then vice-versa
|
155
183
|
email:
|
156
184
|
- ph-s@mail.ru
|
157
185
|
executables: []
|