eucalypt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE +21 -0
  4. data/README.md +26 -0
  5. data/Rakefile +2 -0
  6. data/bin/eucalypt +3 -0
  7. data/eucalypt.gemspec +39 -0
  8. data/lib/eucalypt/app.rb +6 -0
  9. data/lib/eucalypt/controller.rb +10 -0
  10. data/lib/eucalypt/errors.rb +109 -0
  11. data/lib/eucalypt/eucalypt-blog/helpers.rb +106 -0
  12. data/lib/eucalypt/eucalypt-blog/namespaces/blog/__base__.rb +22 -0
  13. data/lib/eucalypt/eucalypt-blog/namespaces/blog/__require__.rb +1 -0
  14. data/lib/eucalypt/eucalypt-blog/namespaces/blog/cli/blog.rb +65 -0
  15. data/lib/eucalypt/eucalypt-blog/namespaces/blog/generators/article.rb +28 -0
  16. data/lib/eucalypt/eucalypt-blog/namespaces/blog/generators/controller.rb +14 -0
  17. data/lib/eucalypt/eucalypt-blog/namespaces/blog/generators/helper.rb +12 -0
  18. data/lib/eucalypt/eucalypt-blog/namespaces/blog/generators/list.rb +74 -0
  19. data/lib/eucalypt/eucalypt-blog/namespaces/blog/generators/views.rb +20 -0
  20. data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/controller/controller.tt +33 -0
  21. data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/controller/controller_spec.tt +43 -0
  22. data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/helper/helper.tt +5 -0
  23. data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/helper/helper_spec.tt +9 -0
  24. data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/views/article.erb +1 -0
  25. data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/views/article_layout.erb +10 -0
  26. data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/views/article_md.tt +9 -0
  27. data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/views/articles.erb +1 -0
  28. data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/views/articles_layout.erb +10 -0
  29. data/lib/eucalypt/eucalypt-blog/namespaces/blog/templates/views/search.erb +1 -0
  30. data/lib/eucalypt/eucalypt-blog/namespaces/blog-article/cli/article.rb +120 -0
  31. data/lib/eucalypt/eucalypt-blog/namespaces/blog-article-edit/cli/edit-datetime.rb +113 -0
  32. data/lib/eucalypt/eucalypt-blog/namespaces/blog-article-edit/cli/edit-urltitle.rb +75 -0
  33. data/lib/eucalypt/eucalypt-core/cli/__base__.rb +11 -0
  34. data/lib/eucalypt/eucalypt-core/cli/console.rb +15 -0
  35. data/lib/eucalypt/eucalypt-core/cli/core.rb +6 -0
  36. data/lib/eucalypt/eucalypt-core/cli/help.rb +11 -0
  37. data/lib/eucalypt/eucalypt-core/cli/init.rb +71 -0
  38. data/lib/eucalypt/eucalypt-core/cli/launch.rb +33 -0
  39. data/lib/eucalypt/eucalypt-core/cli/test.rb +16 -0
  40. data/lib/eucalypt/eucalypt-core/cli/version.rb +11 -0
  41. data/lib/eucalypt/eucalypt-core/templates/Gemfile.tt +35 -0
  42. data/lib/eucalypt/eucalypt-core/templates/eucalypt/.gitignore +48 -0
  43. data/lib/eucalypt/eucalypt-core/templates/eucalypt/.travis.yml +8 -0
  44. data/lib/eucalypt/eucalypt-core/templates/eucalypt/Procfile +1 -0
  45. data/lib/eucalypt/eucalypt-core/templates/eucalypt/Rakefile +7 -0
  46. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/assets/fonts/.empty_directory +0 -0
  47. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/assets/images/.empty_directory +0 -0
  48. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/assets/scripts/application.js +17 -0
  49. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/assets/stylesheets/__partials__.scss +16 -0
  50. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/assets/stylesheets/application.scss +17 -0
  51. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/assets/stylesheets/partials/_mixins.scss +54 -0
  52. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/controllers/application_controller.rb +7 -0
  53. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/helpers/application_helper.rb +3 -0
  54. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/models/.empty_directory +0 -0
  55. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/static/.empty_directory +0 -0
  56. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/static/readme.yml +34 -0
  57. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/views/index.erb +0 -0
  58. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/views/layouts/main.erb +9 -0
  59. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app/views/partials/.empty_directory +0 -0
  60. data/lib/eucalypt/eucalypt-core/templates/eucalypt/app.rb +42 -0
  61. data/lib/eucalypt/eucalypt-core/templates/eucalypt/config/active_record.rb +6 -0
  62. data/lib/eucalypt/eucalypt-core/templates/eucalypt/config/asset_pipeline.rb +15 -0
  63. data/lib/eucalypt/eucalypt-core/templates/eucalypt/config/database.yml +16 -0
  64. data/lib/eucalypt/eucalypt-core/templates/eucalypt/config/initializers/.empty_directory +0 -0
  65. data/lib/eucalypt/eucalypt-core/templates/eucalypt/config/logging.rb +27 -0
  66. data/lib/eucalypt/eucalypt-core/templates/eucalypt/config/manifest.rb +15 -0
  67. data/lib/eucalypt/eucalypt-core/templates/eucalypt/config.ru +10 -0
  68. data/lib/eucalypt/eucalypt-core/templates/eucalypt/log/.empty_directory +0 -0
  69. data/lib/eucalypt/eucalypt-core/templates/eucalypt/spec/controllers/application_controller_spec.rb +9 -0
  70. data/lib/eucalypt/eucalypt-core/templates/eucalypt/spec/helpers/application_helper_spec.rb +9 -0
  71. data/lib/eucalypt/eucalypt-core/templates/eucalypt/spec/models/.empty_directory +0 -0
  72. data/lib/eucalypt/eucalypt-core/templates/eucalypt/spec/spec_helper.rb +18 -0
  73. data/lib/eucalypt/eucalypt-destroy/helpers.rb +77 -0
  74. data/lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy-controller.rb +16 -0
  75. data/lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy-helper.rb +16 -0
  76. data/lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy-model.rb +16 -0
  77. data/lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy-scaffold.rb +63 -0
  78. data/lib/eucalypt/eucalypt-destroy/namespaces/destroy/cli/destroy.rb +21 -0
  79. data/lib/eucalypt/eucalypt-generate/.gitkeep +0 -0
  80. data/lib/eucalypt/eucalypt-generate/namespaces/generate/cli/generate-scaffold.rb +62 -0
  81. data/lib/eucalypt/eucalypt-generate/namespaces/generate/cli/generate.rb +24 -0
  82. data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/cli/generate-controller.rb +29 -0
  83. data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/generators/controller.rb +45 -0
  84. data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/templates/controller/controller.tt +3 -0
  85. data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/templates/controller/policy_rest_controller.tt +71 -0
  86. data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/templates/controller/rest_controller.tt +28 -0
  87. data/lib/eucalypt/eucalypt-generate/namespaces/generate-controller/templates/controller_spec.tt +9 -0
  88. data/lib/eucalypt/eucalypt-generate/namespaces/generate-helper/cli/generate-helper.rb +23 -0
  89. data/lib/eucalypt/eucalypt-generate/namespaces/generate-helper/generators/helper.rb +24 -0
  90. data/lib/eucalypt/eucalypt-generate/namespaces/generate-helper/templates/helper.tt +3 -0
  91. data/lib/eucalypt/eucalypt-generate/namespaces/generate-helper/templates/helper_spec.tt +9 -0
  92. data/lib/eucalypt/eucalypt-generate/namespaces/generate-model/cli/generate-model.rb +26 -0
  93. data/lib/eucalypt/eucalypt-generate/namespaces/generate-model/generators/model.rb +25 -0
  94. data/lib/eucalypt/eucalypt-generate/namespaces/generate-model/templates/model.tt +3 -0
  95. data/lib/eucalypt/eucalypt-generate/namespaces/generate-model/templates/model_spec.tt +8 -0
  96. data/lib/eucalypt/eucalypt-migration/helpers.rb +93 -0
  97. data/lib/eucalypt/eucalypt-migration/migration_base.tt +4 -0
  98. data/lib/eucalypt/eucalypt-migration/namespaces/migration/cli/migration.rb +39 -0
  99. data/lib/eucalypt/eucalypt-migration/namespaces/migration-add/cli/add-column.rb +25 -0
  100. data/lib/eucalypt/eucalypt-migration/namespaces/migration-add/cli/add-index.rb +25 -0
  101. data/lib/eucalypt/eucalypt-migration/namespaces/migration-add/cli/add.rb +18 -0
  102. data/lib/eucalypt/eucalypt-migration/namespaces/migration-add/generators/column.rb +46 -0
  103. data/lib/eucalypt/eucalypt-migration/namespaces/migration-add/generators/index.rb +52 -0
  104. data/lib/eucalypt/eucalypt-migration/namespaces/migration-blank/cli/blank.rb +22 -0
  105. data/lib/eucalypt/eucalypt-migration/namespaces/migration-blank/generators/blank.rb +28 -0
  106. data/lib/eucalypt/eucalypt-migration/namespaces/migration-change/cli/change-column.rb +23 -0
  107. data/lib/eucalypt/eucalypt-migration/namespaces/migration-change/cli/change.rb +17 -0
  108. data/lib/eucalypt/eucalypt-migration/namespaces/migration-change/generators/column.rb +46 -0
  109. data/lib/eucalypt/eucalypt-migration/namespaces/migration-create/cli/create-table.rb +25 -0
  110. data/lib/eucalypt/eucalypt-migration/namespaces/migration-create/cli/create.rb +17 -0
  111. data/lib/eucalypt/eucalypt-migration/namespaces/migration-create/generators/table.rb +53 -0
  112. data/lib/eucalypt/eucalypt-migration/namespaces/migration-drop/cli/drop-column.rb +22 -0
  113. data/lib/eucalypt/eucalypt-migration/namespaces/migration-drop/cli/drop-index.rb +23 -0
  114. data/lib/eucalypt/eucalypt-migration/namespaces/migration-drop/cli/drop-table.rb +22 -0
  115. data/lib/eucalypt/eucalypt-migration/namespaces/migration-drop/cli/drop.rb +19 -0
  116. data/lib/eucalypt/eucalypt-migration/namespaces/migration-drop/generators/column.rb +38 -0
  117. data/lib/eucalypt/eucalypt-migration/namespaces/migration-drop/generators/index.rb +48 -0
  118. data/lib/eucalypt/eucalypt-migration/namespaces/migration-drop/generators/table.rb +37 -0
  119. data/lib/eucalypt/eucalypt-migration/namespaces/migration-rename/cli/rename-column.rb +22 -0
  120. data/lib/eucalypt/eucalypt-migration/namespaces/migration-rename/cli/rename-index.rb +22 -0
  121. data/lib/eucalypt/eucalypt-migration/namespaces/migration-rename/cli/rename-table.rb +24 -0
  122. data/lib/eucalypt/eucalypt-migration/namespaces/migration-rename/cli/rename.rb +19 -0
  123. data/lib/eucalypt/eucalypt-migration/namespaces/migration-rename/generators/column.rb +39 -0
  124. data/lib/eucalypt/eucalypt-migration/namespaces/migration-rename/generators/index.rb +39 -0
  125. data/lib/eucalypt/eucalypt-migration/namespaces/migration-rename/generators/table.rb +38 -0
  126. data/lib/eucalypt/eucalypt-security/helpers.rb +22 -0
  127. data/lib/eucalypt/eucalypt-security/namespaces/security/cli/security.rb +31 -0
  128. data/lib/eucalypt/eucalypt-security/namespaces/security-policy/cli/security-policy.rb +91 -0
  129. data/lib/eucalypt/eucalypt-security/namespaces/security-policy/generators/policy.rb +31 -0
  130. data/lib/eucalypt/eucalypt-security/namespaces/security-policy/templates/create_policy_roles_migration.tt +11 -0
  131. data/lib/eucalypt/eucalypt-security/namespaces/security-policy/templates/policy.tt +16 -0
  132. data/lib/eucalypt/eucalypt-security/namespaces/security-policy-permission/cli/security-policy-permission.rb +62 -0
  133. data/lib/eucalypt/eucalypt-security/namespaces/security-policy-permission/generators/policy-permission.rb +28 -0
  134. data/lib/eucalypt/eucalypt-security/namespaces/security-policy-permission/templates/add_permission_to_policy_migration.tt +5 -0
  135. data/lib/eucalypt/eucalypt-security/namespaces/security-policy-role/cli/security-policy-role.rb +66 -0
  136. data/lib/eucalypt/eucalypt-security/namespaces/security-pundit/cli/security-pundit.rb +79 -0
  137. data/lib/eucalypt/eucalypt-security/namespaces/security-pundit/generators/role.rb +24 -0
  138. data/lib/eucalypt/eucalypt-security/namespaces/security-pundit/templates/create_roles_migration.tt +7 -0
  139. data/lib/eucalypt/eucalypt-security/namespaces/security-pundit/templates/pundit.tt +4 -0
  140. data/lib/eucalypt/eucalypt-security/namespaces/security-warden/cli/security-warden.rb +61 -0
  141. data/lib/eucalypt/eucalypt-security/namespaces/security-warden/generators/auth_controller.rb +34 -0
  142. data/lib/eucalypt/eucalypt-security/namespaces/security-warden/generators/user.rb +37 -0
  143. data/lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/auth_controller.tt +25 -0
  144. data/lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/auth_login.tt +1 -0
  145. data/lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/create_users_table_migration.tt +9 -0
  146. data/lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/user.tt +16 -0
  147. data/lib/eucalypt/eucalypt-security/namespaces/security-warden/templates/warden.tt +35 -0
  148. data/lib/eucalypt/eucalypt-security/namespaces/security-warden/user_confirm.rb +38 -0
  149. data/lib/eucalypt/helpers/colorize.rb +27 -0
  150. data/lib/eucalypt/helpers/gemfile.rb +48 -0
  151. data/lib/eucalypt/helpers/inflect.rb +79 -0
  152. data/lib/eucalypt/helpers/messages.rb +31 -0
  153. data/lib/eucalypt/helpers/migration.rb +85 -0
  154. data/lib/eucalypt/helpers/numeric.rb +10 -0
  155. data/lib/eucalypt/helpers.rb +6 -0
  156. data/lib/eucalypt/list.rb +39 -0
  157. data/lib/eucalypt/static.rb +48 -0
  158. data/lib/eucalypt/version.rb +3 -0
  159. data/lib/eucalypt.rb +19 -0
  160. metadata +373 -0
