railspp 0.1.7 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/commands/initialize.rb +1 -1
- data/lib/commands/make_test.rb +1 -1
- data/lib/commands/model.rb +35 -1
- data/lib/help/model.rb +5 -0
- data/lib/templates/routes_documentation.txt +2 -2
- data/lib/utils/strings.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: badd35a6122fc9810f737b6dcefaff35ff0a680bb4e5390082347cc38bb77a31
|
4
|
+
data.tar.gz: 720af3f9ee0e8a7c428d5786afcd3cce5a0c815e543661c08d603d9a04208b59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f9dce9855cbc9c0544eb2eec89a74eab53c2602baf034d49ff1e25dd4b1c36c96780b89a841a8d4a9826d17995311269dc36720d134b26333a1e70e710ea2ea
|
7
|
+
data.tar.gz: 6bd511e6a26dfc54ebd5f01cf2fe8c3bdf0aa6d623c116ac544ab225c88ca0cf99aba9be46b735296a4042c794df69eca8c9dc6c5047984a8fea921fabe18cc3
|
data/lib/commands/initialize.rb
CHANGED
@@ -42,7 +42,7 @@ class InitializeCommand < MoreUtils
|
|
42
42
|
write_file("#{root}/app/views/layouts/documentation.html.erb", dlhtml_template)
|
43
43
|
|
44
44
|
# Update Routes
|
45
|
-
unless lookup
|
45
|
+
unless lookup.has_key?(:"skip-routes")
|
46
46
|
routes_template = get_file_str("#{this_dir}/../templates/routes_documentation.txt")
|
47
47
|
routes_file = get_file_str("#{root}/config/routes.rb")
|
48
48
|
routes_arr = routes_file.split("\n")
|
data/lib/commands/make_test.rb
CHANGED
@@ -17,7 +17,7 @@ class MakeTestCommand < MoreUtils
|
|
17
17
|
namespace_array = api_route.split('/')
|
18
18
|
model = namespace_array.pop
|
19
19
|
namespace_array = namespace_array.reject { |e| e == '' }
|
20
|
-
namespace = namespace_array.map { |e| e.downcase.capitalize }.join('::') + '::' + model.
|
20
|
+
namespace = namespace_array.map { |e| e.downcase.capitalize }.join('::') + '::' + model.camelcase
|
21
21
|
namespace_snake = (namespace_array.join('_') + '_' + model).underscore
|
22
22
|
|
23
23
|
system("mkdir -p #{root}/test/controllers/#{namespace_array.join('/')}")
|
data/lib/commands/model.rb
CHANGED
@@ -16,7 +16,7 @@ class ModelCommand < MoreUtils
|
|
16
16
|
model_name = arguments[0].camelcase
|
17
17
|
others = arguments[1..-1]
|
18
18
|
|
19
|
-
system("rails generate model #{model_name} #{others.join(' ')}")
|
19
|
+
system("rails generate model #{model_name} #{others.join(' ')} --no-fixture")
|
20
20
|
|
21
21
|
api_version_path = lookup[:"api-version"] || 'api/v1'
|
22
22
|
|
@@ -29,8 +29,42 @@ class ModelCommand < MoreUtils
|
|
29
29
|
controller_str = controller_temp.gsub(controller_regex, controller_name)
|
30
30
|
write_file("#{root}/app/controllers/#{api_version_path}/#{model_name.underscore}_controller.rb", controller_str)
|
31
31
|
|
32
|
+
if lookup.has_key?(:'with-test')
|
33
|
+
routes_file = get_file_str("#{root}/config/routes.rb")
|
34
|
+
routes_file_arr = routes_file.split("\n")
|
35
|
+
last_namespace = ':' + api_version_path.split('/').pop
|
36
|
+
regex = /#{last_namespace}/
|
37
|
+
route_line_index = last_regex_index(routes_file_arr, regex) + 1
|
38
|
+
starting_space = count_spaces(routes_file_arr[route_line_index - 1])
|
39
|
+
add_space = get_space_str(starting_space + space_count(starting_space))
|
40
|
+
new_routes = routes_file_arr.slice(0, route_line_index).join("\n") + "\n#{add_space}resources :#{model_name.underscore}\n" + routes_file_arr.slice(route_line_index, routes_file_arr.length).join("\n")
|
41
|
+
write_file("#{root}/config/routes.rb", new_routes)
|
42
|
+
system("ruby #{this_dir}/../railspp.rb mt /#{api_version_path}/#{model_name.underscore}")
|
43
|
+
end
|
44
|
+
|
32
45
|
puts "#{model_name} model, migration, and controller has been generated."
|
33
46
|
end
|
34
47
|
|
48
|
+
def last_regex_index arr, regex
|
49
|
+
arr.each_with_index.inject(0) do |acc, (e, i)|
|
50
|
+
acc = i if regex.match(e)
|
51
|
+
acc
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def count_spaces line
|
56
|
+
_, spaces_at_beginning, spaces_at_end = /^( *).*?( *)$/.match(line).to_a.map(&:length)
|
57
|
+
spaces_at_beginning
|
58
|
+
end
|
59
|
+
|
60
|
+
def space_count count
|
61
|
+
2
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_space_str num
|
65
|
+
str = ''
|
66
|
+
num.times { |e| str += ' ' }
|
67
|
+
str
|
68
|
+
end
|
35
69
|
end
|
36
70
|
end
|
data/lib/help/model.rb
CHANGED
@@ -19,6 +19,11 @@ Example:
|
|
19
19
|
Same command as:
|
20
20
|
rails generate model <model-name>
|
21
21
|
|
22
|
+
If you use mini test with Rails by default, you can generate the test and your routes with
|
23
|
+
the option:
|
24
|
+
|
25
|
+
--with-test
|
26
|
+
|
22
27
|
With your generated controller
|
23
28
|
|
24
29
|
Run to generate your model, migration, and controller:
|
data/lib/utils/strings.rb
CHANGED