pg_rails 7.0.1 → 7.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -4
  3. data/pg_associable/app/assets/css/pg_associable.scss +99 -0
  4. data/pg_associable/app/assets/js/asociable_controller.js +59 -0
  5. data/pg_associable/app/assets/js/asociable_inline_controller.js +141 -0
  6. data/pg_associable/app/assets/js/modal_controller.js +130 -0
  7. data/pg_associable/app/helpers/pg_associable/form_builder_methods.rb +31 -0
  8. data/pg_associable/app/helpers/pg_associable/helpers.rb +19 -0
  9. data/pg_associable/app/inputs/pg_associable/pg_associable_inline_input.rb +39 -0
  10. data/pg_associable/app/inputs/pg_associable/pg_associable_input.rb +41 -0
  11. data/pg_associable/app/views/pg_associable/_resultados.html.slim +9 -0
  12. data/pg_associable/app/views/pg_associable/_resultados_inline.html.slim +12 -0
  13. data/pg_associable/app/views/pg_engine/base/_pg_associable_modal.html.slim +39 -0
  14. data/pg_associable/index.js +7 -0
  15. data/pg_associable/lib/pg_associable/engine.rb +12 -0
  16. data/pg_associable/lib/pg_associable/simple_form_initializer.rb +34 -0
  17. data/pg_associable/lib/pg_associable.rb +5 -0
  18. data/{lib/tasks/pg_rails_tasks.rake → pg_associable/lib/tasks/pg_associable_tasks.rake} +1 -2
  19. data/pg_engine/app/assets/stylesheets/pg_rails_b5.scss +74 -0
  20. data/pg_engine/app/controllers/pg_engine/base_controller.rb +365 -0
  21. data/pg_engine/app/controllers/pg_engine/devise_controller.rb +9 -0
  22. data/pg_engine/app/controllers/pg_engine/signed_in_controller.rb +7 -0
  23. data/{app/decorators/pg_rails → pg_engine/app/decorators/pg_engine}/base_decorator.rb +21 -23
  24. data/pg_engine/app/helpers/pg_engine/flash_helper.rb +26 -0
  25. data/pg_engine/app/helpers/pg_engine/form_helper.rb +33 -0
  26. data/pg_engine/app/helpers/pg_engine/index_helper.rb +42 -0
  27. data/{app/helpers/pg_rails → pg_engine/app/helpers/pg_engine}/postgres_helper.rb +1 -1
  28. data/{app/helpers/pg_rails → pg_engine/app/helpers/pg_engine}/print_helper.rb +15 -31
  29. data/pg_engine/app/helpers/pg_engine/route_helper.rb +41 -0
  30. data/pg_engine/app/inputs/pg_engine/fecha_input.rb +20 -0
  31. data/{app/lib/pg_rails → pg_engine/app/lib/pg_engine}/filtros_builder.rb +16 -17
  32. data/pg_engine/app/lib/pg_form_builder.rb +22 -0
  33. data/pg_engine/app/models/pg_engine/base_record.rb +63 -0
  34. data/{app/policies/pg_rails → pg_engine/app/policies/pg_engine}/application_policy.rb +2 -2
  35. data/pg_engine/app/views/pg_engine/base/download.xlsx.axlsx +14 -0
  36. data/pg_engine/app/views/pg_engine/base/index.html.slim +51 -0
  37. data/pg_engine/config/locales/es.yml +48 -0
  38. data/pg_engine/config/simple_form/simple_form.rb +178 -0
  39. data/pg_engine/config/simple_form/simple_form_bootstrap.rb +371 -0
  40. data/{lib/pg_rails → pg_engine/lib/pg_engine}/configuracion.rb +3 -1
  41. data/pg_engine/lib/pg_engine/engine.rb +53 -0
  42. data/{lib/pg_rails → pg_engine/lib/pg_engine}/utils/logueador.rb +8 -1
  43. data/pg_engine/lib/pg_engine.rb +35 -0
  44. data/{lib → pg_engine/lib}/tasks/auto_anotar_modelos.rake +1 -1
  45. data/pg_engine/lib/templates/activeadmin/audits.rb +53 -0
  46. data/pg_engine/lib/templates/activeadmin/users.rb +54 -0
  47. data/pg_layout/app/assets/stylesheets/sidebar.scss +106 -0
  48. data/pg_layout/app/javascript/cookies.js +23 -0
  49. data/pg_layout/app/javascript/navbar_controller.js +10 -0
  50. data/pg_layout/app/lib/navbar.rb +61 -0
  51. data/pg_layout/app/views/devise/confirmations/new.html.erb +20 -0
  52. data/pg_layout/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  53. data/pg_layout/app/views/devise/mailer/email_changed.html.erb +7 -0
  54. data/pg_layout/app/views/devise/mailer/password_change.html.erb +3 -0
  55. data/pg_layout/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  56. data/pg_layout/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  57. data/pg_layout/app/views/devise/passwords/edit.html.erb +27 -0
  58. data/pg_layout/app/views/devise/passwords/new.html.erb +18 -0
  59. data/pg_layout/app/views/devise/registrations/edit.html.erb +35 -0
  60. data/pg_layout/app/views/devise/registrations/new.html.erb +25 -0
  61. data/pg_layout/app/views/devise/sessions/new.html.erb +20 -0
  62. data/pg_layout/app/views/devise/shared/_error_messages.html.erb +15 -0
  63. data/pg_layout/app/views/devise/shared/_links.html.erb +25 -0
  64. data/pg_layout/app/views/devise/unlocks/new.html.erb +19 -0
  65. data/pg_layout/app/views/kaminari/_first_page.html.slim +3 -0
  66. data/pg_layout/app/views/kaminari/_gap.html.slim +2 -0
  67. data/pg_layout/app/views/kaminari/_last_page.html.slim +3 -0
  68. data/pg_layout/app/views/kaminari/_next_page.html.slim +3 -0
  69. data/pg_layout/app/views/kaminari/_page.html.slim +6 -0
  70. data/pg_layout/app/views/kaminari/_paginator.html.slim +12 -0
  71. data/pg_layout/app/views/kaminari/_prev_page.html.slim +3 -0
  72. data/pg_layout/app/views/layouts/pg_layout/devise.html.slim +24 -0
  73. data/pg_layout/app/views/layouts/pg_layout/layout.html.slim +30 -0
  74. data/pg_layout/app/views/pg_layout/_flash.html.slim +10 -0
  75. data/pg_layout/app/views/pg_layout/_navbar.html.erb +43 -0
  76. data/pg_layout/app/views/pg_layout/_sidebar.html.erb +42 -0
  77. data/pg_layout/index.js +35 -0
  78. data/pg_layout/lib/pg_layout/engine.rb +7 -0
  79. data/pg_layout/lib/pg_layout.rb +9 -0
  80. data/pg_rails/js/index.js +2 -0
  81. data/pg_rails/lib/pg_rails.rb +7 -0
  82. data/{lib/pg_rails → pg_rails/lib}/version.rb +1 -1
  83. data/pg_rails/scss/pg_rails.scss +3 -0
  84. data/pg_scaffold/lib/generators/pg_active_record/model/model_generator.rb +34 -0
  85. data/pg_scaffold/lib/generators/pg_active_record/model/templates/admin.rb +19 -0
  86. data/pg_scaffold/lib/generators/pg_active_record/model/templates/create_table_migration.rb.tt +46 -0
  87. data/pg_scaffold/lib/generators/pg_active_record/model/templates/migration.rb.tt +48 -0
  88. data/pg_scaffold/lib/generators/pg_active_record/model/templates/model.rb +47 -0
  89. data/pg_scaffold/lib/generators/pg_active_record/model/templates/module.rb +9 -0
  90. data/pg_scaffold/lib/generators/pg_decorator/USAGE +8 -0
  91. data/pg_scaffold/lib/generators/pg_decorator/pg_decorator_generator.rb +31 -0
  92. data/pg_scaffold/lib/generators/pg_decorator/templates/decorator.rb +22 -0
  93. data/pg_scaffold/lib/generators/pg_factory_bot/model/model_generator.rb +95 -0
  94. data/pg_scaffold/lib/generators/pg_factory_bot/model/templates/factories.erb +14 -0
  95. data/pg_scaffold/lib/generators/pg_pundit/USAGE +8 -0
  96. data/pg_scaffold/lib/generators/pg_pundit/pg_pundit_generator.rb +21 -0
  97. data/pg_scaffold/lib/generators/pg_pundit/templates/policy.rb +37 -0
  98. data/pg_scaffold/lib/generators/pg_rails/instalar/USAGE +8 -0
  99. data/pg_scaffold/lib/generators/pg_rails/instalar/instalar_generator.rb +17 -0
  100. data/pg_scaffold/lib/generators/pg_rails/instalar/templates/pg_rails.rb +10 -0
  101. data/pg_scaffold/lib/generators/pg_resource_route/pg_resource_route_generator.rb +27 -0
  102. data/pg_scaffold/lib/generators/pg_rspec/model/model_generator.rb +30 -0
  103. data/pg_scaffold/lib/generators/pg_rspec/model/templates/model_spec.rb +15 -0
  104. data/pg_scaffold/lib/generators/pg_rspec/scaffold/scaffold_generator.rb +43 -0
  105. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/api_controller_spec.rb +167 -0
  106. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +269 -0
  107. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/edit_spec.rb +34 -0
  108. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/index_spec.rb +28 -0
  109. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/new_spec.rb +34 -0
  110. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/routing_spec.rb +50 -0
  111. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/show_spec.rb +26 -0
  112. data/pg_scaffold/lib/generators/pg_scaffold/USAGE +8 -0
  113. data/pg_scaffold/lib/generators/pg_scaffold/pg_scaffold_generator.rb +87 -0
  114. data/pg_scaffold/lib/generators/pg_scaffold/templates/controller.rb +37 -0
  115. data/pg_scaffold/lib/generators/pg_slim/USAGE +8 -0
  116. data/pg_scaffold/lib/generators/pg_slim/pg_slim_generator.rb +31 -0
  117. data/pg_scaffold/lib/generators/pg_slim/templates/_form.html.slim +12 -0
  118. data/pg_scaffold/lib/generators/pg_slim/templates/download.xlsx.axlsx +14 -0
  119. data/pg_scaffold/lib/generators/pg_slim/templates/edit.html.slim +5 -0
  120. data/pg_scaffold/lib/generators/pg_slim/templates/index.html.slim +51 -0
  121. data/pg_scaffold/lib/generators/pg_slim/templates/new.html.slim +5 -0
  122. data/pg_scaffold/lib/generators/pg_slim/templates/partial.html.slim +1 -0
  123. data/pg_scaffold/lib/generators/pg_slim/templates/show.html.slim +38 -0
  124. data/pg_scaffold/lib/pg_scaffold/monkey_patches/mejoras_a_named_base.rb +37 -0
  125. data/pg_scaffold/lib/pg_scaffold/monkey_patches/mejoras_de_atributos.rb +116 -0
  126. data/pg_scaffold/lib/pg_scaffold/railtie.rb +16 -0
  127. data/pg_scaffold/lib/pg_scaffold.rb +4 -0
  128. metadata +134 -48
  129. data/Rakefile +0 -36
  130. data/app/assets/javascripts/pg_rails/asociacion_creable.js +0 -85
  131. data/app/assets/javascripts/pg_rails/best_in_place_datepicker.js +0 -58
  132. data/app/assets/javascripts/pg_rails/librerias.js +0 -13
  133. data/app/assets/javascripts/pg_rails/librerias_b3.js +0 -14
  134. data/app/assets/javascripts/pg_rails/validaciones.js +0 -44
  135. data/app/assets/javascripts/pg_rails.js +0 -318
  136. data/app/assets/stylesheets/pg_rails/librerias.scss +0 -5
  137. data/app/assets/stylesheets/pg_rails/pg_chosen.scss +0 -29
  138. data/app/assets/stylesheets/pg_rails/pg_rails.scss +0 -199
  139. data/app/assets/stylesheets/pg_rails_b3.scss +0 -10
  140. data/app/assets/stylesheets/pg_rails_b4.scss +0 -12
  141. data/app/assets/stylesheets/pg_rails_b5.scss +0 -1
  142. data/app/controllers/pg_rails/application_controller.rb +0 -316
  143. data/app/controllers/pg_rails/editar_en_lugar_controller.rb +0 -24
  144. data/app/helpers/pg_rails/editar_en_lugar_helper.rb +0 -106
  145. data/app/helpers/pg_rails/form_helper.rb +0 -25
  146. data/app/inputs/pg_rails/asociacion_creable_input.rb +0 -72
  147. data/app/inputs/pg_rails/fecha_input.rb +0 -20
  148. data/app/inputs/pg_rails/selects_dependientes_input.rb +0 -9
  149. data/app/lib/pg_form_builder.rb +0 -31
  150. data/app/models/pg_rails/application_record.rb +0 -51
  151. data/app/views/application/_abrir_modal.js.erb +0 -14
  152. data/app/views/application/_actualizar_smart_listing.html.slim +0 -3
  153. data/app/views/application/_cerrar_modal.js.erb +0 -8
  154. data/app/views/application/_modal_ajax_form.js.erb +0 -7
  155. data/config/brakeman.ignore +0 -42
  156. data/config/locales/es.yml +0 -17
  157. data/config/routes.rb +0 -3
  158. data/config/spring.rb +0 -1
  159. data/lib/pg_rails/engine.rb +0 -42
  160. data/lib/pg_rails/simple_form/initializer.rb +0 -583
  161. data/lib/pg_rails.rb +0 -23
  162. /data/{lib/pg_rails → pg_engine/lib/pg_engine}/core_ext.rb +0 -0
