rails_app_generator 0.2.40 → 0.2.43

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 (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/after_templates/addons/scenic/_.rb +64 -0
  4. data/after_templates/addons/scenic/app/controllers/home_controller.rb +24 -0
  5. data/after_templates/addons/scenic/app/services/seed_service.rb +104 -0
  6. data/after_templates/addons/scenic/app/views/home/index.html.erb +3 -0
  7. data/after_templates/addons/scenic/app/views/home/individual_visitors_by_monument.html.erb +24 -0
  8. data/after_templates/addons/scenic/app/views/home/reseed.html.erb +3 -0
  9. data/after_templates/addons/scenic/app/views/home/visitors_by_monument.html.erb +22 -0
  10. data/after_templates/addons/scenic/app/views/layouts/_footer.html.erb +0 -0
  11. data/after_templates/addons/scenic/app/views/layouts/_navbar.html.erb +10 -0
  12. data/after_templates/addons/scenic/app/views/layouts/application.html.erb +29 -0
  13. data/after_templates/addons/scenic/db/seeds.rb +1 -0
  14. data/after_templates/addons/scenic/db/views/individual_visitors_by_monuments_v01.sql +9 -0
  15. data/after_templates/addons/scenic/db/views/visitors_by_monuments_v01.sql +8 -0
  16. data/after_templates/application/klueless/_.rb +99 -0
  17. data/after_templates/application/klueless/app/avo/dashboards/dashboard.rb +13 -0
  18. data/after_templates/application/klueless/app/avo/resources/db_schema_resource.rb +12 -0
  19. data/after_templates/application/klueless/app/avo/resources/rails_app_resource.rb +15 -0
  20. data/after_templates/application/klueless/app/avo/resources/rubocop_resource.rb +12 -0
  21. data/after_templates/application/klueless/app/avo/resources/table_count_resource.rb +12 -0
  22. data/after_templates/application/klueless/app/avo/resources/user_resource.rb +24 -0
  23. data/after_templates/application/klueless/app/controllers/home_controller.rb +12 -0
  24. data/after_templates/application/klueless/app/models/db_schema.rb +11 -0
  25. data/after_templates/application/klueless/app/models/rails_app.rb +3 -0
  26. data/after_templates/application/klueless/app/models/rubocop.rb +11 -0
  27. data/after_templates/application/klueless/app/models/table_count.rb +11 -0
  28. data/after_templates/application/klueless/app/queries/rubocop_log.psql +23 -0
  29. data/after_templates/application/klueless/app/queries/rubocop_log_query.rb +10 -0
  30. data/after_templates/application/klueless/app/queries/sql_query.rb +40 -0
  31. data/after_templates/application/klueless/app/services/seed_service.rb +7 -0
  32. data/after_templates/application/klueless/app/views/home/index.html.erb +6 -0
  33. data/after_templates/application/klueless/app/views/home/quick_signin.html.erb +3 -0
  34. data/after_templates/application/klueless/app/views/layouts/_footer.html.erb +0 -0
  35. data/after_templates/application/klueless/app/views/layouts/_navbar.html.erb +4 -0
  36. data/after_templates/application/klueless/app/views/layouts/application.html.erb +29 -0
  37. data/after_templates/application/klueless/config/initializers/avo.rb +101 -0
  38. data/after_templates/application/klueless/config/locales/en.yml +4 -0
  39. data/after_templates/application/klueless/db/seeds.rb +18 -0
  40. data/after_templates/application/printspeak/_.rb +65 -23
  41. data/after_templates/application/printspeak/db/seeds.rb +3 -3
  42. data/docs/last_run/app_generator_class.json +8 -0
  43. data/docs/last_run/app_generator_data.json +5 -4
  44. data/docs/last_run/rails_options_class.json +8 -0
  45. data/docs/last_run/rails_options_data.json +5 -4
  46. data/lib/rails_app_generator/addons/avo.rb +2 -0
  47. data/lib/rails_app_generator/addons/scenic.rb +15 -0
  48. data/lib/rails_app_generator/app_generator.rb +10 -0
  49. data/lib/rails_app_generator/gem_query.rb +3 -1
  50. data/lib/rails_app_generator/rag_initializer.rb +2 -1
  51. data/lib/rails_app_generator/version.rb +1 -1
  52. data/package-lock.json +2 -2
  53. data/package.json +1 -1
  54. data/profiles/addons/scenic.json +14 -0
  55. data/profiles/application/klueless.json +23 -0
  56. data/profiles/application/printspeak.json +7 -1
  57. data/tasks/profile.thor +1 -0
  58. data/templates/Gemfile.erb +0 -1
  59. data/templates/thor_task/profile/after_template.rb +19 -30
  60. data/templates/thor_task/profile/app/controllers/home_controller.rb +4 -0
  61. data/templates/thor_task/profile/app/services/seed_service.rb +27 -0
  62. data/templates/thor_task/profile/db/seeds.rb +1 -0
  63. metadata +43 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 635081352fed9b65ca6d9905c209e40edc4d74ea8eb1fcc5ae1f53b58c080fe6
4
- data.tar.gz: 0a0e858ef8a51a3c6ae1dca71ffb112e6e61cfb8802c6a3f4f2139d77195334d
3
+ metadata.gz: 9d9ac313ea8fc5383a7d3d37ed9495fff8509f9b7dd1ff373ed97c80ce69ae23
4
+ data.tar.gz: bb65bdcc19d95bfb69abf92458dbe0eec353a8b3085ba8e679d72955ab55f425
5
5
  SHA512:
6
- metadata.gz: b75d081dad75b16ff179fd916c3b25f0f1c2a1fbcd1def2749a7b5cceb2f6af77f950c07abd14fad51a7db3a2d4f12ae3b9c3a8d9ca87f018991c34f3e7889b6
7
- data.tar.gz: 537cac1df29fefd9294470bc47fcbe4510004189f637b7e0da70a815dc2b48a78f9ffb373be70d3b23c4cc0a85c0f8e1f2876f1a6fded9bb44e53de7a236fb3d
6
+ metadata.gz: 6f0ccd26ef5090325cbb6a76408fd201bbce81d8bbd739618e14393eebe0cc6814bb9e24eecdfec7dd7fd07664fe9e52ed1e47d92343461b45ab3378d37e22f7
7
+ data.tar.gz: 70dee6a466c8976ba4f385d532b34325d188a83599df9d4fcd4330b6805f9f0dcc580141fc4ad5e9d1b9a393c4b2084698f7a2771254b7839a18a4f98471765c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## [0.2.42](https://github.com/klueless-io/rails_app_generator/compare/v0.2.41...v0.2.42) (2022-08-30)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add scenic addon ([93a9561](https://github.com/klueless-io/rails_app_generator/commit/93a9561131658399b91075e15c6d9680f1b73ece))
7
+ * cops ([fe3e6b7](https://github.com/klueless-io/rails_app_generator/commit/fe3e6b7031a57b0f212fd91491ebc7f32928b9c1))
8
+
9
+ ## [0.2.41](https://github.com/klueless-io/rails_app_generator/compare/v0.2.40...v0.2.41) (2022-08-30)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * update klueless profile ([e426b82](https://github.com/klueless-io/rails_app_generator/commit/e426b820b15e8e49d2cc6c6ec2ccfd4ed8ea1158))
15
+
16
+ ## [0.2.40](https://github.com/klueless-io/rails_app_generator/compare/v0.2.39...v0.2.40) (2022-08-23)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * add factory_bot_rails profile ([8a6a7ef](https://github.com/klueless-io/rails_app_generator/commit/8a6a7ef6c4b1b26003930776724cedaeb5232f84))
22
+
1
23
  ## [0.2.39](https://github.com/klueless-io/rails_app_generator/compare/v0.2.38...v0.2.39) (2022-08-23)
2
24
 
3
25
 
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ads methods to ActiveRecord:Migration to create and manage database views in Rails
4
+ #
5
+ # exe/rag addons/scenic
6
+
7
+ self.local_template_path = File.dirname(__FILE__)
8
+
9
+ gac 'base rails 7 image created'
10
+
11
+ prepare_environment
12
+
13
+ after_bundle do
14
+ force_copy
15
+
16
+ create_db
17
+ scaffolds
18
+ setup_customizations
19
+ migrate_db
20
+ end
21
+
22
+ def scaffolds
23
+ add_scaffold('country', 'code', 'name')
24
+ add_scaffold('monument', 'name', 'description', 'country:references')
25
+ add_scaffold('visitor', 'name', 'monument:references')
26
+
27
+ generate('scenic:model visitors_by_monument')
28
+ generate('scenic:model individual_visitors_by_monument --materialized')
29
+
30
+ directory "db/views"
31
+ end
32
+
33
+ def setup_customizations
34
+ route("root 'home#index'")
35
+
36
+ add_controller('home', 'index', 'visitors_by_monument', 'individual_visitors_by_monument', 'reseed', 'refresh_material_view')
37
+
38
+ directory "app/controllers"
39
+ directory "app/models"
40
+ directory "app/views"
41
+ template 'app/views/layouts/application.html.erb' , 'app/views/layouts/application.html.erb'
42
+ directory "app/services"
43
+ end
44
+
45
+ def create_db
46
+ gsub_file('config/database.yml', ' encoding: unicode', db_development_settings)
47
+ rails_command('db:environment:set RAILS_ENV=development')
48
+ db(drop: true, create: true)
49
+ end
50
+
51
+ def migrate_db
52
+ template 'db/seeds.rb' , 'db/seeds.rb'
53
+
54
+ db(migrate: true, seed: true)
55
+ end
56
+
57
+ def db_development_settings
58
+ <<-'RUBY'
59
+ encoding: unicode
60
+ host: <%= ENV['DATABASE_HOST'] %>
61
+ username: <%= ENV['DATABASE_USERNAME'] %>
62
+ password: <%= ENV['DATABASE_PASSWORD'] %>
63
+ RUBY
64
+ end
@@ -0,0 +1,24 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+
5
+ def visitors_by_monument
6
+ @visitors = VisitorsByMonument.all.order(:visits)
7
+ end
8
+
9
+ def individual_visitors_by_monument
10
+ @visitors = IndividualVisitorsByMonument.all.order(:visits)
11
+ end
12
+
13
+ def reseed
14
+ SeedService.seed(variant: :refresh)
15
+
16
+ redirect_back_or_to root_path
17
+ end
18
+
19
+ def refresh_material_view
20
+ IndividualVisitorsByMonument.refresh
21
+
22
+ redirect_back_or_to root_path
23
+ end
24
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SeedService
4
+ class << self
5
+ def seed(variant: :reset)
6
+ service = SeedService.new
7
+ service.call(variant: variant)
8
+ end
9
+ end
10
+
11
+ NAMES = %w[
12
+ Adyson Aimee Aisha Akira Alani Albert Aleah Aleena Alena Alexus Alfred Ali Alia
13
+ Amelie Amina Amirah Amiya Anabella Anabelle Andrew Angeline Angelique Ann Annabel Aliana
14
+ Armani Arthur Aryana Ashanti Ashleigh Ashly Aspen Averie Avery Ayana Barbara
15
+ Brynlee Cailyn Cal Camilla Campbell Carina Carissa Carlee Carley Carlie Carolyn Cassie
16
+ Charlie Charlize Chaya Cherish Cierra Clair Clare Clarence Cloe Corinne Cristal
17
+ Destiney Dominique Dorsey Early Edith Edward Eileen Elaine Elisa Ellen Elmer Elsa Elsie
18
+ Fay Felicity Finley Frances Frank Fred Frederick Frida Gemma George Gia Giada Giana Gillian
19
+ Hana Harris Harry Haven Henderson Henry Herbert Hezekiah Hillary Iliana India
20
+ James Jamya Janae Janet Janiah Jaslyn Jaycee Jaylah Jaylee Jaylen Jaylene Jaylyn
21
+ John Johnie Joseph Joslyn Joyce Judith Julianne June Kaia Kaila Kailee Kaiya Kaley
22
+ Karma Kasey Katrina Kaya Kaylen Kayley Kaylyn Keely Kelsie Kendal Kenna Keyla Kierra
23
+ Leanna Lewis Leyla Libby Lilianna Lillianna Lilyana Lina Litzy Lizeth Lonzo Lorelai
24
+ Maeve Magdalena Maia Makena Maleah Maliyah Mara Mareli Mariam Marianna Mariela Marisa
25
+ Miah Micah Milagros Mina Mira Mollie Monique Monserrat Mont Moriah Mylie Natalya
26
+ Paloma Pamela Patience Paula Peter Phoenix Precious Raelynn Raina Raven Rayna Rayne Regan
27
+ Rollin Roselyn Rosemary Roy Ryann Saige Salma Sam Samuel Sanaa Sanai Sarahi Sariah Savanah
28
+ Shyann Shyanne Shyla Siena Sonia Stacy Stephany Susan Taliyah Tamara Taniya Taniyah
29
+ Tianna Tom Valery Walter Will William Willie Wilmer Xiomara Yadira Yamilet Yaritza Yasmine Yazmin
30
+ Yoselin Yuliana Zaniyah Zara Zaria Zion
31
+ %
32
+ ].freeze
33
+
34
+ attr_reader :au, :us, :gb, :monuments
35
+
36
+ def call(variant: :reset)
37
+ reset if variant == :reset
38
+ refresh if variant == :refresh
39
+ create
40
+ end
41
+
42
+ private
43
+
44
+ def reset
45
+ Visitor.delete_all
46
+ Monument.delete_all
47
+ Country.delete_all
48
+ end
49
+
50
+ def refresh
51
+ Visitor.delete_all
52
+ end
53
+
54
+ def create
55
+ upsert_countries
56
+ upsert_monuments
57
+ create_visitors
58
+ end
59
+
60
+ def upsert_countries
61
+ @au = Country.create_with(name: 'Australia').find_or_create_by(code: 'AU')
62
+ @us = Country.create_with(name: 'United States').find_or_create_by(code: 'US')
63
+ @gb = Country.create_with(name: 'United Kingdom').find_or_create_by(code: 'GB')
64
+ end
65
+
66
+ def upsert_monuments
67
+ @monuments = [
68
+ Monument.create_with(country: au,
69
+ description: 'The Sydney Opera House is a multi-venue performing arts centre in Sydney, New South Wales, Australia. It is the largest performing arts centre in Australia and the second largest in the world.')
70
+ .find_or_create_by(name: 'Sydney Opera House'),
71
+ Monument.create_with(country: au,
72
+ description: 'The Sydney Harbour Bridge is a viaduct bridge in Sydney, New South Wales, Australia. It is the longest viaduct bridge in Australia and the second longest in the world.')
73
+ .find_or_create_by(name: 'Sydney Harbour Bridge'),
74
+ Monument.create_with(country: au,
75
+ description: 'The Big Banana is a large, round, fruit-bearing tree in the Australian bushland of the Great Barrier Reef. It is the largest tree in the world.')
76
+ .find_or_create_by(name: 'The Big Banana'),
77
+ Monument.create_with(country: us,
78
+ description: 'The Statue of Liberty is a colossal neoclassical sculpture on Liberty Island in New York Harbor, New York, in the United States. The statue was a gift from the people of France to the people of the United States in 1886.')
79
+ .find_or_create_by(name: 'Statue of Liberty'),
80
+ Monument.create_with(country: us,
81
+ description: 'The Golden Gate Bridge is a suspension bridge spanning the Golden Gate, the one-mile-wide strait connecting San Francisco Bay and the Pacific Ocean. The bridge was completed in 1937.')
82
+ .find_or_create_by(name: 'Golden Gate Bridge'),
83
+ Monument.create_with(country: us,
84
+ description: 'The Empire State Building is a 102-story skyscraper in Midtown Manhattan, New York City. It is the world\'s tallest building, a structure that is the 4th-tallest building in the world.')
85
+ .find_or_create_by(name: 'Empire State Building'),
86
+ Monument.create_with(country: gb,
87
+ description: 'The Tower of London is a historic London tower on the north bank of the River Thames in central London. It is the most-visited paid monument in the world.')
88
+ .find_or_create_by(name: 'Tower of London'),
89
+ Monument.create_with(country: gb, description: 'The Big Ben is a clock tower in the north of London. It is the world\'s tallest clock tower.')
90
+ .find_or_create_by(name: 'Big Ben'),
91
+ Monument.create_with(country: gb,
92
+ description: 'The London Eye is a giant Ferris wheel situated on the South Bank of the River Thames in London, England. It is the world\'s largest Ferris wheel.')
93
+ .find_or_create_by(name: 'London Eye')
94
+ ]
95
+ end
96
+
97
+ def create_visitors
98
+ NAMES.each do |name|
99
+ rand(1..10).times do # number monuments to visited (duplicates are fine)
100
+ Visitor.create(name: name, monument: monuments.sample)
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,3 @@
1
+ <h1>Scenic</h1>
2
+
3
+ <p>Ads methods to ActiveRecord:Migration to create and manage database views in Rails</p>
@@ -0,0 +1,24 @@
1
+ <h1>Individual Visitors by Monument</h1>
2
+
3
+ <pre><code><%= File.read('db/views/individual_visitors_by_monuments_v01.sql') %></code></pre>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th>Person</th>
9
+ <th>Monument</th>
10
+ <th>Country</th>
11
+ <th>Visits</th>
12
+ </tr>
13
+ </thead>
14
+ <tbody>
15
+ <% @visitors.each do |visitor| %>
16
+ <tr>
17
+ <td><%= visitor.person %></td>
18
+ <td><%= visitor.monument %></td>
19
+ <td><%= visitor.country %></td>
20
+ <td><%= visitor.visits %></td>
21
+ </tr>
22
+ <% end %>
23
+ </tbody>
24
+ </table>
@@ -0,0 +1,3 @@
1
+ <h1>Re-Seed</h1>
2
+
3
+ <p>Database has been re-seeded</p>
@@ -0,0 +1,22 @@
1
+ <h1>Visitors by Monument</h1>
2
+
3
+ <pre><code><%= File.read('db/views/visitors_by_monuments_v01.sql') %></code></pre>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th>Monument</th>
9
+ <th>Country</th>
10
+ <th>Visits</th>
11
+ </tr>
12
+ </thead>
13
+ <tbody>
14
+ <% @visitors.each do |visitor| %>
15
+ <tr>
16
+ <td><%= visitor.monument %></td>
17
+ <td><%= visitor.country %></td>
18
+ <td><%= visitor.visits %></td>
19
+ </tr>
20
+ <% end %>
21
+ </tbody>
22
+ </table>
@@ -0,0 +1,10 @@
1
+ <%= link_to 'Home', root_path %>
2
+ | <%= link_to 'Countries', countries_path %>
3
+ | <%= link_to 'Monuments', monuments_path %>
4
+ | <%= link_to 'Visitors', visitors_path %>
5
+ <br>
6
+ <%= link_to 'Visits (View)', home_visitors_by_monument_path %>
7
+ | <%= link_to 'Visits (Materialized)', home_individual_visitors_by_monument_path %>
8
+ | <%= link_to 'Re-Seed', home_reseed_path, style: 'color: blue; font-weight: 600;' %>
9
+ | <%= link_to 'Refresh Material View', home_refresh_material_view_path, style: 'color: blue; font-weight: 600;' %>
10
+ <hr />
@@ -0,0 +1,29 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= camelized %></title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <%%= csrf_meta_tags %>
7
+ <%%= csp_meta_tag %>
8
+
9
+ <%- if options[:skip_hotwire] || options[:skip_javascript] -%>
10
+ <%%= stylesheet_link_tag "application" %>
11
+ <%- else -%>
12
+ <%%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
13
+ <%- end -%>
14
+ </head>
15
+
16
+ <body>
17
+ <header>
18
+ <%%= render 'layouts/navbar' %>
19
+ <hr />
20
+ </header>
21
+ <main>
22
+ <%%= yield %>
23
+ </main>
24
+ <footer>
25
+ <%%= render 'layouts/footer' %>
26
+ </footer>
27
+ </body>
28
+ </html>
29
+
@@ -0,0 +1 @@
1
+ SeedService.seed
@@ -0,0 +1,9 @@
1
+ select
2
+ visitors.name as person,
3
+ monuments.name as monument,
4
+ countries.name as country,
5
+ count(*) as visits
6
+ from visitors
7
+ join monuments on visitors.monument_id = monuments.id
8
+ join countries on monuments.country_id = countries.id
9
+ group by person, monument, country
@@ -0,0 +1,8 @@
1
+ select
2
+ monuments.name as monument,
3
+ countries.name as country,
4
+ count(*) as visits
5
+ from visitors
6
+ join monuments on visitors.monument_id = monuments.id
7
+ join countries on monuments.country_id = countries.id
8
+ group by monument, country
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ # No Code as a Service Rails Application Builder
4
+ #
5
+ # exe/rag application/klueless
6
+
7
+ self.local_template_path = File.dirname(__FILE__)
8
+
9
+ gac 'base rails 7 image created'
10
+
11
+ prepare_environment
12
+
13
+ after_bundle do
14
+ force_copy
15
+ create_db
16
+ scaffolds
17
+ setup_customizations
18
+ migrate_db
19
+ setup_avo
20
+
21
+ swap1 = ' resources :users'
22
+ swap2 = " devise_for :users, controllers: { sessions: 'users/sessions', registrations: 'users/registrations' }"
23
+
24
+ swap_lines('config/routes.rb', swap1, swap2)
25
+ end
26
+
27
+ def scaffolds
28
+ add_scaffold_controller('users', 'name', 'email')
29
+
30
+ add_scaffold('rails_app', 'name', 'user:references') # name of the rails_app
31
+
32
+ # no of records in each table per region
33
+ add_scaffold('table_count', 'data:jsonb', 'rails_app:references')
34
+ # add_scaffold('table_count_table', 'name', 'region', 'count:integer', 'table_count:references')
35
+
36
+ # rubocop logs
37
+ add_scaffold('rubocop', 'data:jsonb', 'rails_app:references') # import_date is known as created_at
38
+
39
+ # database schema
40
+ add_scaffold('db_schema', 'data:jsonb', 'rails_app:references')
41
+ # add_scaffold('db_schema_table', 'name', 'primary_key', 'primary_key_type', 'db_schema:references')
42
+
43
+ # add_scaffold('db_schema_column', 'name', 'type', 'precision:integer', 'scale:integer', 'default', 'array:boolean', 'null:boolean', 'limit:integer', 'db_schema_table:references')
44
+ # add_scaffold('db_schema_foreign_key', 'left', 'right', 'name', 'on_update', 'on_delete', 'column', 'db_schema_table:references')
45
+ # add_scaffold('db_schema_index', 'name', 'fields', 'using', 'order:jsonb', 'where', 'unique', 'db_schema_table:references')
46
+ # add_scaffold('db_schema_view', 'name', 'materialized:boolean', 'sql_definition', 'db_schema_table:references')
47
+ end
48
+
49
+ def setup_customizations
50
+ route("root 'home#index'")
51
+
52
+ force_copy
53
+
54
+ add_controller('home', 'index', 'quick_signin', 'reseed')
55
+
56
+ directory "app/controllers"
57
+ directory "app/models"
58
+ directory "app/views"
59
+ template 'app/views/layouts/application.html.erb', 'app/views/layouts/application.html.erb'
60
+ directory "app/queries"
61
+ end
62
+
63
+ def setup_avo
64
+ # generate('avo:install')
65
+
66
+ generate('avo:resource RailsApp')
67
+ generate('avo:resource TableCount')
68
+ generate('avo:resource Rubocop')
69
+ generate('avo:resource DbSchema')
70
+ generate('avo:resource User')
71
+ # generate('avo:dashboard Dashboard')
72
+
73
+ directory "app/avo"
74
+ directory "config/initializers"
75
+ directory "config/locales"
76
+
77
+ # # add devise support
78
+ # gsub_file 'config/initializers/avo.rb', %(# config.current_user_method = {}), 'config.current_user_method = :current_user'
79
+ end
80
+
81
+ def create_db
82
+ gsub_file('config/database.yml', ' encoding: unicode', db_development_settings)
83
+ db(drop: true, create: true)
84
+ end
85
+
86
+ def migrate_db
87
+ template 'db/seeds.rb' , 'db/seeds.rb'
88
+
89
+ db(migrate: true, seed: true)
90
+ end
91
+
92
+ def db_development_settings
93
+ <<-'RUBY'
94
+ encoding: unicode
95
+ host: <%= ENV['DATABASE_HOST'] %>
96
+ username: <%= ENV['DATABASE_USERNAME'] %>
97
+ password: <%= ENV['DATABASE_PASSWORD'] %>
98
+ RUBY
99
+ end
@@ -0,0 +1,13 @@
1
+ class Dashboard < Avo::Dashboards::BaseDashboard
2
+ self.id = "dashboard"
3
+ self.name = "Dashboard"
4
+
5
+ # self.description = "Tiny dashboard description"
6
+ # self.grid_cols = 3
7
+ # self.visible = -> do
8
+ # true
9
+ # end
10
+
11
+ # cards go here
12
+ # card UsersCount
13
+ end
@@ -0,0 +1,12 @@
1
+ class DbSchemaResource < Avo::BaseResource
2
+ self.title = :display_name
3
+ self.includes = []
4
+
5
+ # self.search_query = ->(params:) do
6
+ # scope.ransack(id_eq: params[:q], m: "or").result(distinct: false)
7
+ # end
8
+
9
+ field :id, as: :id
10
+ # field :data, as: :textarea, only_on: [:edit]
11
+ # field :user_name, as: :text
12
+ end
@@ -0,0 +1,15 @@
1
+ class RailsAppResource < Avo::BaseResource
2
+ self.title = :display_name
3
+ self.includes = []
4
+
5
+ # self.search_query = ->(params:) do
6
+ # scope.ransack(id_eq: params[:q], m: "or").result(distinct: false)
7
+ # end
8
+
9
+ field :id, as: :id
10
+ field :name, as: :text
11
+
12
+ field :db_schema, as: :has_one
13
+ field :table_count, as: :has_one
14
+ field :rubocop, as: :has_one
15
+ end
@@ -0,0 +1,12 @@
1
+ class RubocopResource < Avo::BaseResource
2
+ self.title = :display_name
3
+ self.includes = []
4
+
5
+ # self.search_query = ->(params:) do
6
+ # scope.ransack(id_eq: params[:q], m: "or").result(distinct: false)
7
+ # end
8
+
9
+ field :id, as: :id
10
+ # field :data, as: :textarea, only_on: [:edit]
11
+ # field :user_name, as: :text
12
+ end
@@ -0,0 +1,12 @@
1
+ class TableCountResource < Avo::BaseResource
2
+ self.title = :display_name
3
+ self.includes = []
4
+
5
+ # self.search_query = ->(params:) do
6
+ # scope.ransack(id_eq: params[:q], m: "or").result(distinct: false)
7
+ # end
8
+
9
+ field :id, as: :id
10
+ # field :data, as: :textarea, only_on: [:edit]
11
+ # field :user_name, as: :text
12
+ end
@@ -0,0 +1,24 @@
1
+ # tutorial (user resource): https://youtu.be/WgNK-oINFww?t=599
2
+ class UserResource < Avo::BaseResource
3
+ # https://docs.avohq.io/2.0/resources.html#devise-password-optional
4
+ # you need to fill in the password when creating a new user,
5
+ # but when editing a user you can leave the password field empty
6
+ self.devise_password_optional = true
7
+
8
+ # tutorial (better search experience): https://youtu.be/WgNK-oINFww?t=649
9
+ self.title = :email
10
+ self.includes = []
11
+
12
+ self.search_query = ->(params:) do
13
+ scope
14
+ .ransack(id_eq: params[:q], name_cont: params[:q], email_cont: params[:q], m: "or")
15
+ .result(distinct: false)
16
+ end
17
+
18
+ field :id, as: :id
19
+ field :email, as: :gravatar, link_to_resource: true, as_avatar: true
20
+ field :name, as: :text
21
+ field :email, as: :text, as_description: true
22
+ field :password, as: :text
23
+ field :posts, as: :has_many
24
+ end
@@ -0,0 +1,12 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+
5
+ def quick_signin
6
+ sign_in(:user, User.first)
7
+ end
8
+
9
+ def reseed
10
+ SeedService.seed
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class DbSchema < ApplicationRecord
2
+ belongs_to :rails_app
3
+
4
+ # def user_name
5
+ # rails_app.user.name
6
+ # end
7
+
8
+ def display_name
9
+ "DB Schema for #{rails_app.name} - #{created_at.strftime("%d/%m/%Y")}"
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ class RailsApp < ApplicationRecord
2
+ belongs_to :user
3
+ end
@@ -0,0 +1,11 @@
1
+ class Rubocop < ApplicationRecord
2
+ belongs_to :rails_app
3
+
4
+ # def user_name
5
+ # rails_app.user.name
6
+ # end
7
+
8
+ def display_name
9
+ "RuboCop for #{rails_app.name} - #{created_at.strftime("%d/%m/%Y")}"
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class TableCount < ApplicationRecord
2
+ belongs_to :rails_app
3
+
4
+ # def user_name
5
+ # rails_app.user.name
6
+ # end
7
+
8
+ def display_name
9
+ "Table Counts for #{rails_app.name} - #{created_at.strftime("%d/%m/%Y")}"
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ WITH
2
+
3
+ files AS (
4
+ SELECT jsonb_array_elements(data->'files') FROM rubocops
5
+ ),
6
+ lines AS (
7
+ SELECT
8
+ jsonb_array_elements(files)->>'file' as file,
9
+ jsonb_array_elements(files)->'lines' as lines
10
+ FROM files
11
+ ),
12
+ rubocop_log AS (
13
+ SELECT
14
+ jsonb_array_elements(lines)->>'position' as position,
15
+ jsonb_array_elements(lines)->>'status' as status,
16
+ jsonb_array_elements(lines)->>'status_message' as status_message,
17
+ jsonb_array_elements(lines)->>'cop' as cop,
18
+ jsonb_array_elements(lines)->>'message' as message,
19
+ jsonb_array_elements(lines)->>'full_line' as full_line,
20
+ jsonb_array_elements(lines)->>'file_name' as file_name
21
+ FROM lines
22
+ )
23
+ select * from rubocop_log
@@ -0,0 +1,10 @@
1
+ class RubocopLogQuery < SqlQuery
2
+ sql_resource './rubocop_log.psql'
3
+ fields %i(position status status_message cop message full_line file_name)
4
+
5
+ def call
6
+ sql_query = "#{sql} LIMIT 5"
7
+
8
+ query(sql_query)
9
+ end
10
+ end