mdd 3.0.6 → 3.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/mdwa/requirements_controller.rb +4 -1
- data/lib/generators/mdwa/association/association_generator.rb +17 -10
- data/lib/generators/mdwa/code/code_generator.rb +9 -1
- data/lib/generators/mdwa/{template/templates/views → templates/templates/actions}/view.custom.erb +0 -0
- data/lib/generators/mdwa/{template/templates/views → templates/templates/actions}/view.html.erb +0 -0
- data/lib/generators/mdwa/{template/templates/views → templates/templates/actions}/view.js.erb +0 -0
- data/lib/generators/mdwa/{template/templates/views → templates/templates/actions}/view.json.erb +0 -0
- data/lib/generators/mdwa/templates/templates/general/routes.rb +3 -0
- data/lib/generators/mdwa/templates/templates/scaffold/controller.rb +150 -0
- data/lib/generators/mdwa/templates/templates/scaffold/helper.rb +3 -0
- data/lib/generators/mdwa/templates/templates/scaffold/model.rb +50 -0
- data/lib/generators/mdwa/templates/templates/scaffold/views/_form.html.erb +23 -0
- data/lib/generators/mdwa/templates/templates/scaffold/views/_form_fields.html.erb +45 -0
- data/lib/generators/mdwa/templates/templates/scaffold/views/_list.html.erb +47 -0
- data/lib/generators/mdwa/templates/templates/scaffold/views/create.js.erb +8 -0
- data/lib/generators/mdwa/templates/templates/scaffold/views/destroy.js.erb +3 -0
- data/lib/generators/mdwa/templates/templates/scaffold/views/edit.html.erb +10 -0
- data/lib/generators/mdwa/templates/templates/scaffold/views/index.html.erb +17 -0
- data/lib/generators/mdwa/templates/templates/scaffold/views/index.js.erb +2 -0
- data/lib/generators/mdwa/templates/templates/scaffold/views/new.html.erb +10 -0
- data/lib/generators/mdwa/templates/templates/scaffold/views/show.html.erb +31 -0
- data/lib/generators/mdwa/templates/templates/scaffold/views/update.js.erb +13 -0
- data/lib/generators/mdwa/templates/templates_generator.rb +144 -0
- data/lib/generators/mdwa/transform/templates/changes_migration.rb +16 -0
- data/lib/generators/mdwa/transform/transform_generator.rb +258 -61
- data/lib/generators/mdwa/user_scaffold/user_scaffold_generator.rb +32 -14
- data/lib/mdwa/dsl/action.rb +10 -1
- data/lib/mdwa/dsl/entity.rb +9 -3
- data/lib/mdwa/dsl/entity_association.rb +21 -0
- data/lib/mdwa/dsl/requirements.rb +4 -0
- data/lib/mdwa/generators/model_association.rb +9 -3
- data/lib/mdwa/version.rb +1 -1
- metadata +25 -9
- data/lib/generators/mdwa/template/template_generator.rb +0 -40
data/lib/mdwa/dsl/entity.rb
CHANGED
@@ -73,8 +73,11 @@ module MDWA
|
|
73
73
|
def after_declaration
|
74
74
|
|
75
75
|
# if it's a user and have no attributes, include "name" to prevent errors
|
76
|
-
if user?
|
76
|
+
if user?
|
77
77
|
self.attribute('name', 'string')
|
78
|
+
self.attribute('email', 'string')
|
79
|
+
self.attribute('password', 'password')
|
80
|
+
self.attribute('password_confirmation', 'password')
|
78
81
|
end
|
79
82
|
|
80
83
|
end
|
@@ -134,8 +137,11 @@ module MDWA
|
|
134
137
|
end
|
135
138
|
self.associations.values.each do |association|
|
136
139
|
model1 = Generators::Model.new(self.model_name)
|
137
|
-
|
138
|
-
|
140
|
+
entity2 = DSL.entity(association.destination)
|
141
|
+
model2 = Generators::Model.new(entity2.model_name)
|
142
|
+
assoc = Generators::ModelAssociation.new(model1, model2, association.generator_type, entity2.default_attribute.name)
|
143
|
+
assoc.composition = true if association.composition
|
144
|
+
@generator_model.associations << assoc
|
139
145
|
end
|
140
146
|
return @generator_model
|
141
147
|
end
|
@@ -22,6 +22,7 @@ module MDWA
|
|
22
22
|
self.name = value.downcase if self.name.blank?
|
23
23
|
@destination = value
|
24
24
|
end
|
25
|
+
|
25
26
|
|
26
27
|
#
|
27
28
|
# Return the mapped type for the code generation.
|
@@ -53,6 +54,26 @@ module MDWA
|
|
53
54
|
gen.join(':')
|
54
55
|
end
|
55
56
|
|
57
|
+
def one_to_many?
|
58
|
+
self.type.to_sym == :one_to_many
|
59
|
+
end
|
60
|
+
|
61
|
+
def many_to_one?
|
62
|
+
self.type.to_sym == :many_to_one
|
63
|
+
end
|
64
|
+
|
65
|
+
def one_to_one?
|
66
|
+
self.type.to_sym == :one_to_one
|
67
|
+
end
|
68
|
+
|
69
|
+
def many_to_many?
|
70
|
+
self.type.to_sym == :many_to_many
|
71
|
+
end
|
72
|
+
|
73
|
+
def one_to_one_not_navigable?
|
74
|
+
self.type.to_sym == :one_to_one_not_navigable
|
75
|
+
end
|
76
|
+
|
56
77
|
end
|
57
78
|
|
58
79
|
end
|
@@ -6,20 +6,22 @@ module MDWA
|
|
6
6
|
|
7
7
|
class ModelAssociation
|
8
8
|
|
9
|
-
attr_accessor :model1, :model2, :relation
|
9
|
+
attr_accessor :model1, :model2, :relation, :reference_field, :composition
|
10
10
|
|
11
11
|
ACCEPTED_RELATIONS = [:has_many, :belongs_to, :has_and_belongs_to_many, :nested_many, :nested_one, :has_one]
|
12
12
|
|
13
|
-
def initialize(model1_name, model2_name, relation_name)
|
13
|
+
def initialize(model1_name, model2_name, relation_name, reference_field = nil)
|
14
14
|
|
15
15
|
self.model1 = model1_name
|
16
16
|
self.model2 = model2_name
|
17
17
|
self.relation = relation_name
|
18
|
+
self.reference_field = reference_field || 'id'
|
19
|
+
self.composition = false
|
18
20
|
|
19
21
|
# validation
|
20
22
|
raise "Invalid model name: #{@model1.name}" unless self.model1.valid?
|
21
23
|
raise "Invalid model name: #{@model2.name}" unless self.model2.valid?
|
22
|
-
raise "Invalid relation type: #{@relation}" unless relation_valid?
|
24
|
+
raise "Invalid relation type: #{@relation}" unless self.relation_valid?
|
23
25
|
end
|
24
26
|
|
25
27
|
def model1=(value)
|
@@ -38,6 +40,10 @@ module MDWA
|
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
43
|
+
def composition?
|
44
|
+
self.composition
|
45
|
+
end
|
46
|
+
|
41
47
|
def relation_valid?
|
42
48
|
ACCEPTED_RELATIONS.include? relation.to_sym
|
43
49
|
end
|
data/lib/mdwa/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.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: 2012-
|
12
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -324,11 +324,27 @@ files:
|
|
324
324
|
- lib/generators/mdwa/scaffold/templates/views/index.js.erb
|
325
325
|
- lib/generators/mdwa/scaffold/templates/views/new.html.erb
|
326
326
|
- lib/generators/mdwa/scaffold/templates/views/show.html.erb
|
327
|
-
- lib/generators/mdwa/
|
328
|
-
- lib/generators/mdwa/
|
329
|
-
- lib/generators/mdwa/
|
330
|
-
- lib/generators/mdwa/
|
331
|
-
- lib/generators/mdwa/
|
327
|
+
- lib/generators/mdwa/templates/templates/actions/view.custom.erb
|
328
|
+
- lib/generators/mdwa/templates/templates/actions/view.html.erb
|
329
|
+
- lib/generators/mdwa/templates/templates/actions/view.js.erb
|
330
|
+
- lib/generators/mdwa/templates/templates/actions/view.json.erb
|
331
|
+
- lib/generators/mdwa/templates/templates/general/routes.rb
|
332
|
+
- lib/generators/mdwa/templates/templates/scaffold/controller.rb
|
333
|
+
- lib/generators/mdwa/templates/templates/scaffold/helper.rb
|
334
|
+
- lib/generators/mdwa/templates/templates/scaffold/model.rb
|
335
|
+
- lib/generators/mdwa/templates/templates/scaffold/views/_form.html.erb
|
336
|
+
- lib/generators/mdwa/templates/templates/scaffold/views/_form_fields.html.erb
|
337
|
+
- lib/generators/mdwa/templates/templates/scaffold/views/_list.html.erb
|
338
|
+
- lib/generators/mdwa/templates/templates/scaffold/views/create.js.erb
|
339
|
+
- lib/generators/mdwa/templates/templates/scaffold/views/destroy.js.erb
|
340
|
+
- lib/generators/mdwa/templates/templates/scaffold/views/edit.html.erb
|
341
|
+
- lib/generators/mdwa/templates/templates/scaffold/views/index.html.erb
|
342
|
+
- lib/generators/mdwa/templates/templates/scaffold/views/index.js.erb
|
343
|
+
- lib/generators/mdwa/templates/templates/scaffold/views/new.html.erb
|
344
|
+
- lib/generators/mdwa/templates/templates/scaffold/views/show.html.erb
|
345
|
+
- lib/generators/mdwa/templates/templates/scaffold/views/update.js.erb
|
346
|
+
- lib/generators/mdwa/templates/templates_generator.rb
|
347
|
+
- lib/generators/mdwa/transform/templates/changes_migration.rb
|
332
348
|
- lib/generators/mdwa/transform/transform_generator.rb
|
333
349
|
- lib/generators/mdwa/user/templates/user.rb
|
334
350
|
- lib/generators/mdwa/user/user_generator.rb
|
@@ -391,7 +407,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
391
407
|
version: '0'
|
392
408
|
segments:
|
393
409
|
- 0
|
394
|
-
hash:
|
410
|
+
hash: -2577917960470046169
|
395
411
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
396
412
|
none: false
|
397
413
|
requirements:
|
@@ -400,7 +416,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
400
416
|
version: '0'
|
401
417
|
segments:
|
402
418
|
- 0
|
403
|
-
hash:
|
419
|
+
hash: -2577917960470046169
|
404
420
|
requirements: []
|
405
421
|
rubyforge_project: mdd
|
406
422
|
rubygems_version: 1.8.24
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
|
-
|
3
|
-
require 'rails/generators'
|
4
|
-
require 'rails/generators/migration'
|
5
|
-
|
6
|
-
require 'mdwa/dsl'
|
7
|
-
|
8
|
-
module Mdwa
|
9
|
-
module Generators
|
10
|
-
class CodeGenerator < Rails::Generators::Base
|
11
|
-
|
12
|
-
include Rails::Generators::Migration
|
13
|
-
|
14
|
-
source_root File.expand_path("../templates", __FILE__)
|
15
|
-
|
16
|
-
argument :entities, :type => :array, :banner => 'Specific entities', :default => []
|
17
|
-
|
18
|
-
#
|
19
|
-
# Constructor
|
20
|
-
# Require all entities to load the DSL of the application
|
21
|
-
def initialize(*args, &block)
|
22
|
-
super
|
23
|
-
|
24
|
-
# include files with entities
|
25
|
-
# select entities that will be generated
|
26
|
-
inside Rails.root do
|
27
|
-
if entities.count.zero?
|
28
|
-
require_all MDWA::DSL::STRUCTURAL_PATH unless Dir.glob("#{MDWA::DSL::STRUCTURAL_PATH}/*.rb").count.zero?
|
29
|
-
else
|
30
|
-
files = entities.collect{ |e| "#{MDWA::DSL::STRUCTURAL_PATH}#{MDWA::DSL::Entity.new(e).file_name}.rb" }
|
31
|
-
require_all files.join(', ')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
@all_entities = MDWA::DSL.entities.all
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|