@@ -0,0 +1,10 @@
1
+ / Flash messages que se muestran en el HTML
2
+ / slim-lint:disable LineLength
3
+ - flash_to_show = flash.select { |flash_message| flash_message[0].to_sym.in? ApplicationController._flash_types }
4
+ / slim-lint:enable LineLength
5
+
6
+ - flash_to_show.each do |flash_type, message|
7
+ .toast(class="bg-#{flash_type_to_class(flash_type)}-subtle" role="alert"
8
+ aria-live="assertive" aria-atomic="true")
9
+ .toast-body
10
+ = message
@@ -0,0 +1,43 @@
1
+ <nav class="navbar navbar-expand-<%= @breakpoint_navbar_expand %> bg-light">
2
+ <div class="container-fluid">
3
+ <button data-controller="navbar" data-action="navbar#expandNavbar" class="btn btn-outline-primary me-2 d-none d-<%= @breakpoint_navbar_expand %>-inline-block">
4
+ <i class="bi bi-list"></i>
5
+ </button>
6
+ <!-- <a class="navbar-brand" href="#">Navbar</a> -->
7
+ <button class="navbar-toggler btn btn-outline-primary me-2" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
8
+ <i class="bi bi-list"></i>
9
+ <!-- <span class="navbar-toggler-icon"></span> -->
10
+ </button>
11
+ <div class="collapse navbar-collapse" id="navbarSupportedContent">
12
+ <ul class="navbar-nav me-auto mb-2 mb-lg-0">
13
+ <% if user_signed_in? %>
14
+ <li class="nav-item dropdown">
15
+ <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
16
+ <%= current_user.email %>
17
+ </a>
18
+ <ul class="dropdown-menu">
19
+ <li>
20
+ <%= link_to "Mi perfil", edit_user_registration_path, class: 'dropdown-item' %>
21
+ </li>
22
+ <li>
23
+ <%= link_to "Cerrar sesión", destroy_user_session_path, data: { 'turbo-method': 'delete' }, class: 'dropdown-item' %>
24
+ </li>
25
+ </ul>
26
+ </li>
27
+ <% else %>
28
+ <li class="nav-item">
29
+ <%= link_to 'ingresar', new_user_session_path, class: 'nav-link' %>
30
+ </li>
31
+ <% end %>
32
+ </ul>
33
+ </div>
34
+ </div>
35
+ </nav>
36
+ <!-- <nav>
37
+ <ul>
38
+ <li>
39
+
40
+ </li>
41
+ </ul>
42
+ </nav>
43
+ -->
@@ -0,0 +1,42 @@
1
+ <div id="sidebar" class="<%= @navbar_opened_class %> flex-shrink-0 bg-gradient d-none d-<%= @breakpoint_navbar_expand %>-block">
2
+ <% if user_signed_in? %>
3
+ <div class="sidebar--large-items" style="position:fixed">
4
+ <hr>
5
+ <div class="sidebar--small-items">
6
+ <ul class="list-unstyled ps-0">
7
+ <li class="mb-1 text-center">
8
+ <a href="javascript:void(0)" class="nav-link" data-bs-toggle="tooltip" data-bs-title="Agenda">
9
+ <i class="bi bi-calendar"></i>
10
+ </a>
11
+ </li>
12
+ </ul>
13
+ </div>
14
+ <div class="sidebar--large-items">
15
+ <ul class="list-unstyled ps-0">
16
+ <% @navbar.sidebar.each do |entry| %>
17
+ <% next if @navbar.hide_entry?(entry) %>
18
+ <% random_id = rand(99999).to_s %>
19
+ <li class="mb-1">
20
+ <% if entry[:children].present? %>
21
+ <button class="btn btn-toggle d-inline-flex align-items-center rounded border-0 collapsed" data-bs-toggle="collapse" data-bs-target="#<%= 'collapse-' + random_id %>" aria-expanded="true">
22
+ <%= entry[:title] %>
23
+ </button>
24
+ <div class="collapse <%= @navbar.any_children_active?(entry, request) ? 'show' : '' %>" id="<%= 'collapse-' + random_id %>">
25
+ <ul class="btn-toggle-nav list-unstyled fw-normal pb-1 small">
26
+ <% entry[:children].each do |child| %>
27
+ <% next if @navbar.hide_entry?(child) %>
28
+ <li><a href="<%= child[:path] %>" class="<%= @navbar.active_entry?(child, request) ? 'active' : '' %> d-inline-flex text-decoration-none rounded"><%= child[:title] %></a></li>
29
+ <% end %>
30
+ </ul>
31
+ </div>
32
+ <% else %>
33
+ <a href="<%= entry[:path] %>" class="<%= @navbar.active_entry?(entry, request) ? 'active' : '' %> d-inline-flex text-decoration-none ms-4"><%= entry[:title] %></a>
34
+ <% end %>
35
+ </li>
36
+ <% end %>
37
+ </ul>
38
+ <hr>
39
+ </div>
40
+ </div>
41
+ <% end %>
42
+ </div>
@@ -0,0 +1,35 @@
1
+ // Controllers
2
+ import NavbarController from './app/javascript/navbar_controller'
3
+ window.Stimulus.register('navbar', NavbarController)
4
+
5
+ // Bootstrap's toasts
6
+ import * as bootstrap from 'bootstrap'
7
+ document.addEventListener('turbo:load', function () {
8
+ const toastElList = document.querySelectorAll('.toast:not(.hide):not(.show)')
9
+ Array.from(toastElList).map(toastEl => new bootstrap.Toast(toastEl).show())
10
+
11
+ // Select the node that will be observed for mutations
12
+ const targetNode = document.getElementById('flash')
13
+
14
+ // Options for the observer (which mutations to observe)
15
+ const config = { attributes: true, childList: true, subtree: true }
16
+
17
+ // Callback function to execute when mutations are observed
18
+ const callback = (mutationList, observer) => {
19
+ for (const mutation of mutationList) {
20
+ if (mutation.type === 'childList') {
21
+ console.log('A child node has been added or removed.')
22
+ const toastElList = document.querySelectorAll('.toast:not(.hide):not(.show)')
23
+ Array.from(toastElList).map(toastEl => new bootstrap.Toast(toastEl).show())
24
+ } else if (mutation.type === 'attributes') {
25
+ console.log(`The ${mutation.attributeName} attribute was modified.`)
26
+ }
27
+ }
28
+ }
29
+
30
+ // Create an observer instance linked to the callback function
31
+ const observer = new MutationObserver(callback)
32
+
33
+ // Start observing the target node for configured mutations
34
+ observer.observe(targetNode, config)
35
+ })
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgLayout
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace PgLayout
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ # Para que la viewpath de pg_layout tenga precedencia sobre las de kaminari y devise
2
+ require 'kaminari'
3
+ require 'devise'
4
+ require 'devise-i18n'
5
+
6
+ require_relative 'pg_layout/engine'
7
+
8
+ module PgLayout
9
+ end
@@ -0,0 +1,2 @@
1
+ import './../../pg_associable'
2
+ import './../../pg_layout'
@@ -0,0 +1,7 @@
1
+ require "#{__dir__}/../../pg_engine/lib/pg_engine"
2
+ require "#{__dir__}/../../pg_associable/lib/pg_associable"
3
+ require "#{__dir__}/../../pg_scaffold/lib/pg_scaffold"
4
+ require "#{__dir__}/../../pg_layout/lib/pg_layout"
5
+
6
+ module PgRails
7
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRails
4
- VERSION = '7.0.1'
4
+ VERSION = '7.0.2'
5
5
  end
