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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 471aa431879477e255e4a76c14f55a235ae1db39
4
- data.tar.gz: 2885822fa8c7798469c5b431738d05ccc5fd676d
3
+ metadata.gz: a4d40ad0220410179bc7e2a78cfc606478c6a022
4
+ data.tar.gz: 60333b9d3512a99f9454a43ff5e926f697431d3f
5
5
  SHA512:
6
- metadata.gz: 81c3e88fdee8fec049a9645dbe062746fe9ff5344d0eb3adc9c9480b7fd87439679023a34b61a1dce651893030102de5d2ef03c75d2e807032bbf0f851c56423
7
- data.tar.gz: 9d6db38e292560a0e1a99debd48c57006738f3fd6f92f3ac552b25fc9036a4a8769b4eef5487f2c7d9eb8cca3f334a64bf8c267024a497201fc436de75461d36
6
+ metadata.gz: 3f46b96de8a46493af635b4d01bec24095a136bd84364f0dcaf344d9dd3f8a95d87f42c5d7327eff705e0a8b55335a281c097ce1d6e169eaf843685e363e4b62
7
+ data.tar.gz: 8a6a1492e30b871ae2d8e881c20f0c14fe00aa4d74b26f24c721e506bd173bf5a840a87b809fabd4c10f44607ed6d06fc8027b5fe3c3c44c0a3c745cccf8c922
@@ -1,7 +1,7 @@
1
1
  module Blueprint
2
2
  module Generators
3
3
  module Rails
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.8"
5
5
  end
6
6
  end
7
7
  end
@@ -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.foreach('.') { |f|
69
+ Dir.glob("**/*.rb").each { |f|
64
70
 
65
- # only deal with files that have a '.rb' extension
66
- if File.extname(f) == '.rb'
71
+ # process each file
72
+ File.open(f) do |g|
73
+ concept_name = nil
67
74
 
68
- # process each file
69
- File.open(f) do |g|
70
- concept_name = nil
75
+ # process each line of the file
76
+ g.each_line do |line|
71
77
 
72
- # process each line of the file
73
- g.each_line do |line|
78
+ # search for the class declaration line
79
+ clazz, super_clazz = line.match(/class ([^<]*) < ([^,#\s]*[.]*)/).try(:captures)
74
80
 
75
- # search for the class declaration line
76
- clazz, super_clazz = line.match(/class ([^<]*) < (.*)/).try(:captures)
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
- # if we find a class declaration line, add the new concept to the model
79
- unless clazz.nil?
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
- unless super_clazz.strip == 'ActiveRecord::Base'
89
- is_a_name = super_clazz.singularize
88
+ print_debug step_count, "Adding concept " + concept_name
89
+ step_count += 1
90
90
 
91
- # add the node relationship to the concept
92
- model[concept_name].push({ :type => 'is a', :name => is_a_name })
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 => 'has one', :name => has_one_name })
95
+ model[concept_name].push({ :type => 'is a', :name => is_a_name })
106
96
 
107
- print_debug step_count, "Concept " + concept_name + " has one " + has_one_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
- # search for a 'has_many' declaration
112
- b, has_many_clazz = line.match(/(has_many) :([^,]+)/).try(:captures)
113
- unless has_many_clazz.nil?
114
- has_many_name = has_many_clazz.classify.pluralize.strip
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
- # add the node relationship to the concept
117
- model[concept_name].push({ :type => 'has many', :name => has_many_name })
108
+ # add the node relationship to the concept
109
+ model[concept_name].push({ :type => 'has one', :name => has_one_name })
118
110
 
119
- print_debug step_count, "Concept " + concept_name + " has one " + has_many_name
120
- step_count += 1
121
- end
111
+ print_debug step_count, "Concept " + concept_name + " has one " + has_one_name
112
+ step_count += 1
113
+ end
122
114
 
123
- # search for a 'has_many' declaration
124
- c, habtm_clazz = line.match(/(has_and_belongs_to_many) :([^,]+)/).try(:captures)
125
- unless habtm_clazz.nil?
126
- # this is a many-to-many, so we add two 'has many' relationships (one of each side)
127
- habtm_name = habtm_clazz.classify.pluralize.strip
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
- # add the first side of the 'has many' if it does not already exist
130
- if model[concept_name].find { |v| v[:type] == 'has many' && v[:name] == habtm_name }.nil?
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
- # if the model hash doesn't have any entry for the many side of the relationship, create it
135
- if model[habtm_name].nil?
136
- model[habtm_name] = [ ]
137
- end
124
+ print_debug step_count, "Concept " + concept_name + " has one " + has_many_name
125
+ step_count += 1
126
+ end
138
127
 
139
- # add the second side of the 'has many' if it does not already exist
140
- if model[habtm_name].find { |v| v[:type] == 'has many' && v[:name] == concept_name }.nil?
141
- model[habtm_name].push({ :type => 'has many', :name => concept_name })
142
- end
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
- print_debug step_count, "Concept " + concept_name + " has many-to-many with " + habtm_name
145
- step_count += 1
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.7
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-29 00:00:00.000000000 Z
11
+ date: 2015-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler