railspp 0.1.7 → 0.2.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2f40015e3dbd5be7f68ce044f6f73b0bd90ccf38642ed3b7d8ea792ea3107c2
4
- data.tar.gz: c8f22493f7ba557f57302a4c63781291adc7dc67a4482a0311dba8df60a7c48c
3
+ metadata.gz: badd35a6122fc9810f737b6dcefaff35ff0a680bb4e5390082347cc38bb77a31
4
+ data.tar.gz: 720af3f9ee0e8a7c428d5786afcd3cce5a0c815e543661c08d603d9a04208b59
5
5
  SHA512:
6
- metadata.gz: da072dfecc8f5773f0a391aadbf4876e8709a79077ad9cfb46b1504727cbb8c1a2a44ef3bc41b5690b97a5a70c6461f1362f411bc1d64f1399d479f5ae2f21c5
7
- data.tar.gz: 3687f425a9436e0a11207569a3ec5d57ed914fbf6fe3209cc7e36ebed4c4dab84d5aa25737eb9350f17e45ffcab3b28a85a0e63a8555217189b3523ce1e93501
6
+ metadata.gz: 1f9dce9855cbc9c0544eb2eec89a74eab53c2602baf034d49ff1e25dd4b1c36c96780b89a841a8d4a9826d17995311269dc36720d134b26333a1e70e710ea2ea
7
+ data.tar.gz: 6bd511e6a26dfc54ebd5f01cf2fe8c3bdf0aa6d623c116ac544ab225c88ca0cf99aba9be46b735296a4042c794df69eca8c9dc6c5047984a8fea921fabe18cc3
@@ -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[:"skip-routes"]
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")
@@ -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.capitalize
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('/')}")
@@ -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:
@@ -1,10 +1,10 @@
1
1
  resources :documentation, only: :index
2
2
 
3
- namespace :api do
3
+ namespace :api, except: [:new, :edit] do
4
4
  # Add API Routes here
5
5
 
6
6
  # For API version 1
7
7
  namespace :v1 do
8
8
 
9
9
  end
10
- end
10
+ end
data/lib/utils/strings.rb CHANGED
@@ -21,7 +21,7 @@ class MoreUtils
21
21
  class << self
22
22
 
23
23
  def gem_version
24
- "0.1.7"
24
+ "0.2.4"
25
25
  end
26
26
 
27
27
  def get_file_str path
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railspp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Layne Faler