rails_app_generator 0.2.43 → 0.3.2

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/README.md +22 -1
  4. data/after_templates/addons/factory_bot/_.rb +82 -0
  5. data/after_templates/addons/factory_bot/app/controllers/home_controller.rb +10 -0
  6. data/after_templates/addons/factory_bot/app/services/seed_service.rb +35 -0
  7. data/after_templates/addons/factory_bot/app/views/home/index.html.erb +3 -0
  8. data/after_templates/addons/factory_bot/app/views/layouts/_footer.html.erb +0 -0
  9. data/after_templates/addons/factory_bot/app/views/layouts/_navbar.html.erb +10 -0
  10. data/after_templates/addons/factory_bot/app/views/layouts/application.html.erb +29 -0
  11. data/after_templates/addons/factory_bot/db/seeds.rb +1 -0
  12. data/after_templates/addons/factory_bot/factories.rb +73 -0
  13. data/after_templates/addons/factory_bot/factory-create-user.png +0 -0
  14. data/after_templates/addons/factory_bot/factory-employee-bad.png +0 -0
  15. data/after_templates/addons/factory_bot/factory-employee-good.png +0 -0
  16. data/after_templates/addons/factory_bot/factory-role.png +0 -0
  17. data/after_templates/addons/factory_bot/factory-video.png +0 -0
  18. data/after_templates/application/klueless/.rubocop.yml +40 -0
  19. data/after_templates/application/klueless/_.rb +31 -12
  20. data/after_templates/application/klueless/app/avo/cards/amount_raised.rb +14 -0
  21. data/after_templates/application/klueless/app/avo/cards/example_custom_partial.rb +7 -0
  22. data/after_templates/application/klueless/app/avo/cards/example_metric.rb +38 -0
  23. data/after_templates/application/klueless/app/avo/cards/percent_done.rb +10 -0
  24. data/after_templates/application/klueless/app/avo/cards/rubocop_card.rb +10 -0
  25. data/after_templates/application/klueless/app/avo/filters/rubocop_entry_cop_filter.rb +15 -0
  26. data/after_templates/application/klueless/app/avo/filters/rubocop_entry_filename_filter.rb +13 -0
  27. data/after_templates/application/klueless/app/avo/filters/rubocop_entry_message_filter.rb +13 -0
  28. data/after_templates/application/klueless/app/avo/filters/rubocop_entry_status_filter.rb +15 -0
  29. data/after_templates/application/klueless/app/avo/filters/table_count_entry_tablename_filter.rb +13 -0
  30. data/after_templates/application/klueless/app/avo/resource_tools/rubocop_info.rb +4 -0
  31. data/after_templates/application/klueless/app/avo/resources/rubocop_entry_resource.rb +28 -0
  32. data/after_templates/application/klueless/app/avo/resources/rubocop_resource.rb +9 -0
  33. data/after_templates/application/klueless/app/avo/resources/table_count_entry_resource.rb +18 -0
  34. data/after_templates/application/klueless/app/controllers/home_controller.rb +9 -1
  35. data/after_templates/application/klueless/app/services/seed_service.rb +49 -3
  36. data/after_templates/application/klueless/app/views/home/index.html.erb +2 -2
  37. data/after_templates/application/klueless/app/views/layouts/_navbar.html.erb +6 -3
  38. data/after_templates/application/klueless/config/initializers/avo.rb +4 -2
  39. data/after_templates/application/klueless/db/seeds.rb +1 -18
  40. data/after_templates/application/klueless/db/views/rubocop_entries_v01.sql +23 -0
  41. data/after_templates/application/klueless/db/views/table_count_entries_v01.sql +11 -0
  42. data/docs/last_run/app_generator_data.json +7 -7
  43. data/docs/last_run/rails_options_data.json +10 -8
  44. data/lib/rails_app_generator/app_generator.rb +18 -4
  45. data/lib/rails_app_generator/cli/profile.rb +1 -3
  46. data/lib/rails_app_generator/starter.rb +49 -8
  47. data/lib/rails_app_generator/version.rb +1 -1
  48. data/package-lock.json +2 -2
  49. data/package.json +1 -1
  50. data/profiles/addons/factory_bot.json +18 -0
  51. data/profiles/addons/faker.json +1 -1
  52. data/profiles/application/klueless.json +7 -3
  53. data/templates/README.md.erb +2 -2
  54. data/templates/thor_task/profile/app/services/seed_service.rb +8 -4
  55. data/templates/thor_task/profile/profile.json.tt +2 -1
  56. metadata +33 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d9ac313ea8fc5383a7d3d37ed9495fff8509f9b7dd1ff373ed97c80ce69ae23