@@ -0,0 +1,3 @@
1
+ @import './../../pg_engine/app/assets/stylesheets/pg_rails_b5';
2
+ @import './../../pg_associable/app/assets/css/pg_associable';
3
+ @import './../../pg_layout/app/assets/stylesheets/sidebar';
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/active_record/model/model_generator'
4
+
5
+ module PgActiveRecord
6
+ class ModelGenerator < ActiveRecord::Generators::ModelGenerator
7
+ source_paths << File.expand_path('templates', __dir__)
8
+
9
+ class_option :paranoia, type: :boolean, default: false, desc: 'Paranoid y deleted_at.'
10
+ class_option :discard, type: :boolean, default: false, desc: 'Discard y discarded_at.'
11
+ class_option :trackeo_de_usuarios, type: :boolean, default: true,
12
+ desc: 'Genera campos creado_por y actualizado_por.'
13
+ class_option :activeadmin, type: :boolean, default: false, desc: 'ActiveAdmin file'
14
+
15
+ def create_activeadmin_file
16
+ return unless options[:activeadmin]
17
+
18
+ template 'admin.rb',
19
+ File.join('app/admin', "#{table_name}.rb")
20
+ end
21
+
22
+ # :doc:
23
+ def namespace
24
+ nil
25
+ end
26
+
27
+ # :doc:
28
+ def class_path
29
+ []
30
+ end
31
+
32
+ def create_module_file; end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ ActiveAdmin.register <%= class_name %> do
2
+ permit_params <%= attributes.map { |a| ":#{a.name}" }.join(', ') %>
3
+
4
+ index do
5
+ selectable_column
6
+ id_column<% attributes.each do |at| %>
7
+ column :<%= at.name %><% end %>
8
+ actions
9
+ end
10
+ <% attributes.each do |at| %>
11
+ filter :<%= at.name %><% end %>
12
+
13
+ form do |f|
14
+ f.inputs do<% attributes.each do |at| %>
15
+ f.input :<%= at.name %><% end %>
16
+ end
17
+ f.actions
18
+ end
19
+ end
@@ -0,0 +1,46 @@
1
+ # generado con pg_rails
2
+
3
+ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
4
+ def change
5
+ create_table :<%= table_name %><%= primary_key_type %> do |t|
6
+ <% attributes.each do |attribute| -%>
7
+ <% if attribute.password_digest? -%>
8
+ t.string :password_digest<%= attribute.inject_options %>
9
+ <% elsif attribute.token? -%>
10
+ t.string :<%= attribute.name %><%= attribute.inject_options %>
11
+ <% else -%>
12
+ t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
13
+ <% end -%>
14
+ <% end -%>
15
+
16
+ <% if options[:trackeo_de_usuarios] %>
17
+ t.references :creado_por, index: true
18
+ t.references :actualizado_por, index: true
19
+
20
+ <% end -%>
21
+ <% if options[:paranoia] %>
22
+ t.datetime :deleted_at
23
+ <% end -%>
24
+ <% if options[:discard] %>
25
+ t.datetime :discarded_at
26
+ <% end -%>
27
+ <% if options[:timestamps] %>
28
+ t.timestamps
29
+ <% end -%>
30
+ end
31
+ <% attributes.select(&:token?).each do |attribute| -%>
32
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>, unique: true
33
+ <% end -%>
34
+ <% attributes_with_index.each do |attribute| -%>
35
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
36
+ <% end -%>
37
+ <% attributes.select(&:tiene_nombre_de_clase_explicito?).each do |attribute| -%>
38
+ add_foreign_key :<%= table_name %>, :<%= attribute.tabla_referenciada %>, column: '<%= attribute.name %>_id'
39
+ <% end -%>
40
+
41
+ <% if options[:trackeo_de_usuarios] %>
42
+ add_foreign_key :<%= table_name %>, :users, column: 'creado_por_id'
43
+ add_foreign_key :<%= table_name %>, :users, column: 'actualizado_por_id'
44
+ <% end -%>
45
+ end
46
+ end
@@ -0,0 +1,48 @@
1
+ # generado con pg_rails
2
+
3
+ class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
4
+ <%- if migration_action == 'add' -%>
5
+ def change
6
+ <% attributes.each do |attribute| -%>
7
+ <%- if attribute.reference? -%>
8
+ add_reference :<%= table_name %>, :<%= attribute.name %><%= attribute.inject_options %>
9
+ <%- elsif attribute.token? -%>
10
+ add_column :<%= table_name %>, :<%= attribute.name %>, :string<%= attribute.inject_options %>
11
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>, unique: true
12
+ <%- else -%>
13
+ add_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
14
+ <%- if attribute.has_index? -%>
15
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
16
+ <%- end -%>
17
+ <%- end -%>
18
+ <%- end -%>
19
+ end
20
+ <%- elsif migration_action == 'join' -%>
21
+ def change
22
+ create_join_table :<%= join_tables.first %>, :<%= join_tables.second %> do |t|
23
+ <%- attributes.each do |attribute| -%>
24
+ <%- if attribute.reference? -%>
25
+ t.references :<%= attribute.name %><%= attribute.inject_options %>
26
+ <%- else -%>
27
+ <%= '# ' unless attribute.has_index? -%>t.index <%= attribute.index_name %><%= attribute.inject_index_options %>
28
+ <%- end -%>
29
+ <%- end -%>
30
+ end
31
+ end
32
+ <%- else -%>
33
+ def change
34
+ <% attributes.each do |attribute| -%>
35
+ <%- if migration_action -%>
36
+ <%- if attribute.reference? -%>
37
+ remove_reference :<%= table_name %>, :<%= attribute.name %><%= attribute.inject_options %>
38
+ <%- else -%>
39
+ <%- if attribute.has_index? -%>
40
+ remove_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
41
+ <%- end -%>
42
+ remove_column :<%= table_name %>, :<%= attribute.name %>, :<%= attribute.type %><%= attribute.inject_options %>
43
+ <%- end -%>
44
+ <%- end -%>
45
+ <%- end -%>
46
+ end
47
+ <%- end -%>
48
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ <% if namespaced? -%>
6
+ require_dependency "<%= namespaced_path %>/application_record"
7
+
8
+ <% end -%>
9
+ <% module_namespacing do -%>
10
+ class <%= class_name %> < <%= parent_class_name.classify %>
11
+ audited
12
+ <%- if options[:paranoia] -%>
13
+ acts_as_paranoid without_default_scope: true
14
+ <%- end -%>
15
+ <%- if options[:discard] -%>
16
+ include Discard::Model
17
+ <%- end -%>
18
+ <%- if attributes.any?(&:reference?) -%>
19
+
20
+ <%- attributes.select(&:reference?).each do |attribute| -%>
21
+ belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %><%= ', optional: true' unless attribute.required? %><%= ", class_name: '#{attribute.clase_con_modulo}'" if attribute.tiene_nombre_de_clase_explicito? %>
22
+ <%- end -%>
23
+ <%- end -%>
24
+ <%- if options[:trackeo_de_usuarios] -%>
25
+
26
+ belongs_to :creado_por, optional: true, class_name: 'User'
27
+ belongs_to :actualizado_por, optional: true, class_name: 'User'
28
+ <%- end -%>
29
+ <%- if attributes.any?(&:es_enum?) -%>
30
+
31
+ <%- attributes.select(&:es_enum?).each do |attribute| -%>
32
+ enumerize :<%= attribute.name %>, in: { completar: 0, los: 1, valores: 2 }
33
+ <%- end -%>
34
+ <%- end -%>
35
+
36
+ <%- if attributes.any?(&:required?) -%>
37
+
38
+ validates <%= attributes.select(&:required?).map { |at| ":#{at.name}" }.join(', ') %>, presence: true
39
+ <%- end -%>
40
+ <%- attributes.select(&:token?).each do |attribute| -%>
41
+ has_secure_token<% if attribute.name != "token" %> :<%= attribute.name %><% end %>
42
+ <%- end -%>
43
+ <%- if attributes.any?(&:password_digest?) -%>
44
+ has_secure_password
45
+ <%- end -%>
46
+ end
47
+ <% end -%>
@@ -0,0 +1,9 @@
1
+ # generado con pg_rails
2
+
3
+ <% module_namespacing do -%>
4
+ module <%= class_path.map(&:camelize).join('::') %>
5
+ def self.table_name_prefix
6
+ '<%= namespaced? ? namespaced_class_path.join('_') : class_path.join('_') %>_'
7
+ end
8
+ end
9
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate pg_decorator Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'generators/rails/decorator_generator'
4
+
5
+ class PgDecoratorGenerator < Rails::Generators::DecoratorGenerator
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ remove_hook_for :test_framework
9
+
10
+ # :doc:
11
+ def namespace
12
+ nil
13
+ end
14
+
15
+ # :doc:
16
+ def class_path
17
+ []
18
+ end
19
+
20
+ def create_module_file; end
21
+
22
+ private
23
+
24
+ def class_path_original
25
+ @class_path.first
26
+ end
27
+
28
+ def parent_class_name
29
+ 'PgEngine::BaseDecorator'
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ <%- module_namespacing do -%>
6
+ <%- if parent_class_name.present? -%>
7
+ class <%= class_name %>Decorator < <%= parent_class_name %>
8
+ <%- else -%>
9
+ class <%= class_name %>
10
+ <%- end -%>
11
+ delegate_all
12
+
13
+ # Define presentation-specific methods here. Helpers are accessed through
14
+ # `helpers` (aka `h`). You can override attributes, for example:
15
+ #
16
+ # def created_at
17
+ # helpers.content_tag :span, class: 'time' do
18
+ # object.created_at.strftime("%a %m/%d/%y")
19
+ # end
20
+ # end
21
+ end
22
+ <% end -%>
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ # este generator tiene que llamarse ModelGenerator para que funcione el hook_to
4
+ # del ModelGenerator de rails
5
+
6
+ require 'generators/factory_bot/model/model_generator'
7
+
8
+ module PgFactoryBot
9
+ module Generators
10
+ class ModelGenerator < FactoryBot::Generators::ModelGenerator
11
+ # piso el método de FactoryBot::Generators::Base con el método original
12
+ # de Rails::Generators::Base
13
+
14
+ # rubocop:disable Naming/MemoizedInstanceVariableName
15
+ def self.source_root(path = nil)
16
+ @_source_root = path if path
17
+ @_source_root ||= default_source_root
18
+ end
19
+ # rubocop:enable Naming/MemoizedInstanceVariableName
20
+
21
+ source_root File.expand_path('templates', __dir__)
22
+
23
+ class_option(
24
+ :dir,
25
+ type: :string,
26
+ default: 'spec/factories',
27
+ desc: 'The directory or file root where factories belong'
28
+ )
29
+
30
+ # Los modelos nunca tienen modulo
31
+ def explicit_class_option; end
32
+
33
+ # :doc:
34
+ def namespace
35
+ nil
36
+ end
37
+
38
+ # :doc:
39
+ def class_path
40
+ []
41
+ end
42
+
43
+ def create_module_file; end
44
+
45
+ private
46
+
47
+ # {factory_attributes.gsub(/^/, ' ')}#{los_traits.gsub(/^/, ' ')}
48
+ def factory_definition
49
+ <<~RUBY
50
+ factory :#{singular_table_name}#{explicit_class_option} do
51
+ #{factory_attributes}#{los_traits}
52
+ end
53
+ RUBY
54
+ end
55
+
56
+ def los_traits
57
+ attributes.select(&:reference?).map do |atributo|
58
+ {
59
+ clase: atributo.clase_con_modulo,
60
+ atributo_name: atributo.name
61
+ }
62
+ end
63
+ end
64
+
65
+ # Genero los valores de las factories con los helpers de Faker
66
+
67
+ def factory_attributes
68
+ attributes.map do |attribute|
69
+ if attribute.reference?
70
+ # "association :#{attribute.name}, factory: :#{attribute.tabla_referenciada_singular}"
71
+ attribute.name
72
+ else
73
+ "#{attribute.name} { #{valor_atributo(attribute)} }"
74
+ end
75
+ end
76
+ end
77
+
78
+ def valor_atributo(attribute)
79
+ if attribute.es_enum?
80
+ "#{nombre_clase_completo}.#{attribute.name}.values.sample"
81
+ elsif attribute.type == :string
82
+ 'Faker::Lorem.sentence'
83
+ elsif attribute.type == :date
84
+ 'Faker::Date.backward'
85
+ elsif attribute.type == :float || attribute.type == :decimal
86
+ 'Faker::Number.decimal(l_digits: 3, r_digits: 2)'
87
+ elsif attribute.type == :integer
88
+ 'rand(1..9999)'
89
+ else
90
+ attribute.default.inspect
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ FactoryBot.define do
6
+ factory :<%= singular_table_name %> do<% factory_attributes.each do |a| %>
7
+ <%= a %><% end %><% los_traits.each do |trait| %>
8
+
9
+ trait :<%= trait[:atributo_name] %>_existente do
10
+ <%= trait[:atributo_name] %> { nil }
11
+ <%= trait[:atributo_name] %>_id { <%= trait[:clase] %>.pluck(:id).sample }
12
+ end<% end %>
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate pg_pundit Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'generators/pundit/policy/policy_generator'
4
+
5
+ class PgPunditGenerator < Pundit::Generators::PolicyGenerator
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ remove_hook_for :test_framework
9
+
10
+ # :doc:
11
+ def namespace
12
+ nil
13
+ end
14
+
15
+ # :doc:
16
+ def class_path
17
+ []
18
+ end
19
+
20
+ def create_module_file; end
21
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ <% if namespaced? -%>
6
+ require_dependency "<%= namespaced_path %>/application_policy"
7
+
8
+ <% end -%>
9
+ <% module_namespacing do -%>
10
+ class <%= class_name %>Policy < ApplicationPolicy
11
+ class Scope < ApplicationPolicy::Scope
12
+ # def resolve
13
+ # if policy.acceso_total?
14
+ # scope.all
15
+ # else
16
+ # scope.none
17
+ # end
18
+ # end
19
+ end
20
+
21
+ # def puede_editar?
22
+ # acceso_total? && !record.readonly?
23
+ # end
24
+
25
+ # def puede_crear?
26
+ # acceso_total? || user.asesor?
27
+ # end
28
+
29
+ # def puede_borrar?
30
+ # acceso_total? && !record.readonly?
31
+ # end
32
+
33
+ # def acceso_total?
34
+ # user.admin?
35
+ # end
36
+ end
37
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate instalar Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgRails
4
+ class InstalarGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('templates', __dir__)
6
+
7
+ def copy_application_policy
8
+ template 'pg_rails.rb', 'config/initializers/pg_rails.rb'
9
+ end
10
+
11
+ private
12
+
13
+ def clase_aplicacion
14
+ 'cosa'
15
+ end
16
+ end
17
+ end