yaddl 0.0.6 → 0.0.7
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/README.md +199 -0
- data/lib/yaddl.rb +2 -2
- data/lib/yaddl/version.rb +1 -1
- data/test/dummy/log/test.log +30 -0
- data/test/yaddl_test.rb +31 -6
- metadata +2 -8
- data/test/dummy/app/models/related_model.rb +0 -5
- data/test/dummy/app/models/test_model.rb +0 -12
- data/test/dummy/db/schema.yaml +0 -21
data/README.md
CHANGED
|
@@ -4,6 +4,8 @@ This project rocks and uses MIT-LICENSE.
|
|
|
4
4
|
|
|
5
5
|
# Usage
|
|
6
6
|
|
|
7
|
+
`gem 'yaddl'`
|
|
8
|
+
|
|
7
9
|
```
|
|
8
10
|
rake yaddl:models
|
|
9
11
|
rake yaddl:migrations
|
|
@@ -67,3 +69,200 @@ Legend:
|
|
|
67
69
|
- !!{ruby_code} - unique ruby_code will be added to model only once
|
|
68
70
|
- if, unless, def, module, class - ruby code blocks (else and elsif are not currently supported at root)
|
|
69
71
|
- include, require, has_many, serialize, etc. - single line ruby methods
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
# Example Yaddl File
|
|
76
|
+
|
|
77
|
+
/db/photo_gallery.yaddl
|
|
78
|
+
```ruby
|
|
79
|
+
Gallery(name:string)
|
|
80
|
+
@Describable
|
|
81
|
+
@Commentable
|
|
82
|
+
|
|
83
|
+
User
|
|
84
|
+
|
|
85
|
+
*Photo(name:string)
|
|
86
|
+
@Describable
|
|
87
|
+
@Commentable
|
|
88
|
+
|
|
89
|
+
User
|
|
90
|
+
|
|
91
|
+
photographer:User
|
|
92
|
+
*participant:User
|
|
93
|
+
|
|
94
|
+
taken_at:datetime
|
|
95
|
+
|
|
96
|
+
-image_src:text
|
|
97
|
+
-thumb_src:text
|
|
98
|
+
|
|
99
|
+
before_save :generate_thumbnail
|
|
100
|
+
def generate_thumbnail
|
|
101
|
+
# generate a thumbnail from image_drc for thumb_src
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
User(email:string)
|
|
105
|
+
!!{has_secure_password}
|
|
106
|
+
name:string
|
|
107
|
+
email:string
|
|
108
|
+
password_digest:string
|
|
109
|
+
attr_accessible :password
|
|
110
|
+
=to_s{email}
|
|
111
|
+
|
|
112
|
+
@Describable
|
|
113
|
+
description:text
|
|
114
|
+
|
|
115
|
+
@Commentable
|
|
116
|
+
*Comment
|
|
117
|
+
@Commentable
|
|
118
|
+
User
|
|
119
|
+
approved:boolean
|
|
120
|
+
def approve!
|
|
121
|
+
self.update_columns(approved: true)
|
|
122
|
+
end
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
# Example Output
|
|
126
|
+
|
|
127
|
+
### Migrations
|
|
128
|
+
|
|
129
|
+
/db/schema.rb
|
|
130
|
+
```ruby
|
|
131
|
+
ActiveRecord::Schema.define(version: 20140318005217) do
|
|
132
|
+
|
|
133
|
+
create_table "comments", force: true do |t|
|
|
134
|
+
t.boolean "approved"
|
|
135
|
+
t.integer "gallery_id"
|
|
136
|
+
t.integer "photo_id"
|
|
137
|
+
t.integer "comment_id"
|
|
138
|
+
t.datetime "created_at"
|
|
139
|
+
t.datetime "updated_at"
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
add_index "comments", ["comment_id"], name: "index_comments_on_comment_id"
|
|
143
|
+
add_index "comments", ["gallery_id"], name: "index_comments_on_gallery_id"
|
|
144
|
+
add_index "comments", ["photo_id"], name: "index_comments_on_photo_id"
|
|
145
|
+
|
|
146
|
+
create_table "galleries", force: true do |t|
|
|
147
|
+
t.string "name"
|
|
148
|
+
t.text "description"
|
|
149
|
+
t.datetime "created_at"
|
|
150
|
+
t.datetime "updated_at"
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
create_table "photos", force: true do |t|
|
|
154
|
+
t.string "name"
|
|
155
|
+
t.datetime "taken_at"
|
|
156
|
+
t.text "image_src"
|
|
157
|
+
t.text "thumb_src"
|
|
158
|
+
t.text "description"
|
|
159
|
+
t.integer "gallery_id"
|
|
160
|
+
t.integer "photographer_id"
|
|
161
|
+
t.datetime "created_at"
|
|
162
|
+
t.datetime "updated_at"
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
add_index "photos", ["gallery_id"], name: "index_photos_on_gallery_id"
|
|
166
|
+
add_index "photos", ["photographer_id"], name: "index_photos_on_photographer_id"
|
|
167
|
+
|
|
168
|
+
create_table "users", force: true do |t|
|
|
169
|
+
t.string "email"
|
|
170
|
+
t.string "name"
|
|
171
|
+
t.string "password_digest"
|
|
172
|
+
t.integer "gallery_id"
|
|
173
|
+
t.integer "photo_id"
|
|
174
|
+
t.integer "participants_id"
|
|
175
|
+
t.integer "comment_id"
|
|
176
|
+
t.datetime "created_at"
|
|
177
|
+
t.datetime "updated_at"
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
add_index "users", ["comment_id"], name: "index_users_on_comment_id"
|
|
181
|
+
add_index "users", ["gallery_id"], name: "index_users_on_gallery_id"
|
|
182
|
+
add_index "users", ["participants_id"], name: "index_users_on_participants_id"
|
|
183
|
+
add_index "users", ["photo_id"], name: "index_users_on_photo_id"
|
|
184
|
+
|
|
185
|
+
end
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
/app/models/photo.rb
|
|
189
|
+
```ruby
|
|
190
|
+
class Photo < ActiveRecord::Base
|
|
191
|
+
belongs_to :gallery
|
|
192
|
+
belongs_to :photographer, class_name: "User", dependent: :destroy
|
|
193
|
+
has_one :user, dependent: :destroy
|
|
194
|
+
has_many :participants, class_name: "User", dependent: :destroy, foreign_key: :participant_id
|
|
195
|
+
has_many :comments, dependent: :destroy
|
|
196
|
+
|
|
197
|
+
attr_accessible :gallery_id, :photographer_id
|
|
198
|
+
attr_accessible :name, :taken_at, :image_src, :thumb_src, :description
|
|
199
|
+
|
|
200
|
+
accepts_nested_attributes_for :user
|
|
201
|
+
accepts_nested_attributes_for :participants, :comments
|
|
202
|
+
|
|
203
|
+
before_save :generate_thumbnail
|
|
204
|
+
|
|
205
|
+
def generate_thumbnail
|
|
206
|
+
# generate a thumbnail from image_drc for thumb_src
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
/app/models/gallery.rb
|
|
212
|
+
```ruby
|
|
213
|
+
class Gallery < ActiveRecord::Base
|
|
214
|
+
has_one :user, dependent: :destroy
|
|
215
|
+
has_many :photos, dependent: :destroy
|
|
216
|
+
has_many :comments, dependent: :destroy
|
|
217
|
+
|
|
218
|
+
attr_accessible :name, :description
|
|
219
|
+
|
|
220
|
+
accepts_nested_attributes_for :user
|
|
221
|
+
accepts_nested_attributes_for :photos, :comments
|
|
222
|
+
end
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
/app/models/comment.rb
|
|
226
|
+
```ruby
|
|
227
|
+
class Comment < ActiveRecord::Base
|
|
228
|
+
belongs_to :gallery
|
|
229
|
+
belongs_to :photo
|
|
230
|
+
belongs_to :comment
|
|
231
|
+
has_one :user, dependent: :destroy
|
|
232
|
+
has_many :comments, dependent: :destroy
|
|
233
|
+
|
|
234
|
+
attr_accessible :gallery_id, :photo_id, :comment_id
|
|
235
|
+
attr_accessible :approved
|
|
236
|
+
|
|
237
|
+
accepts_nested_attributes_for :user
|
|
238
|
+
accepts_nested_attributes_for :comments
|
|
239
|
+
|
|
240
|
+
def approve!
|
|
241
|
+
self.update_columns(approved: true)
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
/app/models/user.rb
|
|
247
|
+
```ruby
|
|
248
|
+
class User < ActiveRecord::Base
|
|
249
|
+
belongs_to :gallery
|
|
250
|
+
belongs_to :photo
|
|
251
|
+
belongs_to :participants, class_name: "Photo"
|
|
252
|
+
belongs_to :comment
|
|
253
|
+
has_many :photographer_photos, class_name: "Photo", foreign_key: :photographer_id, dependent: :destroy
|
|
254
|
+
|
|
255
|
+
attr_accessible :gallery_id, :photo_id, :participants_id, :comment_id
|
|
256
|
+
attr_accessible :email, :name, :password_digest
|
|
257
|
+
|
|
258
|
+
accepts_nested_attributes_for :photographer_photos
|
|
259
|
+
|
|
260
|
+
has_secure_password
|
|
261
|
+
attr_accessible :password
|
|
262
|
+
|
|
263
|
+
# returns: string
|
|
264
|
+
def to_s
|
|
265
|
+
email
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
```
|
data/lib/yaddl.rb
CHANGED
|
@@ -109,7 +109,7 @@ class Generator
|
|
|
109
109
|
model['code']['after'] ||= []
|
|
110
110
|
model['code']['controller'] ||= []
|
|
111
111
|
sc = "rails g model #{name} " + model['attributes'].map{ |k,v| k + ':' + v['type'].sub(/yaml|hash|object|cache/i,"text") }.join(' ') + " " + model['belongs_to'].map{ |k,v| k + ':references' + (v['polymorphic'] ? "{polymorphic}" : "") }.join(' ')
|
|
112
|
-
puts("migration: cd #{Rails::root} && #{sc} --skip")
|
|
112
|
+
puts("migration: cd #{Rails::root} && #{sc} --skip --no-test-framework") unless @quiet
|
|
113
113
|
`cd #{Rails::root} && #{sc} --skip --no-test-framework`
|
|
114
114
|
end if options.include?("--migrations-only")
|
|
115
115
|
|
|
@@ -532,7 +532,7 @@ end.join } <td><%= link_to 'Show', #{name.underscore} %></td>
|
|
|
532
532
|
@multiline_buffer = line[@multiline_spaces..line.length]
|
|
533
533
|
return
|
|
534
534
|
elsif line.strip =~ /^[a-z_]+ |^acts_as_.*/
|
|
535
|
-
if line.strip =~
|
|
535
|
+
if line.strip =~ /^include |^require |^extend |^acts_as_[a-z_]+/
|
|
536
536
|
line = "!top{#{line.strip}}"
|
|
537
537
|
else
|
|
538
538
|
line = "!!{#{line.strip}}"
|
data/lib/yaddl/version.rb
CHANGED
data/test/dummy/log/test.log
CHANGED
|
@@ -416,5 +416,35 @@ YaddlTest: test_create_test_model
|
|
|
416
416
|
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
|
417
417
|
-----------------------
|
|
418
418
|
YaddlTest: test_defined
|
|
419
|
+
-----------------------
|
|
420
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
|
421
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
|
422
|
+
---------------------------------
|
|
423
|
+
YaddlTest: test_create_test_model
|
|
424
|
+
---------------------------------
|
|
425
|
+
[1m[35m (0.2ms)[0m rollback transaction
|
|
426
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
|
427
|
+
-----------------------
|
|
428
|
+
YaddlTest: test_defined
|
|
429
|
+
-----------------------
|
|
430
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
|
431
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
|
432
|
+
---------------------------------
|
|
433
|
+
YaddlTest: test_create_test_model
|
|
434
|
+
---------------------------------
|
|
435
|
+
[1m[35m (0.2ms)[0m rollback transaction
|
|
436
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
|
437
|
+
-----------------------
|
|
438
|
+
YaddlTest: test_defined
|
|
439
|
+
-----------------------
|
|
440
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
|
441
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
|
442
|
+
---------------------------------
|
|
443
|
+
YaddlTest: test_create_test_model
|
|
444
|
+
---------------------------------
|
|
445
|
+
[1m[35m (0.2ms)[0m rollback transaction
|
|
446
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
|
447
|
+
-----------------------
|
|
448
|
+
YaddlTest: test_defined
|
|
419
449
|
-----------------------
|
|
420
450
|
[1m[35m (0.1ms)[0m rollback transaction
|
data/test/yaddl_test.rb
CHANGED
|
@@ -9,15 +9,21 @@ class YaddlTest < ActiveSupport::TestCase
|
|
|
9
9
|
y = Yaddl::Generator.new
|
|
10
10
|
y.markup = "TestModel(name:string)
|
|
11
11
|
=to_s{name}
|
|
12
|
-
*
|
|
12
|
+
*ChildModel
|
|
13
|
+
+RelatedModel
|
|
14
|
+
ReferencedModel"
|
|
13
15
|
y.generate("--no-scaffolds --quiet")
|
|
14
16
|
y.generate("--migrations-only --quiet")
|
|
15
17
|
assert_file "app/models/test_model.rb", "class TestModel < ActiveRecord::Base
|
|
16
|
-
|
|
18
|
+
belongs_to :related_model
|
|
19
|
+
has_one :referenced_model, dependent: :destroy
|
|
20
|
+
has_many :child_models, dependent: :destroy
|
|
17
21
|
|
|
22
|
+
attr_accessible :related_model_id
|
|
18
23
|
attr_accessible :name
|
|
19
24
|
|
|
20
|
-
accepts_nested_attributes_for :
|
|
25
|
+
accepts_nested_attributes_for :referenced_model
|
|
26
|
+
accepts_nested_attributes_for :child_models
|
|
21
27
|
|
|
22
28
|
# returns: string
|
|
23
29
|
def to_s
|
|
@@ -27,9 +33,8 @@ end
|
|
|
27
33
|
"
|
|
28
34
|
|
|
29
35
|
assert_file "app/models/related_model.rb", "class RelatedModel < ActiveRecord::Base
|
|
30
|
-
|
|
36
|
+
has_many :test_models, dependent: :nullify
|
|
31
37
|
|
|
32
|
-
attr_accessible :test_model_id
|
|
33
38
|
end
|
|
34
39
|
"
|
|
35
40
|
|
|
@@ -45,11 +50,31 @@ TestModel:
|
|
|
45
50
|
returns: string
|
|
46
51
|
getter: name
|
|
47
52
|
has_many:
|
|
48
|
-
|
|
53
|
+
child_models:
|
|
49
54
|
dependent: destroy
|
|
55
|
+
class_names:
|
|
56
|
+
- ChildModel
|
|
57
|
+
belongs_to:
|
|
58
|
+
related_model:
|
|
50
59
|
class_names:
|
|
51
60
|
- RelatedModel
|
|
61
|
+
has_one:
|
|
62
|
+
referenced_model:
|
|
63
|
+
dependent: destroy
|
|
64
|
+
class_names:
|
|
65
|
+
- ReferencedModel
|
|
66
|
+
ChildModel:
|
|
67
|
+
belongs_to:
|
|
68
|
+
test_model:
|
|
69
|
+
class_names:
|
|
70
|
+
- TestModel
|
|
52
71
|
RelatedModel:
|
|
72
|
+
has_many:
|
|
73
|
+
test_models:
|
|
74
|
+
dependent: nullify
|
|
75
|
+
class_names:
|
|
76
|
+
- RelatedModel
|
|
77
|
+
ReferencedModel:
|
|
53
78
|
belongs_to:
|
|
54
79
|
test_model:
|
|
55
80
|
class_names:
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yaddl
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.7
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2014-03-
|
|
12
|
+
date: 2014-03-21 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rails
|
|
@@ -62,8 +62,6 @@ files:
|
|
|
62
62
|
- test/dummy/app/assets/stylesheets/application.css
|
|
63
63
|
- test/dummy/app/controllers/application_controller.rb
|
|
64
64
|
- test/dummy/app/helpers/application_helper.rb
|
|
65
|
-
- test/dummy/app/models/related_model.rb
|
|
66
|
-
- test/dummy/app/models/test_model.rb
|
|
67
65
|
- test/dummy/app/views/layouts/application.html.erb
|
|
68
66
|
- test/dummy/bin/bundle
|
|
69
67
|
- test/dummy/bin/rails
|
|
@@ -85,7 +83,6 @@ files:
|
|
|
85
83
|
- test/dummy/config/locales/en.yml
|
|
86
84
|
- test/dummy/config/routes.rb
|
|
87
85
|
- test/dummy/config.ru
|
|
88
|
-
- test/dummy/db/schema.yaml
|
|
89
86
|
- test/dummy/db/test.sqlite3
|
|
90
87
|
- test/dummy/log/development.log
|
|
91
88
|
- test/dummy/log/test.log
|
|
@@ -126,8 +123,6 @@ test_files:
|
|
|
126
123
|
- test/dummy/app/assets/stylesheets/application.css
|
|
127
124
|
- test/dummy/app/controllers/application_controller.rb
|
|
128
125
|
- test/dummy/app/helpers/application_helper.rb
|
|
129
|
-
- test/dummy/app/models/related_model.rb
|
|
130
|
-
- test/dummy/app/models/test_model.rb
|
|
131
126
|
- test/dummy/app/views/layouts/application.html.erb
|
|
132
127
|
- test/dummy/bin/bundle
|
|
133
128
|
- test/dummy/bin/rails
|
|
@@ -149,7 +144,6 @@ test_files:
|
|
|
149
144
|
- test/dummy/config/locales/en.yml
|
|
150
145
|
- test/dummy/config/routes.rb
|
|
151
146
|
- test/dummy/config.ru
|
|
152
|
-
- test/dummy/db/schema.yaml
|
|
153
147
|
- test/dummy/db/test.sqlite3
|
|
154
148
|
- test/dummy/log/development.log
|
|
155
149
|
- test/dummy/log/test.log
|
data/test/dummy/db/schema.yaml
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
TestModel:
|
|
3
|
-
attributes:
|
|
4
|
-
name:
|
|
5
|
-
type: string
|
|
6
|
-
primary_ref:
|
|
7
|
-
-
|
|
8
|
-
methods:
|
|
9
|
-
to_s:
|
|
10
|
-
returns: string
|
|
11
|
-
getter: name
|
|
12
|
-
has_many:
|
|
13
|
-
related_models:
|
|
14
|
-
dependent: destroy
|
|
15
|
-
class_names:
|
|
16
|
-
- RelatedModel
|
|
17
|
-
RelatedModel:
|
|
18
|
-
belongs_to:
|
|
19
|
-
test_model:
|
|
20
|
-
class_names:
|
|
21
|
-
- TestModel
|