sdl 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/build.yml +22 -0
- data/.github/workflows/publish.yml +38 -0
- data/Gemfile +2 -0
- data/README.md +24 -11
- data/Rakefile +2 -2
- data/lib/sdl.rb +0 -1
- data/lib/sdl/attribute.rb +1 -1
- data/lib/sdl/enum.rb +1 -1
- data/lib/sdl/model.rb +48 -11
- data/lib/sdl/name.rb +18 -14
- data/lib/sdl/parser.rb +4 -4
- data/lib/sdl/version.rb +1 -1
- metadata +5 -5
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c83558361e4cc4d117a79eeafb41bc88282ab58787bae3392b2a322c7f2725ee
|
4
|
+
data.tar.gz: d15a86beac0656606ebffd86a6b2e928f2218ce307ed576c381593f157b3f3e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 607eb1f7253d0f6645d5076b7cfba2305a303ad11e35ee182fbcdea597609d9759bd4d7f673301f658b85e00baf5a31cf6923240fc48891a78c1076deb099a1f
|
7
|
+
data.tar.gz: 07b880a3864b82b939a96812ba670e691d2ea8964227839eb5632111cd7323675f3eac1f9349c310e4580145d901c56d225d608f7587b358629e56de1efd90c0
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Build
|
2
|
+
on: [push]
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
runs-on: ubuntu-latest
|
6
|
+
steps:
|
7
|
+
- name: Checkout
|
8
|
+
uses: actions/checkout@v2
|
9
|
+
|
10
|
+
- name: Setup Ruby
|
11
|
+
uses: actions/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 2.7.x
|
14
|
+
|
15
|
+
- name: Install bundler
|
16
|
+
run: gem install bundler
|
17
|
+
|
18
|
+
- name: Install dependencies
|
19
|
+
run: bundle install
|
20
|
+
|
21
|
+
- name: Test
|
22
|
+
run: bundle exec rspec
|
@@ -0,0 +1,38 @@
|
|
1
|
+
name: Publish
|
2
|
+
on:
|
3
|
+
release:
|
4
|
+
types: [published]
|
5
|
+
jobs:
|
6
|
+
publish:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- name: Checkout
|
10
|
+
uses: actions/checkout@v2
|
11
|
+
|
12
|
+
- name: Setup Ruby
|
13
|
+
uses: actions/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 2.7.x
|
16
|
+
|
17
|
+
- name: Install bundler
|
18
|
+
run: gem install bundler
|
19
|
+
|
20
|
+
- name: Install dependencies
|
21
|
+
run: bundle install
|
22
|
+
|
23
|
+
- name: Test
|
24
|
+
run: bundle exec rspec
|
25
|
+
|
26
|
+
- name: Set version
|
27
|
+
run: perl -pi -e "s/0\.0\.0/${GITHUB_REF:11}/" lib/sdl/version.rb
|
28
|
+
|
29
|
+
- name: Publish
|
30
|
+
run: |
|
31
|
+
mkdir -p $HOME/.gem
|
32
|
+
touch $HOME/.gem/credentials
|
33
|
+
chmod 0600 $HOME/.gem/credentials
|
34
|
+
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_TOKEN}\n" > $HOME/.gem/credentials
|
35
|
+
gem build *.gemspec
|
36
|
+
gem push *.gem
|
37
|
+
env:
|
38
|
+
RUBYGEMS_TOKEN: ${{ secrets.RUBYGEMS_TOKEN }}
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
-
|
1
|
+
<h1 align="center">SDL</h1>
|
2
2
|
|
3
|
-
|
3
|
+
<div align="center">
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
![Build](https://github.com/rzane/sdl/workflows/Build/badge.svg)
|
6
|
+
![Version](https://img.shields.io/gem/v/sdl)
|
7
|
+
|
8
|
+
</div>
|
9
|
+
|
10
|
+
SDL stands for *S*chema *D*efinition *L*anguage. It's a language for describing models in a system.
|
11
|
+
|
12
|
+
Alone, it doesn't do a whole lot. However, you might find helpful for building [code generators](https://github.com/rzane/geny).
|
7
13
|
|
8
14
|
## Installation
|
9
15
|
|
@@ -28,15 +34,15 @@ Or install it yourself as:
|
|
28
34
|
```ruby
|
29
35
|
SDL.define do
|
30
36
|
model :user do
|
31
|
-
attribute :email, :string,
|
37
|
+
attribute :email, :string, unique: true
|
32
38
|
has_many :posts
|
33
39
|
timestamps
|
34
40
|
end
|
35
41
|
|
36
42
|
model :post do
|
37
|
-
attribute :title, :string, limit: 120
|
38
|
-
attribute :body, :text
|
39
|
-
enum :status, values: [:draft, :published]
|
43
|
+
attribute :title, :string, limit: 120
|
44
|
+
attribute :body, :text, nullable: true
|
45
|
+
enum :status, values: [:draft, :published], default: :draft
|
40
46
|
belongs_to :user, foreign_key: true
|
41
47
|
has_one_attached :image
|
42
48
|
timestamps
|
@@ -46,6 +52,13 @@ end
|
|
46
52
|
|
47
53
|
### Load a schema from a file
|
48
54
|
|
55
|
+
```ruby
|
56
|
+
# schema.rb
|
57
|
+
model :user do
|
58
|
+
attribute :name, :string
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
49
62
|
```ruby
|
50
63
|
SDL.load_file "schema.rb"
|
51
64
|
```
|
@@ -54,13 +67,13 @@ SDL.load_file "schema.rb"
|
|
54
67
|
|
55
68
|
```ruby
|
56
69
|
SDL.parse "user", %w[
|
57
|
-
email:
|
70
|
+
email:unique
|
58
71
|
posts:has_many
|
59
72
|
]
|
60
73
|
|
61
74
|
SDL.parse "post", %w[
|
62
|
-
title:string{120}
|
63
|
-
body:text
|
75
|
+
title:string{120}
|
76
|
+
body:text:nullable
|
64
77
|
status:enum{draft,published}
|
65
78
|
user:belongs_to:foreign_key
|
66
79
|
image:has_one_attached
|
data/Rakefile
CHANGED
data/lib/sdl.rb
CHANGED
data/lib/sdl/attribute.rb
CHANGED
data/lib/sdl/enum.rb
CHANGED
data/lib/sdl/model.rb
CHANGED
@@ -10,10 +10,6 @@ module SDL
|
|
10
10
|
# @return [Name]
|
11
11
|
attr_reader :name
|
12
12
|
|
13
|
-
# All of the fields that have been registered
|
14
|
-
# @return [Array<Field>]
|
15
|
-
attr_reader :fields
|
16
|
-
|
17
13
|
# Any additional options
|
18
14
|
# @return [Hash]
|
19
15
|
attr_reader :options
|
@@ -26,6 +22,30 @@ module SDL
|
|
26
22
|
instance_eval(&block) if block_given?
|
27
23
|
end
|
28
24
|
|
25
|
+
# List or filter fields that have been registered
|
26
|
+
# @param types [Array<Symbol>] types to filter
|
27
|
+
# @return [Array<Field>]
|
28
|
+
# @example List all fields
|
29
|
+
# model.fields.each { |field| puts field.name }
|
30
|
+
# @example Filter fields
|
31
|
+
# model.fields(:integer).each { |field| puts field.name }
|
32
|
+
def fields(*types)
|
33
|
+
return @fields if types.empty?
|
34
|
+
|
35
|
+
types.flat_map { |type|
|
36
|
+
case type
|
37
|
+
when :attribute
|
38
|
+
@fields.grep Attribute
|
39
|
+
when :association
|
40
|
+
@fields.grep Association
|
41
|
+
when :attachment
|
42
|
+
@fields.grep Attachment
|
43
|
+
else
|
44
|
+
@fields.select { |field| field.type == type }
|
45
|
+
end
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
29
49
|
# Adds an {Attribute} to the model
|
30
50
|
# @param name [Symbol]
|
31
51
|
# @param type [Symbol]
|
@@ -135,75 +155,92 @@ module SDL
|
|
135
155
|
end
|
136
156
|
|
137
157
|
# Get all {Attribute} fields
|
158
|
+
# @deprecated Use {#fields} instead
|
138
159
|
# @return [Array<Attribute>]
|
139
160
|
def attribute_fields
|
140
|
-
fields
|
161
|
+
fields(:attribute)
|
141
162
|
end
|
142
163
|
|
143
164
|
# Get all {Association} fields
|
165
|
+
# @deprecated Use {#fields} instead
|
144
166
|
# @return [Array<Association>]
|
145
167
|
def association_fields
|
146
|
-
fields
|
168
|
+
fields(:association)
|
147
169
|
end
|
148
170
|
|
149
171
|
# Get all {Attachment} fields
|
172
|
+
# @deprecated Use {#fields} instead
|
150
173
|
# @return [Array<Attachment>]
|
151
174
|
def attachment_fields
|
152
|
-
fields
|
175
|
+
fields(:attachment)
|
153
176
|
end
|
154
177
|
|
155
178
|
# @!method id_fields
|
156
179
|
# Get all {Attribute} fields whose type is `:id`
|
180
|
+
# @deprecated Use {#fields} instead
|
157
181
|
# @return [Array<Attribute>]
|
158
182
|
# @!method string_fields
|
159
183
|
# Get all {Attribute} fields whose type is `:string`
|
184
|
+
# @deprecated Use {#fields} instead
|
160
185
|
# @return [Array<Attribute>]
|
161
186
|
# @!method boolean_fields
|
162
187
|
# Get all {Attribute} fields whose type is `:boolean`
|
188
|
+
# @deprecated Use {#fields} instead
|
163
189
|
# @return [Array<Attribute>]
|
164
190
|
# @!method integer_fields
|
165
191
|
# Get all {Attribute} fields whose type is `:integer`
|
192
|
+
# @deprecated Use {#fields} instead
|
166
193
|
# @return [Array<Attribute>]
|
167
194
|
# @!method float_fields
|
168
195
|
# Get all {Attribute} fields whose type is `:float`
|
196
|
+
# @deprecated Use {#fields} instead
|
169
197
|
# @return [Array<Attribute>]
|
170
198
|
# @!method decimal_fields
|
171
199
|
# Get all {Attribute} fields whose type is `:decimal`
|
200
|
+
# @deprecated Use {#fields} instead
|
172
201
|
# @return [Array<Attribute>]
|
173
202
|
# @!method date_fields
|
174
203
|
# Get all {Attribute} fields whose type is `:date`
|
204
|
+
# @deprecated Use {#fields} instead
|
175
205
|
# @return [Array<Attribute>]
|
176
206
|
# @!method datetime_fields
|
177
207
|
# Get all {Attribute} fields whose type is `:datetime`
|
208
|
+
# @deprecated Use {#fields} instead
|
178
209
|
# @return [Array<Attribute>]
|
179
210
|
# @!method text_fields
|
180
211
|
# Get all {Attribute} fields whose type is `:text`
|
212
|
+
# @deprecated Use {#fields} instead
|
181
213
|
# @return [Array<Attribute>]
|
182
214
|
# @!method binary_fields
|
183
215
|
# Get all {Attribute} fields whose type is `:binary`
|
216
|
+
# @deprecated Use {#fields} instead
|
184
217
|
# @return [Array<Attribute>]
|
185
218
|
# @!method enum_fields
|
186
219
|
# Get all {Enum} fields
|
220
|
+
# @deprecated Use {#fields} instead
|
187
221
|
# @return [Array<Enum>]
|
188
222
|
# @!method belongs_to_fields
|
189
223
|
# Get all {Association::BelongsTo} fields
|
224
|
+
# @deprecated Use {#fields} instead
|
190
225
|
# @return [Array<Association::BelongsTo>]
|
191
226
|
# @!method has_one_fields
|
192
227
|
# Get all {Association::HasOne} fields
|
228
|
+
# @deprecated Use {#fields} instead
|
193
229
|
# @return [Array<Assocation::HasOne>]
|
194
230
|
# @!method has_many_fields
|
195
231
|
# Get all {Association::HasMany} fields
|
232
|
+
# @deprecated Use {#fields} instead
|
196
233
|
# @return [Array<Association::HasMany>]
|
197
234
|
# @!method has_one_attached_fields
|
198
235
|
# Get all {Attachment::HasOne} fields
|
236
|
+
# @deprecated Use {#fields} instead
|
199
237
|
# @return [Array<Attachment::HasOne>]
|
200
238
|
# @!method has_many_attached_fields
|
201
239
|
# Get all {Attachment::HasMany} fields
|
240
|
+
# @deprecated Use {#fields} instead
|
202
241
|
# @return [Array<Attachment::HasMany>]
|
203
|
-
TYPES.each do |
|
204
|
-
define_method
|
205
|
-
fields.select { |field| field.type == meth }
|
206
|
-
end
|
242
|
+
TYPES.each do |type|
|
243
|
+
define_method("#{type}_fields") { fields(type) }
|
207
244
|
end
|
208
245
|
end
|
209
246
|
end
|
data/lib/sdl/name.rb
CHANGED
@@ -2,21 +2,25 @@ require "active_support/inflector"
|
|
2
2
|
|
3
3
|
module SDL
|
4
4
|
# An extension of a string that will format a name
|
5
|
-
# This is especially useful for code generation
|
6
5
|
class Name < String
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
6
|
+
class << self
|
7
|
+
private
|
8
|
+
|
9
|
+
# @!macro [attach] inflect
|
10
|
+
# @return [String]
|
11
|
+
def inflect(name, transforms)
|
12
|
+
define_method(name) do
|
13
|
+
transforms.reduce(self) do |acc, arg|
|
14
|
+
case arg
|
15
|
+
when :upcase
|
16
|
+
acc.upcase
|
17
|
+
when :lower_camelize
|
18
|
+
ActiveSupport::Inflector.camelize(acc, false)
|
19
|
+
when :lower_humanize
|
20
|
+
ActiveSupport::Inflector.humanize(acc, capitalize: false)
|
21
|
+
else
|
22
|
+
ActiveSupport::Inflector.send(arg, acc)
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
data/lib/sdl/parser.rb
CHANGED
@@ -13,8 +13,8 @@ module SDL
|
|
13
13
|
#
|
14
14
|
# Examples:
|
15
15
|
#
|
16
|
-
# * `title:string{120}
|
17
|
-
# * `body:text`
|
16
|
+
# * `title:string{120}`
|
17
|
+
# * `body:text:nullable`
|
18
18
|
# * `status:enum{draft,published}`
|
19
19
|
# * `user:belongs_to:foreign_key`
|
20
20
|
# * `image:has_one_attached`
|
@@ -67,9 +67,9 @@ module SDL
|
|
67
67
|
opts[:default] = coerce(opts[:default], type) if opts[:default]
|
68
68
|
|
69
69
|
if type.is_a?(Symbol)
|
70
|
-
Attribute.new(name, type, opts)
|
70
|
+
Attribute.new(name, type, **opts)
|
71
71
|
else
|
72
|
-
type.new(name, opts)
|
72
|
+
type.new(name, **opts)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
data/lib/sdl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sdl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ray Zane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -87,9 +87,10 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
+
- ".github/workflows/build.yml"
|
91
|
+
- ".github/workflows/publish.yml"
|
90
92
|
- ".gitignore"
|
91
93
|
- ".rspec"
|
92
|
-
- ".travis.yml"
|
93
94
|
- ".yardopts"
|
94
95
|
- CODE_OF_CONDUCT.md
|
95
96
|
- Gemfile
|
@@ -133,8 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
134
|
- !ruby/object:Gem::Version
|
134
135
|
version: '0'
|
135
136
|
requirements: []
|
136
|
-
|
137
|
-
rubygems_version: 2.6.14
|
137
|
+
rubygems_version: 3.1.2
|
138
138
|
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: A generic schema definition language.
|