sdl 0.2.1 → 0.5.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 +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/association.rb +15 -5
- data/lib/sdl/attribute.rb +7 -1
- data/lib/sdl/enum.rb +11 -4
- data/lib/sdl/field.rb +29 -8
- data/lib/sdl/model.rb +58 -19
- data/lib/sdl/name.rb +48 -0
- data/lib/sdl/parser.rb +14 -10
- data/lib/sdl/version.rb +1 -1
- metadata +6 -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
|
+

|
6
|
+

|
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/association.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require "sdl/field"
|
2
|
-
require "active_support/
|
2
|
+
require "active_support/inflector"
|
3
3
|
|
4
4
|
module SDL
|
5
5
|
# Base class for all association types
|
6
6
|
# @abstract
|
7
7
|
class Association < Field
|
8
8
|
# The name of the associated model
|
9
|
-
# @return [
|
9
|
+
# @return [Name]
|
10
10
|
def model_name
|
11
|
-
options.fetch(:model_name, name).to_s
|
11
|
+
Name.new(options.fetch(:model_name, name).to_s)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -30,9 +30,13 @@ module SDL
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# The name of the associated model
|
33
|
-
# @return [
|
33
|
+
# @return [Name]
|
34
34
|
def model_name
|
35
|
-
options.fetch(:model_name)
|
35
|
+
model_name = options.fetch(:model_name) do
|
36
|
+
ActiveSupport::Inflector.singularize(name.to_s)
|
37
|
+
end
|
38
|
+
|
39
|
+
Name.new(model_name.to_s)
|
36
40
|
end
|
37
41
|
end
|
38
42
|
|
@@ -51,5 +55,11 @@ module SDL
|
|
51
55
|
def foreign_key?
|
52
56
|
options.fetch(:foreign_key, false)
|
53
57
|
end
|
58
|
+
|
59
|
+
# The name of the column
|
60
|
+
# @return [Name]
|
61
|
+
def column_name
|
62
|
+
Name.new("#{name}_id")
|
63
|
+
end
|
54
64
|
end
|
55
65
|
end
|
data/lib/sdl/attribute.rb
CHANGED
@@ -11,8 +11,14 @@ module SDL
|
|
11
11
|
|
12
12
|
# @api private
|
13
13
|
def initialize(name, type, **options)
|
14
|
-
super(name, options)
|
14
|
+
super(name, **options)
|
15
15
|
@type = type
|
16
16
|
end
|
17
|
+
|
18
|
+
# The name of the column
|
19
|
+
# @return [Name]
|
20
|
+
def column_name
|
21
|
+
name
|
22
|
+
end
|
17
23
|
end
|
18
24
|
end
|
data/lib/sdl/enum.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "sdl/field"
|
2
|
+
require "sdl/name"
|
2
3
|
|
3
4
|
module SDL
|
4
5
|
# A field of a {Model} that has a predefined list of possible values
|
@@ -12,15 +13,21 @@ module SDL
|
|
12
13
|
end
|
13
14
|
|
14
15
|
# A default value for this field
|
15
|
-
# @return [
|
16
|
+
# @return [Name]
|
16
17
|
def default
|
17
|
-
options[:default]
|
18
|
+
Name.new(options[:default].to_s) if options[:default]
|
18
19
|
end
|
19
20
|
|
20
21
|
# The possible values for the enum
|
21
|
-
# @return [Array<
|
22
|
+
# @return [Array<Name>]
|
22
23
|
def values
|
23
|
-
options.fetch(:values, []).map(
|
24
|
+
options.fetch(:values, []).map { |value| Name.new(value.to_s) }
|
25
|
+
end
|
26
|
+
|
27
|
+
# The name of the column
|
28
|
+
# @return [Name]
|
29
|
+
def column_name
|
30
|
+
name
|
24
31
|
end
|
25
32
|
end
|
26
33
|
end
|
data/lib/sdl/field.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "sdl/name"
|
1
2
|
require "sdl/types"
|
2
3
|
|
3
4
|
module SDL
|
@@ -5,7 +6,7 @@ module SDL
|
|
5
6
|
# @abstract
|
6
7
|
class Field
|
7
8
|
# The name of the field
|
8
|
-
# @return [
|
9
|
+
# @return [Name]
|
9
10
|
attr_reader :name
|
10
11
|
|
11
12
|
# All options that were passed to the field
|
@@ -14,7 +15,7 @@ module SDL
|
|
14
15
|
|
15
16
|
# @api private
|
16
17
|
def initialize(name, **options)
|
17
|
-
@name = name.to_s
|
18
|
+
@name = Name.new(name.to_s)
|
18
19
|
@options = options
|
19
20
|
end
|
20
21
|
|
@@ -36,6 +37,32 @@ module SDL
|
|
36
37
|
has_one? || has_many? || belongs_to?
|
37
38
|
end
|
38
39
|
|
40
|
+
# Can this field be null? By default, this is `false`. But, it can
|
41
|
+
# be overridden by passing `nullable: true` to a field.
|
42
|
+
# @return [Boolean]
|
43
|
+
def nullable?
|
44
|
+
options.fetch(:nullable, false)
|
45
|
+
end
|
46
|
+
|
47
|
+
# The opposite of {#nullable?}. All fields are required by default
|
48
|
+
# @return [Boolean]
|
49
|
+
def required?
|
50
|
+
!nullable?
|
51
|
+
end
|
52
|
+
|
53
|
+
# The type of the field
|
54
|
+
# @abstract
|
55
|
+
# @return [Symbol]
|
56
|
+
def type
|
57
|
+
raise NotImplementedError, __method__
|
58
|
+
end
|
59
|
+
|
60
|
+
# The name of the type
|
61
|
+
# @return [Name]
|
62
|
+
def type_name
|
63
|
+
Name.new(type.to_s)
|
64
|
+
end
|
65
|
+
|
39
66
|
# @!method id?
|
40
67
|
# Indicates that this is an {Attribute} whose type is `:id`
|
41
68
|
# @return [Boolean]
|
@@ -91,12 +118,6 @@ module SDL
|
|
91
118
|
end
|
92
119
|
|
93
120
|
module ColumnOptions
|
94
|
-
# Is this field required?
|
95
|
-
# @return [Boolean]
|
96
|
-
def required?
|
97
|
-
options.fetch(:required, false)
|
98
|
-
end
|
99
|
-
|
100
121
|
# A default value for this field
|
101
122
|
# @return [Object]
|
102
123
|
def default
|
data/lib/sdl/model.rb
CHANGED
@@ -1,34 +1,55 @@
|
|
1
|
-
require "sdl/attribute"
|
2
|
-
require "sdl/enum"
|
3
1
|
require "sdl/association"
|
4
2
|
require "sdl/attachment"
|
3
|
+
require "sdl/attribute"
|
4
|
+
require "sdl/enum"
|
5
|
+
require "sdl/name"
|
5
6
|
|
6
7
|
module SDL
|
7
8
|
class Model
|
8
9
|
# Name of the model
|
9
|
-
# @return [
|
10
|
+
# @return [Name]
|
10
11
|
attr_reader :name
|
11
12
|
|
12
|
-
# All of the fields that have been registered
|
13
|
-
# @return [Array<Field>]
|
14
|
-
attr_reader :fields
|
15
|
-
|
16
13
|
# Any additional options
|
17
14
|
# @return [Hash]
|
18
15
|
attr_reader :options
|
19
16
|
|
20
17
|
# @api private
|
21
18
|
def initialize(name, fields: [], **options, &block)
|
22
|
-
@name = name.to_s
|
19
|
+
@name = Name.new(name.to_s)
|
23
20
|
@fields = fields
|
24
21
|
@options = options
|
25
22
|
instance_eval(&block) if block_given?
|
26
23
|
end
|
27
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
|
+
|
28
49
|
# Adds an {Attribute} to the model
|
29
50
|
# @param name [Symbol]
|
30
51
|
# @param type [Symbol]
|
31
|
-
# @option options [Boolean] :
|
52
|
+
# @option options [Boolean] :nullable
|
32
53
|
# @option options [Boolean] :unique
|
33
54
|
# @option options [Object] :default
|
34
55
|
# @option options [Integer] :limit
|
@@ -46,7 +67,7 @@ module SDL
|
|
46
67
|
# Adds an {Enum} to the model
|
47
68
|
# @param name [Symbol]
|
48
69
|
# @option options [Array<Symbol>] :values
|
49
|
-
# @option options [Boolean] :
|
70
|
+
# @option options [Boolean] :nullable
|
50
71
|
# @option options [Boolean] :unique
|
51
72
|
# @option options [Object] :default
|
52
73
|
#
|
@@ -61,7 +82,7 @@ module SDL
|
|
61
82
|
# Adds an {Association::BelongsTo} to the model
|
62
83
|
# @param name [Symbol]
|
63
84
|
# @option options [Symbol] :model_name
|
64
|
-
# @option options [Boolean] :
|
85
|
+
# @option options [Boolean] :nullable
|
65
86
|
# @option options [Boolean] :unique
|
66
87
|
# @option options [Boolean] :foreign_key
|
67
88
|
#
|
@@ -76,6 +97,7 @@ module SDL
|
|
76
97
|
# Adds an {Association::HasOne} to the model
|
77
98
|
# @param name [Symbol]
|
78
99
|
# @option options [Symbol] :model_name
|
100
|
+
# @option options [Boolean] :nullable
|
79
101
|
#
|
80
102
|
# @example
|
81
103
|
# model :user do
|
@@ -99,7 +121,7 @@ module SDL
|
|
99
121
|
|
100
122
|
# Adds an {Attachment::HasOne} to the model
|
101
123
|
# @param name [Symbol]
|
102
|
-
# @option options [
|
124
|
+
# @option options [Symbol] :nullable
|
103
125
|
#
|
104
126
|
# @example
|
105
127
|
# model :user do
|
@@ -133,75 +155,92 @@ module SDL
|
|
133
155
|
end
|
134
156
|
|
135
157
|
# Get all {Attribute} fields
|
158
|
+
# @deprecated Use {#fields} instead
|
136
159
|
# @return [Array<Attribute>]
|
137
160
|
def attribute_fields
|
138
|
-
fields
|
161
|
+
fields(:attribute)
|
139
162
|
end
|
140
163
|
|
141
164
|
# Get all {Association} fields
|
165
|
+
# @deprecated Use {#fields} instead
|
142
166
|
# @return [Array<Association>]
|
143
167
|
def association_fields
|
144
|
-
fields
|
168
|
+
fields(:association)
|
145
169
|
end
|
146
170
|
|
147
171
|
# Get all {Attachment} fields
|
172
|
+
# @deprecated Use {#fields} instead
|
148
173
|
# @return [Array<Attachment>]
|
149
174
|
def attachment_fields
|
150
|
-
fields
|
175
|
+
fields(:attachment)
|
151
176
|
end
|
152
177
|
|
153
178
|
# @!method id_fields
|
154
179
|
# Get all {Attribute} fields whose type is `:id`
|
180
|
+
# @deprecated Use {#fields} instead
|
155
181
|
# @return [Array<Attribute>]
|
156
182
|
# @!method string_fields
|
157
183
|
# Get all {Attribute} fields whose type is `:string`
|
184
|
+
# @deprecated Use {#fields} instead
|
158
185
|
# @return [Array<Attribute>]
|
159
186
|
# @!method boolean_fields
|
160
187
|
# Get all {Attribute} fields whose type is `:boolean`
|
188
|
+
# @deprecated Use {#fields} instead
|
161
189
|
# @return [Array<Attribute>]
|
162
190
|
# @!method integer_fields
|
163
191
|
# Get all {Attribute} fields whose type is `:integer`
|
192
|
+
# @deprecated Use {#fields} instead
|
164
193
|
# @return [Array<Attribute>]
|
165
194
|
# @!method float_fields
|
166
195
|
# Get all {Attribute} fields whose type is `:float`
|
196
|
+
# @deprecated Use {#fields} instead
|
167
197
|
# @return [Array<Attribute>]
|
168
198
|
# @!method decimal_fields
|
169
199
|
# Get all {Attribute} fields whose type is `:decimal`
|
200
|
+
# @deprecated Use {#fields} instead
|
170
201
|
# @return [Array<Attribute>]
|
171
202
|
# @!method date_fields
|
172
203
|
# Get all {Attribute} fields whose type is `:date`
|
204
|
+
# @deprecated Use {#fields} instead
|
173
205
|
# @return [Array<Attribute>]
|
174
206
|
# @!method datetime_fields
|
175
207
|
# Get all {Attribute} fields whose type is `:datetime`
|
208
|
+
# @deprecated Use {#fields} instead
|
176
209
|
# @return [Array<Attribute>]
|
177
210
|
# @!method text_fields
|
178
211
|
# Get all {Attribute} fields whose type is `:text`
|
212
|
+
# @deprecated Use {#fields} instead
|
179
213
|
# @return [Array<Attribute>]
|
180
214
|
# @!method binary_fields
|
181
215
|
# Get all {Attribute} fields whose type is `:binary`
|
216
|
+
# @deprecated Use {#fields} instead
|
182
217
|
# @return [Array<Attribute>]
|
183
218
|
# @!method enum_fields
|
184
219
|
# Get all {Enum} fields
|
220
|
+
# @deprecated Use {#fields} instead
|
185
221
|
# @return [Array<Enum>]
|
186
222
|
# @!method belongs_to_fields
|
187
223
|
# Get all {Association::BelongsTo} fields
|
224
|
+
# @deprecated Use {#fields} instead
|
188
225
|
# @return [Array<Association::BelongsTo>]
|
189
226
|
# @!method has_one_fields
|
190
227
|
# Get all {Association::HasOne} fields
|
228
|
+
# @deprecated Use {#fields} instead
|
191
229
|
# @return [Array<Assocation::HasOne>]
|
192
230
|
# @!method has_many_fields
|
193
231
|
# Get all {Association::HasMany} fields
|
232
|
+
# @deprecated Use {#fields} instead
|
194
233
|
# @return [Array<Association::HasMany>]
|
195
234
|
# @!method has_one_attached_fields
|
196
235
|
# Get all {Attachment::HasOne} fields
|
236
|
+
# @deprecated Use {#fields} instead
|
197
237
|
# @return [Array<Attachment::HasOne>]
|
198
238
|
# @!method has_many_attached_fields
|
199
239
|
# Get all {Attachment::HasMany} fields
|
240
|
+
# @deprecated Use {#fields} instead
|
200
241
|
# @return [Array<Attachment::HasMany>]
|
201
|
-
TYPES.each do |
|
202
|
-
define_method
|
203
|
-
fields.select { |field| field.type == meth }
|
204
|
-
end
|
242
|
+
TYPES.each do |type|
|
243
|
+
define_method("#{type}_fields") { fields(type) }
|
205
244
|
end
|
206
245
|
end
|
207
246
|
end
|
data/lib/sdl/name.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "active_support/inflector"
|
2
|
+
|
3
|
+
module SDL
|
4
|
+
# An extension of a string that will format a name
|
5
|
+
class Name < String
|
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
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
inflect :table, %i[tableize]
|
30
|
+
inflect :plural, %i[pluralize]
|
31
|
+
inflect :snake, %i[underscore]
|
32
|
+
inflect :snakes, %i[underscore pluralize]
|
33
|
+
inflect :scream, %i[underscore upcase]
|
34
|
+
inflect :screams, %i[pluralize underscore upcase]
|
35
|
+
inflect :camel, %i[lower_camelize]
|
36
|
+
inflect :camels, %i[pluralize lower_camelize]
|
37
|
+
inflect :param, %i[dasherize]
|
38
|
+
inflect :params, %i[pluralize dasherize]
|
39
|
+
inflect :entity, %i[camelize]
|
40
|
+
inflect :entities, %i[pluralize camelize]
|
41
|
+
inflect :title, %i[titleize]
|
42
|
+
inflect :titles, %i[pluralize titleize]
|
43
|
+
inflect :label, %i[humanize]
|
44
|
+
inflect :labels, %i[pluralize humanize]
|
45
|
+
inflect :description, %i[lower_humanize]
|
46
|
+
inflect :descriptions, %i[pluralize lower_humanize]
|
47
|
+
end
|
48
|
+
end
|
data/lib/sdl/parser.rb
CHANGED
@@ -4,7 +4,7 @@ require "sdl/enum"
|
|
4
4
|
require "sdl/attribute"
|
5
5
|
require "sdl/association"
|
6
6
|
require "sdl/attachment"
|
7
|
-
require "active_support/
|
7
|
+
require "active_support/inflector"
|
8
8
|
|
9
9
|
module SDL
|
10
10
|
# The parser takes a string and converts it to a {Field}.
|
@@ -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`
|
@@ -46,7 +46,7 @@ module SDL
|
|
46
46
|
# * `has_one_attached`
|
47
47
|
# * `has_many_attached`
|
48
48
|
# * `unique`
|
49
|
-
# * `
|
49
|
+
# * `nullable`
|
50
50
|
# * `index`
|
51
51
|
# * `foreign_key`
|
52
52
|
# * `default{value}`
|
@@ -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
|
|
@@ -86,7 +86,7 @@ module SDL
|
|
86
86
|
ASSOCIATION_WITH_NAME = /^(belongs_to|has_one|has_many)\{(.*)\}$/
|
87
87
|
|
88
88
|
DEFAULT = /^default\{(.*)\}$/
|
89
|
-
MODIFIERS = %w[
|
89
|
+
MODIFIERS = %w[nullable unique index foreign_key]
|
90
90
|
|
91
91
|
def parse!(arg, opts)
|
92
92
|
case arg
|
@@ -103,12 +103,12 @@ module SDL
|
|
103
103
|
opts[:type] = Enum
|
104
104
|
opts[:values] = $1.split(SEPARATOR)
|
105
105
|
when ASSOCIATION
|
106
|
-
opts[:type] = Association.const_get($1
|
106
|
+
opts[:type] = Association.const_get(camelize($1))
|
107
107
|
when ASSOCIATION_WITH_NAME
|
108
|
-
opts[:type] = Association.const_get($1
|
108
|
+
opts[:type] = Association.const_get(camelize($1))
|
109
109
|
opts[:model_name] = $2.to_sym
|
110
110
|
when ATTACHMENT
|
111
|
-
opts[:type] = Attachment.const_get($1
|
111
|
+
opts[:type] = Attachment.const_get(camelize($1))
|
112
112
|
when DEFAULT
|
113
113
|
opts[:default] = $1
|
114
114
|
when *MODIFIERS
|
@@ -118,6 +118,10 @@ module SDL
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
+
def camelize(value)
|
122
|
+
ActiveSupport::Inflector.camelize(value)
|
123
|
+
end
|
124
|
+
|
121
125
|
def coerce(value, type)
|
122
126
|
case type
|
123
127
|
when :integer then value.to_i
|
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
|
@@ -105,6 +106,7 @@ files:
|
|
105
106
|
- lib/sdl/enum.rb
|
106
107
|
- lib/sdl/field.rb
|
107
108
|
- lib/sdl/model.rb
|
109
|
+
- lib/sdl/name.rb
|
108
110
|
- lib/sdl/parser.rb
|
109
111
|
- lib/sdl/schema.rb
|
110
112
|
- lib/sdl/types.rb
|
@@ -132,8 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
134
|
- !ruby/object:Gem::Version
|
133
135
|
version: '0'
|
134
136
|
requirements: []
|
135
|
-
|
136
|
-
rubygems_version: 2.6.14
|
137
|
+
rubygems_version: 3.1.2
|
137
138
|
signing_key:
|
138
139
|
specification_version: 4
|
139
140
|
summary: A generic schema definition language.
|