blueprint-generators-rails 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/blueprint/generators/rails/version.rb +1 -1
- data/lib/tasks/blueprint.rake +67 -63
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4d40ad0220410179bc7e2a78cfc606478c6a022
|
4
|
+
data.tar.gz: 60333b9d3512a99f9454a43ff5e926f697431d3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f46b96de8a46493af635b4d01bec24095a136bd84364f0dcaf344d9dd3f8a95d87f42c5d7327eff705e0a8b55335a281c097ce1d6e169eaf843685e363e4b62
|
7
|
+
data.tar.gz: 8a6a1492e30b871ae2d8e881c20f0c14fe00aa4d74b26f24c721e506bd173bf5a840a87b809fabd4c10f44607ed6d06fc8027b5fe3c3c44c0a3c745cccf8c922
|
data/lib/tasks/blueprint.rake
CHANGED
@@ -25,6 +25,12 @@ namespace :blueprint do
|
|
25
25
|
next
|
26
26
|
end
|
27
27
|
|
28
|
+
# if an application.rb file can't be found in the config directory then stop
|
29
|
+
unless File.exist?(root_dir + '/config/application.rb')
|
30
|
+
puts 'No application.rb found in config directory. Is this a Rails project?'
|
31
|
+
next
|
32
|
+
end
|
33
|
+
|
28
34
|
# if the models directory can't be found then stop
|
29
35
|
unless Dir.exist?(root_dir + '/app/models')
|
30
36
|
puts 'No app/models directory found. Is this a Rails project?'
|
@@ -60,92 +66,90 @@ namespace :blueprint do
|
|
60
66
|
Dir.chdir(root_dir + '/app/models') do
|
61
67
|
|
62
68
|
# list all files in the directory
|
63
|
-
Dir.
|
69
|
+
Dir.glob("**/*.rb").each { |f|
|
64
70
|
|
65
|
-
#
|
66
|
-
|
71
|
+
# process each file
|
72
|
+
File.open(f) do |g|
|
73
|
+
concept_name = nil
|
67
74
|
|
68
|
-
# process each file
|
69
|
-
|
70
|
-
concept_name = nil
|
75
|
+
# process each line of the file
|
76
|
+
g.each_line do |line|
|
71
77
|
|
72
|
-
#
|
73
|
-
|
78
|
+
# search for the class declaration line
|
79
|
+
clazz, super_clazz = line.match(/class ([^<]*) < ([^,#\s]*[.]*)/).try(:captures)
|
74
80
|
|
75
|
-
|
76
|
-
|
81
|
+
# if we find a class declaration line, add the new concept to the model
|
82
|
+
unless clazz.nil?
|
83
|
+
concept_name = clazz.pluralize
|
77
84
|
|
78
|
-
#
|
79
|
-
|
80
|
-
concept_name = clazz.pluralize
|
81
|
-
|
82
|
-
# add the concept to the model hash
|
83
|
-
model[concept_name] = [ ]
|
84
|
-
|
85
|
-
print_debug step_count, "Adding concept " + concept_name
|
86
|
-
step_count += 1
|
85
|
+
# add the concept to the model hash
|
86
|
+
model[concept_name] = [ ]
|
87
87
|
|
88
|
-
|
89
|
-
|
88
|
+
print_debug step_count, "Adding concept " + concept_name
|
89
|
+
step_count += 1
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
print_debug step_count, "Concept " + concept_name + " is a " + is_a_name
|
95
|
-
step_count += 1
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
# search for a 'has_one' or 'belongs_to' declaration
|
100
|
-
a, has_one_clazz = line.match(/(has_one|belongs_to) :([^,]+)/).try(:captures)
|
101
|
-
unless has_one_clazz.nil?
|
102
|
-
has_one_name = has_one_clazz.classify.singularize.strip
|
91
|
+
unless super_clazz.strip == 'ActiveRecord::Base'
|
92
|
+
is_a_name = super_clazz.singularize
|
103
93
|
|
104
94
|
# add the node relationship to the concept
|
105
|
-
model[concept_name].push({ :type => '
|
95
|
+
model[concept_name].push({ :type => 'is a', :name => is_a_name })
|
106
96
|
|
107
|
-
print_debug step_count, "Concept " + concept_name + "
|
97
|
+
print_debug step_count, "Concept " + concept_name + " is a " + is_a_name
|
108
98
|
step_count += 1
|
109
99
|
end
|
100
|
+
end
|
110
101
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
102
|
+
# search for a 'has_one' or 'belongs_to' declaration
|
103
|
+
# TODO this would find '->' symbols: (has_one) :([^,#\s]+),[\s]*->[\s]*{(.*)}
|
104
|
+
a, has_one_clazz = line.match(/(has_one|belongs_to) :([^,#\s]+)/).try(:captures)
|
105
|
+
unless has_one_clazz.nil?
|
106
|
+
has_one_name = has_one_clazz.classify.singularize.strip
|
115
107
|
|
116
|
-
|
117
|
-
|
108
|
+
# add the node relationship to the concept
|
109
|
+
model[concept_name].push({ :type => 'has one', :name => has_one_name })
|
118
110
|
|
119
|
-
|
120
|
-
|
121
|
-
|
111
|
+
print_debug step_count, "Concept " + concept_name + " has one " + has_one_name
|
112
|
+
step_count += 1
|
113
|
+
end
|
122
114
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
115
|
+
# search for a 'has_many' declaration
|
116
|
+
# TODO this would find '->' symbols: (has_many) :([^,#\s]+),[\s]*->[\s]*{(.*)}
|
117
|
+
b, has_many_clazz = line.match(/(has_many) :([^,#\s]+)/).try(:captures)
|
118
|
+
unless has_many_clazz.nil?
|
119
|
+
has_many_name = has_many_clazz.classify.pluralize.strip
|
128
120
|
|
129
|
-
|
130
|
-
|
131
|
-
model[concept_name].push({ :type => 'has many', :name => habtm_name })
|
132
|
-
end
|
121
|
+
# add the node relationship to the concept
|
122
|
+
model[concept_name].push({ :type => 'has many', :name => has_many_name })
|
133
123
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
end
|
124
|
+
print_debug step_count, "Concept " + concept_name + " has one " + has_many_name
|
125
|
+
step_count += 1
|
126
|
+
end
|
138
127
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
128
|
+
# search for a 'has_many' declaration
|
129
|
+
c, habtm_clazz = line.match(/(has_and_belongs_to_many) : :([^,#\s]+)/).try(:captures)
|
130
|
+
unless habtm_clazz.nil?
|
131
|
+
# this is a many-to-many, so we add two 'has many' relationships (one of each side)
|
132
|
+
habtm_name = habtm_clazz.classify.pluralize.strip
|
143
133
|
|
144
|
-
|
145
|
-
|
134
|
+
# add the first side of the 'has many' if it does not already exist
|
135
|
+
if model[concept_name].find { |v| v[:type] == 'has many' && v[:name] == habtm_name }.nil?
|
136
|
+
model[concept_name].push({ :type => 'has many', :name => habtm_name })
|
146
137
|
end
|
147
138
|
|
139
|
+
# if the model hash doesn't have any entry for the many side of the relationship, create it
|
140
|
+
if model[habtm_name].nil?
|
141
|
+
model[habtm_name] = [ ]
|
142
|
+
end
|
143
|
+
|
144
|
+
# add the second side of the 'has many' if it does not already exist
|
145
|
+
if model[habtm_name].find { |v| v[:type] == 'has many' && v[:name] == concept_name }.nil?
|
146
|
+
model[habtm_name].push({ :type => 'has many', :name => concept_name })
|
147
|
+
end
|
148
|
+
|
149
|
+
print_debug step_count, "Concept " + concept_name + " has many-to-many with " + habtm_name
|
150
|
+
step_count += 1
|
148
151
|
end
|
152
|
+
|
149
153
|
end
|
150
154
|
end
|
151
155
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blueprint-generators-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- benjii
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|