eucalypt 0.1.0

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.
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,22 @@
1
+ require 'eucalypt/eucalypt-migration/namespaces/migration-blank/generators/blank'
2
+ require 'eucalypt/app'
3
+ require 'eucalypt/errors'
4
+ require 'eucalypt/helpers'
5
+
6
+ module Eucalypt
7
+ class Migration < Thor
8
+ include Eucalypt::Helpers
9
+ using Colorize
10
+ desc "blank [NAME]", "Creates a blank migration".colorize(:grey)
11
+ def blank(name)
12
+ directory = File.expand_path('.')
13
+ if Eucalypt.app? directory
14
+ migration = Eucalypt::Generators::Blank.new
15
+ migration.destination_root = directory
16
+ migration.generate(name: name)
17
+ else
18
+ Eucalypt::Error.wrong_directory
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
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 Blank < 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(File.dirname(File.dirname __dir__))
15
+ end
16
+
17
+ def generate(name:)
18
+ migration_name = Inflect.resource_keep_inflection(name.to_s)
19
+
20
+ sleep 1
21
+ migration = Eucalypt::Helpers::Migration[title: migration_name, template: 'migration_base.tt']
22
+ return unless migration.create_anyway? if migration.exists?
23
+ config = {migration_class_name: migration_name.camelize}
24
+ template migration.template, migration.file_path, config
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ require 'eucalypt/eucalypt-migration/namespaces/migration-change/generators/column'
2
+ require 'eucalypt/helpers'
3
+ require 'eucalypt/errors'
4
+
5
+ module Eucalypt
6
+ class MigrationChange < Thor
7
+ include Eucalypt::Helpers
8
+ using Colorize
9
+ option :options, aliases: '-o', type: :hash, default: {}, enum: %w[limit default null precision scale], desc: "Column options"
10
+ desc "column [TABLE] [COLUMN] [TYPE]", "Changes a column's type definition".colorize(:grey)
11
+ def column(table, column, type)
12
+ directory = File.expand_path('.')
13
+ if Eucalypt.app? directory
14
+ return unless Eucalypt::Helpers::Migration::Validation.valid_type? type
15
+ migration = Eucalypt::Generators::Change::Column.new
16
+ migration.destination_root = directory
17
+ migration.generate(table: table, column: column, type: type, options: options[:options])
18
+ else
19
+ Eucalypt::Error.wrong_directory
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ require 'thor'
2
+ require 'eucalypt/helpers'
3
+ require_relative 'change-column'
4
+
5
+ module Eucalypt
6
+ class MigrationChange < Thor
7
+ include Thor::Actions
8
+
9
+ class << self
10
+ require 'eucalypt/list'
11
+ include Eucalypt::List
12
+ def banner(task, namespace = false, subcommand = true)
13
+ "#{basename} migration #{task.formatted_usage(self, true, subcommand).split(':').join(' ')}"
14
+ end
15
+ end
16
+ end
17
+ 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 Change
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 = "change_#{column}_column_on_#{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 << " change_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,25 @@
1
+ require 'eucalypt/eucalypt-migration/namespaces/migration-create/generators/table'
2
+ require 'eucalypt/app'
3
+ require 'eucalypt/errors'
4
+ require 'eucalypt/helpers'
5
+
6
+ module Eucalypt
7
+ class MigrationCreate < Thor
8
+ include Eucalypt::Helpers
9
+ using Colorize
10
+ option :options, aliases: '-o', type: :hash, default: {}, enum: %w[primary_key id temporary force], desc: "Table options"
11
+ desc "table [NAME] *[COLUMN∶TYPE]", "Creates a table".colorize(:grey)
12
+ def table(name, *columns)
13
+ directory = File.expand_path('.')
14
+ if Eucalypt.app? directory
15
+ validation = Eucalypt::Helpers::Migration::Validation.new columns
16
+ return if validation.any_invalid?
17
+ migration = Eucalypt::Generators::Create::Table.new
18
+ migration.destination_root = directory
19
+ migration.generate(name: name, columns: columns, options: options[:options])
20
+ else
21
+ Eucalypt::Error.wrong_directory
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ require 'thor'
2
+ require 'eucalypt/helpers'
3
+ require_relative 'create-table'
4
+
5
+ module Eucalypt
6
+ class MigrationCreate < Thor
7
+ include Thor::Actions
8
+
9
+ class << self
10
+ require 'eucalypt/list'
11
+ include Eucalypt::List
12
+ def banner(task, namespace = false, subcommand = true)
13
+ "#{basename} migration #{task.formatted_usage(self, true, subcommand).split(':').join(' ')}"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,53 @@
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 Create
10
+ class Table < 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(columns: [], options: {}, name:)
21
+ name = Inflect.resources(name.to_s)
22
+ columns.map!{|c| c.split(?:).map{|i| Inflect.resource_keep_inflection(i)}}
23
+
24
+ sleep 1
25
+ migration_name = "create_#{name}"
26
+ migration = Eucalypt::Helpers::Migration[title: migration_name, template: 'migration_base.tt']
27
+ return unless migration.create_anyway? if migration.exists?
28
+ config = {migration_class_name: migration_name.camelize}
29
+ template migration.template, migration.file_path, config
30
+
31
+ sanitized_options = sanitize_table_options(options)
32
+
33
+ insert_into_file migration.file_path, :after => "def change\n" do
34
+ String.build do |s|
35
+ s << " create_table :#{name}"
36
+ s << ', ' unless sanitized_options.empty?
37
+ s << sanitized_options.map{|opt| "#{opt.first}: #{opt.last}"}*', '
38
+ unless columns.empty?
39
+ s << " do |t|\n"
40
+ columns.each do |column|
41
+ n, t = column
42
+ s << " t.#{t} :#{n}\n"
43
+ end
44
+ s << " end"
45
+ end
46
+ s << "\n"
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,22 @@
1
+ require 'eucalypt/eucalypt-migration/namespaces/migration-drop/generators/column'
2
+ require 'eucalypt/app'
3
+ require 'eucalypt/errors'
4
+ require 'eucalypt/helpers'
5
+
6
+ module Eucalypt
7
+ class MigrationDrop < Thor
8
+ include Eucalypt::Helpers
9
+ using Colorize
10
+ desc "column [TABLE] [NAME]", "Removes a column from a table".colorize(:grey)
11
+ def column(table, name)
12
+ directory = File.expand_path('.')
13
+ if Eucalypt.app? directory
14
+ migration = Eucalypt::Generators::Drop::Column.new
15
+ migration.destination_root = directory
16
+ migration.generate(table: table, name: name)
17
+ else
18
+ Eucalypt::Error.wrong_directory
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ require 'eucalypt/eucalypt-migration/namespaces/migration-drop/generators/index'
2
+ require 'eucalypt/app'
3
+ require 'eucalypt/errors'
4
+ require 'eucalypt/helpers'
5
+
6
+ module Eucalypt
7
+ class MigrationDrop < Thor
8
+ include Eucalypt::Helpers
9
+ using Colorize
10
+ option :name, aliases: '-n', type: :string, desc: "Index name"
11
+ desc "index [TABLE] [*COLUMNS]", "Removes an index from a table".colorize(:grey)
12
+ def index(table, *columns)
13
+ directory = File.expand_path('.')
14
+ if Eucalypt.app? directory
15
+ migration = Eucalypt::Generators::Drop::Index.new
16
+ migration.destination_root = directory
17
+ migration.generate(table: table, columns: columns, name: options[:name]||'index')
18
+ else
19
+ Eucalypt::Error.wrong_directory
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ require 'eucalypt/eucalypt-migration/namespaces/migration-drop/generators/table'
2
+ require 'eucalypt/app'
3
+ require 'eucalypt/errors'
4
+ require 'eucalypt/helpers'
5
+
6
+ module Eucalypt
7
+ class MigrationDrop < Thor
8
+ include Eucalypt::Helpers
9
+ using Colorize
10
+ desc "table [NAME]", "Removes a table".colorize(:grey)
11
+ def table(name)
12
+ directory = File.expand_path('.')
13
+ if Eucalypt.app? directory
14
+ migration = Eucalypt::Generators::Drop::Table.new
15
+ migration.destination_root = directory
16
+ migration.generate(name: name)
17
+ else
18
+ Eucalypt::Error.wrong_directory
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ require 'thor'
2
+ require 'eucalypt/helpers'
3
+ require_relative 'drop-table'
4
+ require_relative 'drop-index'
5
+ require_relative 'drop-column'
6
+
7
+ module Eucalypt
8
+ class MigrationDrop < Thor
9
+ include Thor::Actions
10
+
11
+ class << self
12
+ require 'eucalypt/list'
13
+ include Eucalypt::List
14
+ def banner(task, namespace = false, subcommand = true)
15
+ "#{basename} migration #{task.formatted_usage(self, true, subcommand).split(':').join(' ')}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,38 @@
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
+ module Drop
9
+ class Column < Thor::Group
10
+ include Thor::Actions
11
+ include Eucalypt::Helpers
12
+ using String::Builder
13
+
14
+ def self.source_root
15
+ File.join File.dirname(File.dirname(File.dirname __dir__))
16
+ end
17
+
18
+ def generate(table:, name:)
19
+ table = Inflect.resource_keep_inflection(table.to_s)
20
+ name = Inflect.resource_keep_inflection(name.to_s)
21
+
22
+ sleep 1
23
+ migration_name = "drop_#{name}_from_#{table}"
24
+ migration = Eucalypt::Helpers::Migration[title: migration_name, template: 'migration_base.tt']
25
+ return unless migration.create_anyway? if migration.exists?
26
+ config = {migration_class_name: migration_name.camelize}
27
+ template migration.template, migration.file_path, config
28
+
29
+ insert_into_file migration.file_path, :after => "def change\n" do
30
+ String.build do |s|
31
+ s << " remove_column :#{table}, :#{name}\n"
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,48 @@
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
+ module Drop
9
+ class Index < Thor::Group
10
+ include Thor::Actions
11
+ include Eucalypt::Helpers
12
+ using String::Builder
13
+
14
+ def self.source_root
15
+ File.join File.dirname(File.dirname(File.dirname __dir__))
16
+ end
17
+
18
+ def generate(table:, columns: [], name:)
19
+ table = Inflect.resource_keep_inflection(table.to_s)
20
+ name = Inflect.resource_keep_inflection(name.to_s)
21
+
22
+ sleep 1
23
+ migration_name = "drop_#{name}_from_#{table}"
24
+ migration = Eucalypt::Helpers::Migration[title: migration_name, template: 'migration_base.tt']
25
+ return unless migration.create_anyway? if migration.exists?
26
+ config = {migration_class_name: migration_name.camelize}
27
+ template migration.template, migration.file_path, config
28
+
29
+ insert_into_file migration.file_path, :after => "def change\n" do
30
+ String.build do |s|
31
+ s << " remove_index :#{table}"
32
+ unless name.empty? || name == 'index'
33
+ s << ", name: :#{name}"
34
+ else
35
+ unless columns.empty?
36
+ columns.map!(&:to_sym)
37
+ s << ", column: "
38
+ s << (columns.size == 1 ? ":#{columns.first}" : "%i[#{columns*' '}]")
39
+ end
40
+ end
41
+ s << "\n"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,37 @@
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
+ module Drop
9
+ class Table < Thor::Group
10
+ include Thor::Actions
11
+ include Eucalypt::Helpers
12
+ using String::Builder
13
+
14
+ def self.source_root
15
+ File.join File.dirname(File.dirname(File.dirname __dir__))
16
+ end
17
+
18
+ def generate(name:)
19
+ name = Inflect.resource_keep_inflection(name.to_s)
20
+
21
+ sleep 1
22
+ migration_name = "drop_#{name}"
23
+ migration = Eucalypt::Helpers::Migration[title: migration_name, template: 'migration_base.tt']
24
+ return unless migration.create_anyway? if migration.exists?
25
+ config = {migration_class_name: migration_name.camelize}
26
+ template migration.template, migration.file_path, config
27
+
28
+ insert_into_file migration.file_path, :after => "def change\n" do
29
+ String.build do |s|
30
+ s << " drop_table :#{name}\n"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,22 @@
1
+ require 'eucalypt/eucalypt-migration/namespaces/migration-rename/generators/column'
2
+ require 'eucalypt/helpers'
3
+ require 'eucalypt/errors'
4
+
5
+ module Eucalypt
6
+ class MigrationRename < Thor
7
+ include Eucalypt::Helpers
8
+ using Colorize
9
+
10
+ desc "column [TABLE] [OLD] [NEW]", "Renames a column".colorize(:grey)
11
+ def column(table, old_name, new_name)
12
+ directory = File.expand_path('.')
13
+ if Eucalypt.app? directory
14
+ migration = Eucalypt::Generators::Rename::Column.new
15
+ migration.destination_root = directory
16
+ migration.generate(table: table, old_name: old_name, new_name: new_name)
17
+ else
18
+ Eucalypt::Error.wrong_directory
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'eucalypt/eucalypt-migration/namespaces/migration-rename/generators/index'
2
+ require 'eucalypt/helpers'
3
+ require 'eucalypt/errors'
4
+
5
+ module Eucalypt
6
+ class MigrationRename < Thor
7
+ include Eucalypt::Helpers
8
+ using Colorize
9
+
10
+ desc "index [TABLE] [OLD] [NEW]", "Renames an index".colorize(:grey)
11
+ def index(table, old_name, new_name)
12
+ directory = File.expand_path('.')
13
+ if Eucalypt.app? directory
14
+ migration = Eucalypt::Generators::Rename::Index.new
15
+ migration.destination_root = directory
16
+ migration.generate(table: table, old_name: old_name, new_name: new_name)
17
+ else
18
+ Eucalypt::Error.wrong_directory
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ require 'eucalypt/eucalypt-migration/namespaces/migration-rename/generators/table'
2
+ require 'eucalypt/helpers'
3
+ require 'eucalypt/errors'
4
+
5
+ module Eucalypt
6
+ class MigrationRename < Thor
7
+ include Eucalypt::Helpers
8
+ include Eucalypt::Helpers::Messages
9
+ using Colorize
10
+
11
+ desc "table [OLD] [NEW]", "Renames a table".colorize(:grey)
12
+ def table(old_name, new_name)
13
+ directory = File.expand_path('.')
14
+ if Eucalypt.app? directory
15
+ Out.warning "This command #{"will not".colorize(:bold)} rename any associated model."
16
+ migration = Eucalypt::Generators::Rename::Table.new
17
+ migration.destination_root = directory
18
+ migration.generate(old_name: old_name, new_name: new_name)
19
+ else
20
+ Eucalypt::Error.wrong_directory
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ require 'thor'
2
+ require 'eucalypt/helpers'
3
+ require_relative 'rename-column'
4
+ require_relative 'rename-index'
5
+ require_relative 'rename-table'
6
+
7
+ module Eucalypt
8
+ class MigrationRename < Thor
9
+ include Thor::Actions
10
+
11
+ class << self
12
+ require 'eucalypt/list'
13
+ include Eucalypt::List
14
+ def banner(task, namespace = false, subcommand = true)
15
+ "#{basename} migration #{task.formatted_usage(self, true, subcommand).split(':').join(' ')}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
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
+ module Rename
9
+ class Column < Thor::Group
10
+ include Thor::Actions
11
+ include Eucalypt::Helpers
12
+ using String::Builder
13
+
14
+ def self.source_root
15
+ File.join File.dirname(File.dirname(File.dirname __dir__))
16
+ end
17
+
18
+ def generate(table:, old_name:, new_name:)
19
+ table = Inflect.resource_keep_inflection(table.to_s)
20
+ old_name = Inflect.resource_keep_inflection(old_name.to_s)
21
+ new_name = Inflect.resource_keep_inflection(new_name.to_s)
22
+
23
+ sleep 1
24
+ migration_name = "rename_#{old_name}_on_#{table}"
25
+ migration = Eucalypt::Helpers::Migration[title: migration_name, template: 'migration_base.tt']
26
+ return unless migration.create_anyway? if migration.exists?
27
+ config = {migration_class_name: migration_name.camelize}
28
+ template migration.template, migration.file_path, config
29
+
30
+ insert_into_file migration.file_path, :after => "def change\n" do
31
+ String.build do |s|
32
+ s << " rename_column :#{table}, :#{old_name}, :#{new_name}\n"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
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
+ module Rename
9
+ class Index < Thor::Group
10
+ include Thor::Actions
11
+ include Eucalypt::Helpers
12
+ using String::Builder
13
+
14
+ def self.source_root
15
+ File.join File.dirname(File.dirname(File.dirname __dir__))
16
+ end
17
+
18
+ def generate(table:, old_name:, new_name:)
19
+ table = Inflect.resource_keep_inflection(table.to_s)
20
+ old_name = Inflect.resource_keep_inflection(old_name.to_s)
21
+ new_name = Inflect.resource_keep_inflection(new_name.to_s)
22
+
23
+ sleep 1
24
+ migration_name = "rename_#{old_name}_on_#{table}"
25
+ migration = Eucalypt::Helpers::Migration[title: migration_name, template: 'migration_base.tt']
26
+ return unless migration.create_anyway? if migration.exists?
27
+ config = {migration_class_name: migration_name.camelize}
28
+ template migration.template, migration.file_path, config
29
+
30
+ insert_into_file migration.file_path, :after => "def change\n" do
31
+ String.build do |s|
32
+ s << " rename_index :#{table}, :#{old_name}, :#{new_name}\n"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,38 @@
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
+ module Rename
9
+ class Table < Thor::Group
10
+ include Thor::Actions
11
+ include Eucalypt::Helpers
12
+ using String::Builder
13
+
14
+ def self.source_root
15
+ File.join File.dirname(File.dirname(File.dirname __dir__))
16
+ end
17
+
18
+ def generate(old_name:, new_name:)
19
+ old_name = Inflect.resource_keep_inflection(old_name.to_s)
20
+ new_name = Inflect.resource_keep_inflection(new_name.to_s)
21
+
22
+ sleep 1
23
+ migration_name = "rename_#{old_name}_to_#{new_name}"
24
+ migration = Eucalypt::Helpers::Migration[title: migration_name, template: 'migration_base.tt']
25
+ return unless migration.create_anyway? if migration.exists?
26
+ config = {migration_class_name: migration_name.camelize}
27
+ template migration.template, migration.file_path, config
28
+
29
+ insert_into_file migration.file_path, :after => "def change\n" do
30
+ String.build do |s|
31
+ s << " rename_table :#{old_name}, :#{new_name}\n"
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end