4
- data.tar.gz: bb65bdcc19d95bfb69abf92458dbe0eec353a8b3085ba8e679d72955ab55f425
3
+ metadata.gz: c53c84982de8f9b1f3180f4c84b7527a04cc623dac815cdec90d325f7e56183f
4
+ data.tar.gz: 0f2d44fc8597836b396faa7b3ef6995896e41222b34362a0cb73802bd2fbd70d
5
5
  SHA512:
6
- metadata.gz: 6f0ccd26ef5090325cbb6a76408fd201bbce81d8bbd739618e14393eebe0cc6814bb9e24eecdfec7dd7fd07664fe9e52ed1e47d92343461b45ab3378d37e22f7
7
- data.tar.gz: 70dee6a466c8976ba4f385d532b34325d188a83599df9d4fcd4330b6805f9f0dcc580141fc4ad5e9d1b9a393c4b2084698f7a2771254b7839a18a4f98471765c
6
+ metadata.gz: 0d2f6fe3d00ca2befc5acaf668f58f655c60e7f0a0d14f7670067f5e3847861e92cf93a927d284d36546a26bf85ea8beebb7ac76cc183d88c0bf2b06e8c60d18
7
+ data.tar.gz: 24704cce18d58445b1a1d69122df8e098e3f2b87627030df4b1e863931e7320e0da89e71b8e5d4ac7e886c03c01d7b593aec20da3cc3165703771e8b5945c4c9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## [0.3.1](https://github.com/klueless-io/rails_app_generator/compare/v0.3.0...v0.3.1) (2022-09-02)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * rename to when_folder_exist ([3363b0c](https://github.com/klueless-io/rails_app_generator/commit/3363b0c5df5c161f3578ae422b79c3bb7f3b863e))
7
+
8
+ # [0.3.0](https://github.com/klueless-io/rails_app_generator/compare/v0.2.43...v0.3.0) (2022-09-02)
9
+
10
+
11
+ ### Features
12
+
13
+ * add target_folder_exists handling ([cf0b7c6](https://github.com/klueless-io/rails_app_generator/commit/cf0b7c6d9b09fddc6cef940b17d3ce431b9c4eff))
14
+
15
+ ## [0.2.43](https://github.com/klueless-io/rails_app_generator/compare/v0.2.42...v0.2.43) (2022-08-31)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * add scenic profile ([dc309e6](https://github.com/klueless-io/rails_app_generator/commit/dc309e6f399cec7085de3133aa32989bc7ff7ed4))
21
+ * add scenic profile ([44614f7](https://github.com/klueless-io/rails_app_generator/commit/44614f70d73fe41cee5fd9cb9af5d20f0aa4f915))
22
+
1
23
  ## [0.2.42](https://github.com/klueless-io/rails_app_generator/compare/v0.2.41...v0.2.42) (2022-08-30)
2
24
 
3
25
 
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
  gem install rails_app_generator
23
23
  ```
24
24
 
25
- Use the Gem
25
+ ### Use the Gem
26
26
 
27
27
  ```
28
28
  rag rag-simple
@@ -30,6 +30,27 @@ rag rag-tailwind
30
30
  rag rag-bootstrap
31
31
  ```
32
32
 
33
+ ### Create new Addon to Rails App Generator
34
+
35
+ If you need to make a new addon available then use `thor addon:new`
36
+
37
+ Generally an Addon will be for a gem so if you use the `--gem` option, it will bring in the GEM info such as latest version number
38
+
39
+ ```
40
+ thor addon:new image_processing --gem
41
+ thor addon:new kaminari --gem
42
+ ```
43
+
44
+ ### Create new Profile to Rails App Generator
45
+
46
+ A profile is a sample Rails application template with files that allows you to test one or more Addons and produces a working Rails 7 application.
47
+
48
+ If you are just keeping the example to a simple GEM then use the `--variant` option with the folder you would like to write code into, e.g. `addons`
49
+
50
+ ```
51
+ thor profile:new factory_bot --variant=addons
52
+ thor profile:new kaminari --variant=addons
53
+ ```
33
54
 
34
55
  ## Notes
35
56
 
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ # factory_bot provides a framework and DSL for defining and using factories - less error-prone, more explicit, and all-around easier to work with than fixtures.
4
+ #
5
+ # exe/rag addons/factory_bot
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
+ create_db
15
+ scaffolds
16
+ setup_customizations
17
+ migrate_db
18
+ end
19
+
20
+ # Goals:
21
+ # - Store Factories in subfolder under spec
22
+ # -
23
+ # - Use the faker GEM with both standard and custom data
24
+ # - Custom data goes in custom locales folder, see: https://stackoverflow.com/questions/28153540/extending-faker-in-a-gem-where-do-i-put-the-yaml-file
25
+ # - Use associations to affectively create related records
26
+ # - Create default and NULL factory example
27
+ # - Create Seed Data services
28
+ # - Add support for STI
29
+ # - Add support for polymorphic associations
30
+ # Things to be aware of in faker
31
+ # - Random focused data is better then sequence
32
+ # sequence(:name) { |n| "Category #{n}" }
33
+ # vs
34
+ # name { Faker::Hipster.word }
35
+ # -
36
+
37
+
38
+ def scaffolds
39
+ add_scaffold('app', 'title', 'description', 'settings:json')
40
+ add_scaffold('tenant', 'name', 'slug', 'active:boolean', 'app:references')
41
+ add_scaffold('role', 'code') # contributor, moderator, admin
42
+ add_scaffold('employee', 'first_name', 'last_name', 'address:text', 'email', 'password', 'tenant:references', 'role:references')
43
+ add_scaffold('project', 'name', 'status', 'budget:decimal', 'country', 'progress:integer', 'tenant:references')
44
+ add_scaffold('article', 'title', 'body:text', 'is_featured:boolean', 'employee:references', 'tenant:references')
45
+ add_scaffold('video', 'title', 'youtube_id', '', 'article:references')
46
+ end
47
+
48
+ def setup_customizations
49
+ route("root 'home#index'")
50
+
51
+ force_copy
52
+
53
+ add_controller('home', 'index', 'reseed')
54
+
55
+ directory "app/controllers"
56
+ directory "app/models"
57
+ directory "app/views"
58
+ template 'app/views/layouts/application.html.erb' , 'app/views/layouts/application.html.erb'
59
+ directory "app/services"
60
+ copy_file 'factories.rb'
61
+ end
62
+
63
+ def create_db
64
+ # uncomment this if you need custom configuration in database.yml
65
+ # gsub_file('config/database.yml', ' encoding: unicode', db_development_settings)
66
+ db(create: true)
67
+ end
68
+
69
+ def migrate_db
70
+ template 'db/seeds.rb' , 'db/seeds.rb'
71
+
72
+ db(migrate: true, seed: true)
73
+ end
74
+
75
+ def db_development_settings
76
+ <<-'RUBY'
77
+ encoding: unicode
78
+ host: 127.0.0.1
79
+ username: printspeak
80
+ password: printspeak
81
+ RUBY
82
+ end
@@ -0,0 +1,10 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+
5
+ def reseed
6
+ SeedService.seed(variant: :reset)
7
+
8
+ redirect_back_or_to root_path
9
+ end
10
+ end
@@ -0,0 +1,35 @@
1
+ class SeedService
2
+ class << self
3
+ def seed(variant: :reset)
4
+ service = SeedService.new
5
+ service.call(variant: variant)
6
+ end
7
+ end
8
+
9
+ def call(variant: :reset)
10
+ reset if variant == :reset
11
+ refresh if variant == :refresh
12
+ create
13
+ end
14
+
15
+ private
16
+
17
+ def reset
18
+ Article.delete_all
19
+ Project.delete_all
20
+ Employee.delete_all
21
+ Tenant.delete_all
22
+ App.delete_all
23
+ end
24
+
25
+ def refresh
26
+ end
27
+
28
+ def create
29
+ app = FactoryBot.create(:app)
30
+ tenants = FactoryBot.create_list(:tenant, rand(10..20), app: app)
31
+ employees = FactoryBot.create_list(:employee, rand(10..20), tenant: tenants.sample)
32
+ _articles = FactoryBot.create_list(:article, rand(10..20), tenant: tenants.sample, employee: employees.sample)
33
+ _projects = FactoryBot.create_list(:project, rand(10..20), tenant: tenants.sample)
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ <h1>Factory bot</h1>
2
+
3
+ <p>factory_bot provides a framework and DSL for defining and using factories - less error-prone, more explicit, and all-around easier to work with than fixtures.</p>
@@ -0,0 +1,10 @@
1
+ <%= link_to 'Home', root_path %>
2
+ | <%= link_to 'Apps', apps_path %>
3
+ | <%= link_to 'Tenants', tenants_path %>
4
+ | <%= link_to 'Employees', employees_path %>
5
+ | <%= link_to 'Roles', roles_path %>
6
+ | <%= link_to 'Projects', projects_path %>
7
+ | <%= link_to 'Articles', articles_path %>
8
+ | <%= link_to 'Videos', videos_path %>
9
+ | <%= link_to 'Re-Seed', home_reseed_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,73 @@
1
+ FactoryBot.define do
2
+ factory :app do
3
+ title { Faker::Name.name } # Faker::App.name
4
+ description { Faker::Lorem.paragraphs(number: rand(4...10)).join("\n") }
5
+ settings { { 'foo' => 'bar' } }
6
+ end
7
+
8
+ factory :tenant do
9
+ name { Faker::Name.name }
10
+ slug { Faker::Internet.slug }
11
+ active { [true, false].sample }
12
+ app
13
+ end
14
+
15
+ factory :employee do
16
+ first_name { Faker::Name.first_name }
17
+ last_name { Faker::Name.last_name }
18
+ email { Faker::Internet.email }
19
+ password { Faker::Internet.password }
20
+ address { Faker::Address.full_address }
21
+ end
22
+
23
+ factory :article do
24
+ title { Faker::Quote.famous_last_words }
25
+ body { Faker::Lorem.paragraphs(number: rand(4...10)).join("\n") }
26
+ is_featured { [true, false].sample }
27
+ end
28
+
29
+ factory :project do
30
+ name { Faker::App.name }
31
+ status { [:closed, :rejected, :failed, :loading, :running, :waiting, :done, :finalized, :archived, :finished].sample }
32
+ budget { Faker::Number.decimal(l_digits: 4) }
33
+ country { Faker::Address.country_code }
34
+ progress { Faker::Number.between(from: 0, to: 100) }
35
+ end
36
+ end
37
+
38
+ def examples
39
+ Faker::Name.name
40
+ Faker::Name.unique.name
41
+
42
+ Faker::Internet.email
43
+
44
+ Faker::Artist.name
45
+ Faker::Address.city #=> "Imogeneborough"
46
+ Faker::Address.street_name #=> "Larkin Fork"
47
+ Faker::Address.street_address #=> "282 Kevin Brook"
48
+ Faker::Address.secondary_address #=> "Apt. 672"
49
+ Faker::Address.building_number #=> "7304"
50
+ Faker::Address.mail_box #=> "PO Box 123"
51
+ Faker::Address.community #=> "University Crossing"
52
+ Faker::Address.zip_code #=> "58517" or "23285-4905"
53
+ Faker::Address.zip #=> "58517" or "66259-8212"
54
+ Faker::Address.postcode #=> "76032-4907" or "58517"
55
+ Faker::Address.time_zone #=> "Asia/Yakutsk"
56
+ Faker::Address.street_suffix #=> "Street"
57
+ Faker::Address.city_suffix #=> "fort"
58
+ Faker::Address.city_prefix #=> "Lake"
59
+ Faker::Address.state #=> "California"
60
+ Faker::Address.state_abbr #=> "AP"
61
+ Faker::Address.country #=> "French Guiana"
62
+
63
+ # Keyword arguments: code
64
+ Faker::Address.country_by_code(code: 'NL') #=> "Netherlands"
65
+
66
+ # Keyword arguments: name
67
+ Faker::Address.country_name_to_code(name: 'united_states') #=> "US"
68
+ Faker::Address.country_code #=> "IT"
69
+ Faker::Address.country_code_long #=> "ITA"
70
+ Faker::Address.latitude #=> "-58.17256227443719"
71
+ Faker::Address.longitude #=> "-156.65548382095133"
72
+ Faker::Address.full_address #=> "282 Kevin Brook, Imogeneborough, CA 58517"
73
+ end
@@ -0,0 +1,40 @@
1
+ require:
2
+ - rubocop-rails
3
+
4
+ AllCops:
5
+ NewCops: enable
6
+ Exclude:
7
+ - bin/*
8
+ - db/schema.rb
9
+ - db/migrate/*
10
+ - node_modules/**/*
11
+
12
+ Naming/AccessorMethodName:
13
+ Enabled: false
14
+
15
+ Metrics/MethodLength:
16
+ CountAsOne: ['array', 'heredoc']
17
+ AllowedMethods: ['describe', 'context']
18
+
19
+ Metrics/BlockLength:
20
+ AllowedMethods: ['describe', 'context']
21
+ Exclude:
22
+ - config/environments/*.rb
23
+ - '**/*.rake'
24
+
25
+ Layout/LineLength:
26
+ Max: 120
27
+
28
+ Layout/MultilineMethodCallIndentation:
29
+ EnforcedStyle: indented
30
+
31
+ Lint/EmptyBlock:
32
+ Exclude:
33
+ - spec/factories/*
34
+
35
+ Style/BlockDelimiters:
36
+ Exclude:
37
+ - spec/**/*
38
+
39
+ Style/Documentation:
40
+ Enabled: false
@@ -14,9 +14,9 @@ after_bundle do
14
14
  force_copy
15
15
  create_db
16
16
  scaffolds
17
+ setup_avo
17
18
  setup_customizations
18
19
  migrate_db
19
- setup_avo
20
20
 
21
21
  swap1 = ' resources :users'
22
22
  swap2 = " devise_for :users, controllers: { sessions: 'users/sessions', registrations: 'users/registrations' }"
@@ -27,6 +27,8 @@ end
27
27
  def scaffolds
28
28
  add_scaffold_controller('users', 'name', 'email')
29
29
 
30
+ add_scaffold('booking', 'name', 'state')
31
+
30
32
  add_scaffold('rails_app', 'name', 'user:references') # name of the rails_app
31
33
 
32
34
  # no of records in each table per region
@@ -44,6 +46,9 @@ def scaffolds
44
46
  # add_scaffold('db_schema_foreign_key', 'left', 'right', 'name', 'on_update', 'on_delete', 'column', 'db_schema_table:references')
45
47
  # add_scaffold('db_schema_index', 'name', 'fields', 'using', 'order:jsonb', 'where', 'unique', 'db_schema_table:references')
46
48
  # add_scaffold('db_schema_view', 'name', 'materialized:boolean', 'sql_definition', 'db_schema_table:references')
49
+
50
+ generate('scenic:model rubocop_entry --materialized')
51
+ generate('scenic:model table_count_entry')
47
52
  end
48
53
 
49
54
  def setup_customizations
@@ -51,36 +56,50 @@ def setup_customizations
51
56
 
52
57
  force_copy
53
58
 
54
- add_controller('home', 'index', 'quick_signin', 'reseed')
59
+ add_controller('home', 'index', 'quick_signin', 'reseed', 'refresh_material_view')
55
60
 
56
61
  directory "app/controllers"
57
62
  directory "app/models"
58
63
  directory "app/views"
59
64
  template 'app/views/layouts/application.html.erb', 'app/views/layouts/application.html.erb'
60
65
  directory "app/queries"
66
+ directory "app/services"
67
+ directory "db/views" # takes views from both scaffolds and customizations
68
+
69
+ copy_file '.rubocop.yml', '.rubocop.yml'
61
70
  end
62
71
 
63
72
  def setup_avo
64
- # generate('avo:install')
73
+ generate('avo:resource rails_app')
74
+
75
+ generate('avo:resource table_count')
76
+ generate('avo:resource table_count_entry')
77
+ generate('avo:filter table_count_tablename_filter')
78
+
79
+ generate('avo:resource rubocop')
80
+ generate('avo:resource_tool rubocop_info')
81
+
82
+ generate('avo:resource rubocop_entry')
83
+ generate('avo:filter rubocop_entry_cop_filter')
84
+ generate('avo:filter rubocop_entry_filename_filter')
85
+ generate('avo:filter rubocop_entry_message_filter')
86
+ generate('avo:filter rubocop_entry_status_filter')
87
+
88
+ generate('avo:resource db_schema')
89
+ generate('avo:resource user')
65
90
 
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
91
  # generate('avo:dashboard Dashboard')
72
92
 
73
93
  directory "app/avo"
74
94
  directory "config/initializers"
75
95
  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
96
  end
80
97
 
81
98
  def create_db
82
99
  gsub_file('config/database.yml', ' encoding: unicode', db_development_settings)
83
- db(drop: true, create: true)
100
+
101
+ db_recreate(environment: :development)
102
+ db_recreate(environment: :test)
84
103
  end
85
104
 
86
105
  def migrate_db
@@ -0,0 +1,14 @@
1
+ class AmountRaised < Avo::Dashboards::MetricCard
2
+ self.id = "amount_raised"
3
+ self.label = "Amount raised"
4
+ # self.description = "Some description"
5
+ # self.cols = 1
6
+ # self.initial_range = 30
7
+ # self.ranges = [7, 30, 60, 365, "TODAY", "MTD", "QTD", "YTD", "ALL"]
8
+ self.prefix = "$"
9
+ # self.suffix = ""
10
+
11
+ query do
12
+ result 9001
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ class ExampleCustomPartial < Avo::Dashboards::PartialCard
2
+ self.id = "users_custom_card"
3
+ self.cols = 3
4
+ self.rows = 4
5
+ self.partial = "avo/cards/custom_card"
6
+ self.description = "This card has been loaded from a custom partial."
7
+ end
@@ -0,0 +1,38 @@
1
+ class ExampleMetric < Avo::Dashboards::MetricCard
2
+ self.id = "users_metric"
3
+ self.label = "Users count"
4
+ self.description = "Users description"
5
+ self.cols = 1
6
+ self.initial_range = 30
7
+ self.ranges = [7, 30, 60, 365, "TODAY", "MTD", "QTD", "YTD", "ALL"]
8
+ # self.prefix = "$"
9
+ # self.suffix = "%"
10
+ self.refresh_every = 10.minutes
11
+
12
+ # You have access to context, params, range, current dashboard, and current card
13
+ query do
14
+ from = Date.today.midnight - 1.week
15
+ to = DateTime.current
16
+
17
+ if range.present?
18
+ if range.to_s == range.to_i.to_s
19
+ from = DateTime.current - range.to_i.days
20
+ else
21
+ case range
22
+ when "TODAY"
23
+ from = DateTime.current.beginning_of_day
24
+ when "MTD"
25
+ from = DateTime.current.beginning_of_month
26
+ when "QTD"
27
+ from = DateTime.current.beginning_of_quarter
28
+ when "YTD"
29
+ from = DateTime.current.beginning_of_year
30
+ when "ALL"
31
+ from = Time.at(0)
32
+ end
33
+ end
34
+ end
35
+
36
+ result User.where(created_at: from..to).count
37
+ end
38
+ end
@@ -0,0 +1,10 @@
1
+ class PercentDone < Avo::Dashboards::MetricCard
2
+ self.id = "percent_done"
3
+ self.label = "Percent done"
4
+ self.description = "This is the progress we made so far..."
5
+ self.suffix = "%"
6
+
7
+ query do
8
+ result 42
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class RubocopCard < Avo::Dashboards::PartialCard
2
+ self.id = "percent_done"
3
+ self.label = "Percent done"
4
+ self.description = "This is the progress we made so far..."
5
+
6
+ self.cols = 3
7
+ self.rows = 20
8
+ self.partial = "avo/cards/rubocop_card"
9
+
10
+ end
@@ -0,0 +1,15 @@
1
+ class RubocopEntryCopFilter < Avo::Filters::MultipleSelectFilter
2
+ self.name = "Cop"
3
+
4
+ def apply(_request, query, values)
5
+ query.where(cop: values)
6
+ end
7
+
8
+ def options
9
+ RubocopEntry
10
+ .select(:cop)
11
+ .distinct
12
+ .order(:cop)
13
+ .map { |entry| [entry.cop, entry.cop] }.to_h
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ class RubocopEntryFilenameFilter < Avo::Filters::TextFilter
2
+ self.name = "FileName"
3
+
4
+ def apply(_request, query, value)
5
+ values = value.split(" ")
6
+
7
+ values.each do |word|
8
+ query = query.where("file_name ILIKE ?", "%#{word}%")
9
+ end
10
+
11
+ query
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ class RubocopEntryMessageFilter < Avo::Filters::TextFilter
2
+ self.name = "Message"
3
+
4
+ def apply(_request, query, value)
5
+ values = value.split(" ")
6
+
7
+ values.each do |word|
8
+ query = query.where("message ILIKE ?", "%#{word}%")
9
+ end
10
+
11
+ query
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ class RubocopEntryStatusFilter < Avo::Filters::SelectFilter
2
+ self.name = "Status"
3
+
4
+ def apply(_request, query, value)
5
+ query.where(status: value)
6
+ end
7
+
8
+ def options
9
+ RubocopEntry
10
+ .select(:status)
11
+ .distinct
12
+ .order(:status)
13
+ .map { |entry| [entry.status, entry.status] }.to_h
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ class TableCountEntryTablenameFilter < Avo::Filters::TextFilter
2
+ self.name = "Table Name"
3
+
4
+ def apply(_request, query, value)
5
+ values = value.split(" ")
6
+
7
+ values.each do |word|
8
+ query = query.where("table_name ILIKE ?", "%#{word}%")
9
+ end
10
+
11
+ query
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ class RubocopInfo < Avo::BaseResourceTool
2
+ self.name = "Rubocop info"
3
+ self.partial = "avo/resource_tools/rubocop_info"
4
+ end