@@ -0,0 +1,24 @@
1
+ require 'eucalypt/eucalypt-generate/namespaces/generate-controller/cli/generate-controller'
2
+ require 'eucalypt/eucalypt-generate/namespaces/generate-helper/cli/generate-helper'
3
+ require 'eucalypt/eucalypt-generate/namespaces/generate-model/cli/generate-model'
4
+ require_relative 'generate-scaffold'
5
+ require 'eucalypt/helpers'
6
+
7
+ module Eucalypt
8
+ class Generate < Thor
9
+ include Eucalypt::Helpers
10
+ using Colorize
11
+ class << self
12
+ require 'eucalypt/list'
13
+ include Eucalypt::List
14
+ def banner(task, namespace = false, subcommand = true)
15
+ basename + ' ' + task.formatted_usage(self, true, subcommand).split(':').join(' ')
16
+ end
17
+ end
18
+ end
19
+ class CLI < Thor
20
+ include Eucalypt::Helpers
21
+ using Colorize
22
+ register(Generate, 'generate', 'generate [COMMAND]', 'Generate individual MVC files or scaffolds'.colorize(:grey))
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ require 'eucalypt/eucalypt-generate/namespaces/generate-controller/generators/controller'
2
+ require 'eucalypt/app'
3
+ require 'eucalypt/errors'
4
+ require 'eucalypt/helpers'
5
+
6
+ module Eucalypt
7
+ class Generate < Thor
8
+ include Eucalypt::Helpers
9
+ using Colorize
10
+ option :spec, type: :boolean, default: true, desc: "Include a controller spec file"
11
+ option :rest, aliases: '-r', type: :boolean, default: false, desc: "Generate REST routes for the controller"
12
+ desc "controller [NAME]", "Generates a controller".colorize(:grey)
13
+ def controller(name)
14
+ directory = File.expand_path('.')
15
+ if Eucalypt.app? directory
16
+ controller = Eucalypt::Generators::Controller.new
17
+ controller.destination_root = directory
18
+ controller.generate(
19
+ name: name,
20
+ spec: options[:spec],
21
+ rest: options[:rest],
22
+ policy: false
23
+ )
24
+ else
25
+ Eucalypt::Error.wrong_directory
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,45 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+ require 'string/builder'
4
+ require 'thor'
5
+
6
+ module Eucalypt
7
+ module Generators
8
+ class Controller < Thor::Group
9
+ include Thor::Actions
10
+ include Eucalypt::Helpers
11
+ using String::Builder
12
+
13
+ def self.source_root
14
+ File.join File.dirname(__dir__), 'templates'
15
+ end
16
+
17
+ def generate(spec: true, rest: false, policy: false, name:)
18
+ controller = Inflect.new(:controller, name)
19
+
20
+ route = '/' << (rest ? controller.route_name.pluralize : controller.route_name)
21
+
22
+ controller_file_name = String.build do |s|
23
+ s << 'policy_' if policy
24
+ s << 'rest_' if rest
25
+ s << 'controller.tt'
26
+ end
27
+ controller_template = File.join 'controller', controller_file_name
28
+
29
+ helper = Inflect.new(:helper, controller.resource)
30
+
31
+ config = {
32
+ route: route,
33
+ constant: controller.constant,
34
+ class_name: controller.class_name,
35
+ helper_class_name: helper.class_name,
36
+ resource: controller.resource,
37
+ resources: controller.resources
38
+ }
39
+
40
+ template(controller_template, controller.file_path, config)
41
+ template("controller_spec.tt", controller.spec_path, config) if spec
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ class <%= config[:class_name] %> < Eucalypt::Controller(route: '<%= config[:route] %>')
2
+ helpers <%= config[:helper_class_name] %> if defined? <%= config[:helper_class_name] %>
3
+ end
@@ -0,0 +1,71 @@
1
+ class <%= config[:class_name] %> < Eucalypt::Controller(route: '<%= config[:route] %>')
2
+ helpers <%= config[:helper_class_name] %> if defined? <%= config[:helper_class_name] %>
3
+
4
+ # You can use the `current_user` helper provided by Warden in your views.
5
+
6
+ # You can also use authorization helpers provided by Pundit in your views.
7
+ # These are useful for conditional displays to users with the correct permissions.
8
+ # - e.g. Showing a form for editing <%= config[:resources] %>
9
+
10
+ # Pundit authorization helpers are used in the following way:
11
+ # - `policy(<%= config[:constant] %>).add?`
12
+ # - `policy(<%= config[:constant] %>).edit?`
13
+ # - `policy(<%= config[:constant] %>).delete?`
14
+
15
+ # GET - Browse
16
+ get '/' do
17
+ @<%= config[:resources] %> = <%= config[:constant] %>.all
18
+ # Render a view here for displaying all <%= config[:resources] %>
19
+ end
20
+
21
+ # GET - Read
22
+ get '/:id' do |id|
23
+ @<%= config[:resource] %> = <%= config[:constant] %>.find id
24
+ # Render a view here for displaying a single <%= config[:resource] %>
25
+ rescue ActiveRecord::RecordNotFound
26
+ status 404 # Resource not found
27
+ redirect to '/'
28
+ end
29
+
30
+ # POST - Edit
31
+ post '/:id/edit' do |id|
32
+ authenticate
33
+ <%= config[:resource] %> = <%= config[:constant] %>.find id
34
+ authorize <%= config[:resource]%>, :edit?
35
+ <%= config[:resource] %>.update! params['<%= config[:resource] %>']
36
+ redirect to "/#{id}"
37
+ rescue ActiveRecord::RecordNotFound
38
+ status 404 # Resource not found
39
+ redirect to "/#{id}"
40
+ rescue Pundit::NotAuthorizedError
41
+ status 401 # Unauthorized
42
+ redirect to '/'
43
+ end
44
+
45
+ # POST - Add
46
+ post '/' do
47
+ authenticate
48
+ <%= config[:resource] %> = <%= config[:constant] %>.new params['<%= config[:resource] %>']
49
+ authorize <%= config[:resource] %>, :add?
50
+ <%= config[:resource] %>.save!
51
+ redirect to "/#{<%= config[:resource] %>.id}"
52
+ rescue Pundit::NotAuthorizedError
53
+ status 401 # Unauthorized
54
+ redirect to '/'
55
+ end
56
+
57
+ # POST - Delete
58
+ post '/:id/delete' do |id|
59
+ authenticate
60
+ <%= config[:resource] %> = <%= config[:constant] %>.find id
61
+ authorize <%= config[:resource]%>, :delete?
62
+ <%= config[:resource] %>.destroy!
63
+ redirect to '/'
64
+ rescue ActiveRecord::RecordNotFound
65
+ status 404 # Resource not found
66
+ redirect to "/#{id}"
67
+ rescue Pundit::NotAuthorizedError
68
+ status 401 # Unauthorized
69
+ redirect to '/'
70
+ end
71
+ end
@@ -0,0 +1,28 @@
1
+ class <%= config[:class_name] %> < Eucalypt::Controller(route: '<%= config[:route] %>')
2
+ helpers <%= config[:helper_class_name] %> if defined? <%= config[:helper_class_name] %>
3
+
4
+ # GET - Browse
5
+ get '/' do
6
+
7
+ end
8
+
9
+ # GET - Read
10
+ get '/:id' do |id|
11
+
12
+ end
13
+
14
+ # POST - Edit
15
+ post '/:id/edit' do |id|
16
+
17
+ end
18
+
19
+ # POST - Add
20
+ post '/' do
21
+
22
+ end
23
+
24
+ # POST - Delete
25
+ post '/:id/delete' do |id|
26
+
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe <%= config[:class_name] %> do
4
+ def app() <%= config[:class_name] %> end
5
+
6
+ it "should expect true to be true" do
7
+ expect(true).to be false
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ require 'eucalypt/eucalypt-generate/namespaces/generate-helper/generators/helper'
2
+ require 'eucalypt/app'
3
+ require 'eucalypt/errors'
4
+ require 'eucalypt/helpers'
5
+
6
+ module Eucalypt
7
+ class Generate < Thor
8
+ include Eucalypt::Helpers
9
+ using Colorize
10
+ option :spec, type: :boolean, default: true, desc: "Include a helper spec file"
11
+ desc "helper [NAME]", "Generates a helper".colorize(:grey)
12
+ def helper(name)
13
+ directory = File.expand_path('.')
14
+ if Eucalypt.app? directory
15
+ helper = Eucalypt::Generators::Helper.new
16
+ helper.destination_root = directory
17
+ helper.generate(name: name, spec: options[:spec])
18
+ else
19
+ Eucalypt::Error.wrong_directory
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+ require 'thor'
4
+ require 'eucalypt/helpers'
5
+
6
+ module Eucalypt
7
+ module Generators
8
+ class Helper < Thor::Group
9
+ include Thor::Actions
10
+ include Eucalypt::Helpers
11
+
12
+ def self.source_root
13
+ File.join File.dirname(__dir__), 'templates'
14
+ end
15
+
16
+ def generate(spec: true, name:)
17
+ helper = Inflect.new(:helper, name)
18
+ config = {class_name: helper.class_name}
19
+ template("helper.tt", helper.file_path, config)
20
+ template("helper_spec.tt", helper.spec_path, config) if spec
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module <%= config[:class_name] %>
2
+ # Add your methods...
3
+ end
@@ -0,0 +1,9 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe <%= config[:class_name] %> do
4
+ include <%= config[:class_name] %>
5
+
6
+ it "should expect true to be true" do
7
+ expect(true).to be false
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ require 'eucalypt/eucalypt-generate/namespaces/generate-model/generators/model'
2
+ require 'eucalypt/app'
3
+ require 'eucalypt/errors'
4
+ require 'eucalypt/helpers'
5
+
6
+ module Eucalypt
7
+ class Generate < Thor
8
+ include Eucalypt::Helpers
9
+ using Colorize
10
+ option :table, type: :boolean, default: true, desc: "Generate table migration"
11
+ option :spec, type: :boolean, default: true, desc: "Include a model spec file"
12
+ desc "model [NAME] *[COLUMN∶TYPE]", "Generates a model".colorize(:grey)
13
+ def model(name, *columns)
14
+ directory = File.expand_path('.')
15
+ if Eucalypt.app? directory
16
+ validation = Eucalypt::Helpers::Migration::Validation.new columns
17
+ return if validation.any_invalid?
18
+ model = Eucalypt::Generators::Model.new
19
+ model.destination_root = directory
20
+ model.generate(name: name, spec: options[:spec], table: options[:table], columns: columns)
21
+ else
22
+ Eucalypt::Error.wrong_directory
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+ require 'thor'
4
+ require 'eucalypt/helpers'
5
+
6
+ module Eucalypt
7
+ module Generators
8
+ class Model < Thor::Group
9
+ include Thor::Actions
10
+ include Eucalypt::Helpers
11
+
12
+ def self.source_root
13
+ File.join File.dirname(__dir__), 'templates'
14
+ end
15
+
16
+ def generate(spec: true, columns: [], table: true, name:)
17
+ model = Inflect.new(:model, name)
18
+ config = {class_name: model.class_name}
19
+ template("model.tt", model.file_path, config)
20
+ template("model_spec.tt", model.spec_path, config) if spec
21
+ Eucalypt::CLI.start(['migration', 'create', 'table', Inflect.resources(name), *columns]) if table
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ class <%= config[:class_name] %> < ActiveRecord::Base
2
+ # Add your model methods here...
3
+ end
@@ -0,0 +1,8 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe <%= config[:class_name] %>, type: :model do
4
+
5
+ it "should expect true to be true" do
6
+ expect(true).to be false
7
+ end
8
+ end
@@ -0,0 +1,93 @@
1
+ require 'eucalypt/helpers/numeric'
2
+ require 'eucalypt/helpers/inflect'
3
+ require 'thor'
4
+ module Eucalypt
5
+ class Migration < Thor
6
+ module Helpers
7
+ include Eucalypt::Helpers
8
+
9
+ def sanitize_table_options(options) # primary_key id temporary force
10
+ sanitized_options = []
11
+ options.keys.each do |option|
12
+ value = options[option]
13
+ option = option.to_sym
14
+
15
+ case option
16
+ when :primary_key
17
+ next unless /\A[^,]+(,[^,]+)*\Z/.match? value
18
+ opts = value.split(?,).map{|v| Inflect.resource_keep_inflection(v)}
19
+ opts.reject! &:empty?
20
+ next if opts.empty?
21
+ sanitized_options << (opts.size == 1 ? [option, ":#{opts.first}"] : [option, "%i[#{(opts.map {|v| "#{v}"}*' ')}]"])
22
+ when :id
23
+ id = Inflect.resource_keep_inflection(value)
24
+ next if id.empty?
25
+ sanitized_options << (%w[true false].include?(id) ? [option, id] : [option, ":#{id}"])
26
+ when :temporary
27
+ sanitized_options << [option, value] if %w[true false].include? value
28
+ when :force
29
+ sanitized_options << [option, ":#{value}"] if value == 'cascade'
30
+ sanitized_options << [option, value] if %w[true false].include? value
31
+ end
32
+ end
33
+ sanitized_options
34
+ end
35
+
36
+ def sanitize_index_options(options) # unique length where using type
37
+ sanitized_options = []
38
+ options.keys.each do |option|
39
+ value = options[option]
40
+ option = option.to_sym
41
+
42
+ case option
43
+ when :unique
44
+ sanitized_options << [option, value] if %w[true false].include? value
45
+ when :length
46
+ sanitized_options << [option, value] if Eucalypt::Helpers::Numeric.string? value
47
+ when :where
48
+ partial = Inflect.resource_keep_inflection(value)
49
+ next if partial.empty?
50
+ sanitized_options << [option, ":#{partial}"]
51
+ when :using
52
+ method = Inflect.resource_keep_inflection(value)
53
+ next if method.empty?
54
+ sanitized_options << [option, ":#{method}"]
55
+ when :type
56
+ type = Inflect.resource_keep_inflection(value)
57
+ next if type.empty?
58
+ sanitized_options << [option, ":#{type}"]
59
+ end
60
+ end
61
+ sanitized_options
62
+ end
63
+
64
+ def sanitize_column_options(options)
65
+ sanitized_options = []
66
+ options.keys.each do |option|
67
+ value = options[option]
68
+ option = option.to_sym
69
+
70
+ case option
71
+ when :limit
72
+ sanitized_options << [option, value] if Eucalypt::Helpers::Numeric.string? value
73
+ when :default
74
+ if %w[nil null].include? value
75
+ sanitized_options << [option, 'nil']
76
+ elsif Eucalypt::Helpers::Numeric.string? value
77
+ sanitized_options << [option, value]
78
+ else
79
+ sanitized_options << [option, "\'#{value}\'"]
80
+ end
81
+ when :null
82
+ sanitized_options << [option, value] if %w[true false].include? value
83
+ when :precision
84
+ sanitized_options << [option, value] if Eucalypt::Helpers::Numeric.string? value
85
+ when :scale
86
+ sanitized_options << [option, value] if Eucalypt::Helpers::Numeric.string? value
87
+ end
88
+ end
89
+ sanitized_options
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,4 @@
1
+ class <%= config[:migration_class_name] %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
+ def change
3
+ end
4
+ end
@@ -0,0 +1,39 @@
1
+ require 'eucalypt/eucalypt-migration/namespaces/migration-create/cli/create'
2
+ require 'eucalypt/eucalypt-migration/namespaces/migration-add/cli/add'
3
+ require 'eucalypt/eucalypt-migration/namespaces/migration-drop/cli/drop'
4
+ require 'eucalypt/eucalypt-migration/namespaces/migration-rename/cli/rename'
5
+ require 'eucalypt/eucalypt-migration/namespaces/migration-change/cli/change'
6
+ require 'eucalypt/eucalypt-migration/namespaces/migration-blank/cli/blank'
7
+ require 'eucalypt/helpers'
8
+
9
+ module Eucalypt
10
+ class Migration < Thor
11
+ include Thor::Actions
12
+ include Eucalypt::Helpers
13
+ using Colorize
14
+
15
+ desc "types", "Display permitted column types".colorize(:grey)
16
+ def types
17
+ puts Eucalypt::Helpers::Migration::Validation::COLUMN_TYPES.inspect
18
+ end
19
+
20
+ class << self
21
+ require 'eucalypt/list'
22
+ include Eucalypt::List
23
+ def banner(task, namespace = false, subcommand = true)
24
+ basename + ' ' + task.formatted_usage(self, true, subcommand).split(':').join(' ')
25
+ end
26
+ end
27
+
28
+ register(Eucalypt::MigrationCreate, 'create', 'create [COMMAND]', 'Create tables'.colorize(:grey))
29
+ register(Eucalypt::MigrationAdd, 'add', 'add [COMMAND]', 'Add indexes and columns to a table'.colorize(:grey))
30
+ register(Eucalypt::MigrationDrop, 'drop', 'drop [COMMAND]', 'Drop tables, columns and indexes'.colorize(:grey))
31
+ register(Eucalypt::MigrationRename, 'rename', 'rename [COMMAND]', 'Rename tables, columns and indexes'.colorize(:grey))
32
+ register(Eucalypt::MigrationChange, 'change', 'change [COMMAND]', 'Change column definitions'.colorize(:grey))
33
+ end
34
+ class CLI < Thor
35
+ include Eucalypt::Helpers
36
+ using Colorize
37
+ register(Migration, 'migration', 'migration [COMMAND]', 'Generate ActiveRecord migrations'.colorize(:grey))
38
+ end
39
+ end
@@ -0,0 +1,25 @@
1
+ require 'eucalypt/eucalypt-migration/namespaces/migration-add/generators/column'
2
+ require 'eucalypt/app'
3
+ require 'eucalypt/errors'
4
+ require 'eucalypt/helpers'
5
+
6
+ module Eucalypt
7
+ class MigrationAdd < Thor
8
+ include Eucalypt::Helpers
9
+ using Colorize
10
+
11
+ option :options, aliases: '-o', type: :hash, default: {}, enum: %w[limit default null precision scale], desc: "Column options"
12
+ desc "column [TABLE] [COLUMN] [TYPE]", "Adds a column".colorize(:grey)
13
+ def column(table, column, type)
14
+ directory = File.expand_path('.')
15
+ if Eucalypt.app? directory
16
+ return unless Eucalypt::Helpers::Migration::Validation.valid_type? type
17
+ migration = Eucalypt::Generators::Add::Column.new
18
+ migration.destination_root = directory
19
+ migration.generate(table: table, column: column, type: type, options: options[:options])
20
+ else
21
+ Eucalypt::Error.wrong_directory
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require 'eucalypt/eucalypt-migration/namespaces/migration-add/generators/index'
2
+ require 'eucalypt/app'
3
+ require 'eucalypt/errors'
4
+ require 'eucalypt/helpers'
5
+
6
+ module Eucalypt
7
+ class MigrationAdd < Thor
8
+ include Eucalypt::Helpers
9
+ using Colorize
10
+
11
+ option :name, aliases: '-n', type: :string, desc: "Index name"
12
+ option :options, aliases: '-o', type: :hash, default: {}, enum: %w[unique length where using type], desc: "Index options"
13
+ desc "index [TABLE] *[COLUMNS]", "Adds an index".colorize(:grey)
14
+ def index(table, *columns)
15
+ directory = File.expand_path('.')
16
+ if Eucalypt.app? directory
17
+ migration = Eucalypt::Generators::Add::Index.new
18
+ migration.destination_root = directory
19
+ migration.generate(table: table, columns: columns, name: options[:name]||'index', options: options[:options])
20
+ else
21
+ Eucalypt::Error.wrong_directory
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ require 'thor'
2
+ require 'eucalypt/helpers'
3
+ require_relative 'add-index'
4
+ require_relative 'add-column'
5
+
6
+ module Eucalypt
7
+ class MigrationAdd < Thor
8
+ include Thor::Actions
9
+
10
+ class << self
11
+ require 'eucalypt/list'
12
+ include Eucalypt::List
13
+ def banner(task, namespace = false, subcommand = true)
14
+ "#{basename} migration #{task.formatted_usage(self, true, subcommand).split(':').join(' ')}"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,46 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+ require 'string/builder'
4
+ require 'thor'
5
+ require 'eucalypt/eucalypt-migration/helpers'
6
+
7
+ module Eucalypt
8
+ module Generators
9
+ module Add
10
+ class Column < Thor::Group
11
+ include Thor::Actions
12
+ include Eucalypt::Helpers
13
+ include Eucalypt::Migration::Helpers
14
+ using String::Builder
15
+
16
+ def self.source_root
17
+ File.join File.dirname(File.dirname(File.dirname __dir__))
18
+ end
19
+
20
+ def generate(table:, column:, type:, options: {})
21
+ table = Inflect.resource_keep_inflection(table.to_s)
22
+ column = Inflect.resource_keep_inflection(column.to_s)
23
+ type = Inflect.resource_keep_inflection(type.to_s)
24
+
25
+ sleep 1
26
+ migration_name = "add_#{column}_to_#{table}"
27
+ migration = Eucalypt::Helpers::Migration[title: migration_name, template: 'migration_base.tt']
28
+ return unless migration.create_anyway? if migration.exists?
29
+ config = {migration_class_name: migration_name.camelize}
30
+ template migration.template, migration.file_path, config
31
+
32
+ sanitized_options = sanitize_column_options(options)
33
+
34
+ insert_into_file migration.file_path, :after => "def change\n" do
35
+ String.build do |s|
36
+ s << " add_column :#{table}, :#{column}, :#{type}"
37
+ s << ', ' unless sanitized_options.empty?
38
+ s << sanitized_options.map{|opt| "#{opt.first}: #{opt.last}"}*', '
39
+ s << "\n"
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,52 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+ require 'string/builder'
4
+ require 'thor'
5
+ require 'eucalypt/eucalypt-migration/helpers'
6
+
7
+ module Eucalypt
8
+ module Generators
9
+ module Add
10
+ class Index < Thor::Group
11
+ include Thor::Actions
12
+ include Eucalypt::Helpers
13
+ include Eucalypt::Migration::Helpers
14
+ using String::Builder
15
+
16
+ def self.source_root
17
+ File.join File.dirname(File.dirname(File.dirname __dir__))
18
+ end
19
+
20
+ def generate(table:, columns: [], options: {}, name:)
21
+ name = Inflect.resource_keep_inflection(name.to_s)
22
+ table = Inflect.resource_keep_inflection(table.to_s)
23
+ columns.map!{|i| Inflect.resource_keep_inflection(i)}
24
+
25
+ sleep 1
26
+ migration_name = "add_#{name}_to_#{table}"
27
+ migration = Eucalypt::Helpers::Migration[title: migration_name, template: 'migration_base.tt']
28
+ return unless migration.create_anyway? if migration.exists?
29
+ config = {migration_class_name: migration_name.camelize}
30
+ template migration.template, migration.file_path, config
31
+
32
+ sanitized_options = sanitize_index_options(options)
33
+
34
+ insert_into_file migration.file_path, :after => "def change\n" do
35
+ String.build do |s|
36
+ s << " add_index :#{table}, "
37
+ unless columns.empty?
38
+ columns.map!(&:to_sym)
39
+ s << (columns.size == 1 ? ":#{columns.first}" : "%i[#{columns*' '}]")
40
+ s << ', ' unless name.empty? || name == 'index'
41
+ end
42
+ s << "name: :#{name}" unless name.empty? || name == 'index'
43
+ s << ', ' unless sanitized_options.empty?
44
+ s << sanitized_options.map{|opt| "#{opt.first}: #{opt.last}"}*', '
45
+ s << "\n"
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end