Skip to content
This repository was archived by the owner on May 12, 2025. It is now read-only.

Commit 575ae25

Browse files
authored
Merge pull request #93 from Annastacia-dev/enhancement/annotate-models
enhancement: annotate models
2 parents 1cd3e34 + ac53b98 commit 575ae25

File tree

9 files changed

+185
-0
lines changed

9 files changed

+185
-0
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ group :development do
5555
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
5656
# gem "spring"
5757

58+
gem 'annotate', '~> 3.2', '>= 3.2.0'
59+
5860
# Capistrano - deployment gems
5961
gem 'capistrano', '~> 3.11'
6062
gem 'capistrano-asdf'

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ GEM
7575
public_suffix (>= 2.0.2, < 5.0)
7676
airbrussh (1.4.1)
7777
sshkit (>= 1.6.1, != 1.7.0)
78+
annotate (3.2.0)
79+
activerecord (>= 3.2, < 8.0)
80+
rake (>= 10.4, < 14.0)
7881
ar_lazy_preload (1.1.2)
7982
rails (>= 5.2)
8083
ast (2.4.2)
@@ -375,6 +378,7 @@ PLATFORMS
375378

376379
DEPENDENCIES
377380
active_storage_validations (~> 1.0)
381+
annotate (~> 3.2, >= 3.2.0)
378382
aws-sdk-s3 (~> 1.119)
379383
bootsnap
380384
cancancan (~> 3.4)

app/models/chapter.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# frozen_string_literal: true
22

3+
# == Schema Information
4+
#
5+
# Table name: chapters
6+
#
7+
# id :bigint not null, primary key
8+
# description :text
9+
# location :string
10+
# name :string
11+
# created_at :datetime not null
12+
# updated_at :datetime not null
13+
# country_id :bigint
14+
#
15+
# Indexes
16+
#
17+
# index_chapters_on_country_id (country_id)
18+
# index_chapters_on_name (name) UNIQUE
19+
#
320
class Chapter < ApplicationRecord
421
# Attachments
522
has_one_attached :image

app/models/country.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# frozen_string_literal: true
22

3+
# == Schema Information
4+
#
5+
# Table name: countries
6+
#
7+
# id :bigint not null, primary key
8+
# name :string
9+
# created_at :datetime not null
10+
# updated_at :datetime not null
11+
#
312
class Country < ApplicationRecord
413
# Associations
514
has_many :chapters, dependent: :nullify

app/models/feature_flag.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
# frozen_string_literal: true
22

3+
# == Schema Information
4+
#
5+
# Table name: feature_flags
6+
#
7+
# id :bigint not null, primary key
8+
# description :text
9+
# enabled :boolean
10+
# name :string
11+
# created_at :datetime not null
12+
# updated_at :datetime not null
13+
#
314
class FeatureFlag < ApplicationRecord
415
end

app/models/project.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# frozen_string_literal: true
22

3+
# == Schema Information
4+
#
5+
# Table name: projects
6+
#
7+
# id :bigint not null, primary key
8+
# description :text
9+
# end_date :datetime
10+
# name :string
11+
# start_date :datetime
12+
# created_at :datetime not null
13+
# updated_at :datetime not null
14+
# chapter_id :bigint not null
15+
#
16+
# Indexes
17+
#
18+
# index_projects_on_chapter_id (chapter_id)
19+
#
20+
# Foreign Keys
21+
#
22+
# fk_rails_... (chapter_id => chapters.id)
23+
#
324
class Project < ApplicationRecord
425
belongs_to :chapter
526
end

app/models/user.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
# frozen_string_literal: true
22

3+
# == Schema Information
4+
#
5+
# Table name: users
6+
#
7+
# id :bigint not null, primary key
8+
# confirmation_sent_at :datetime
9+
# confirmation_token :string
10+
# confirmed_at :datetime
11+
# current_sign_in_at :datetime
12+
# current_sign_in_ip :string
13+
# email :string default(""), not null
14+
# encrypted_password :string default(""), not null
15+
# failed_attempts :integer default(0), not null
16+
# github_username :string
17+
# last_sign_in_at :datetime
18+
# last_sign_in_ip :string
19+
# locked_at :datetime
20+
# name :string
21+
# phone_number :string
22+
# remember_created_at :datetime
23+
# reset_password_sent_at :datetime
24+
# reset_password_token :string
25+
# role :integer
26+
# sign_in_count :integer default(0), not null
27+
# unconfirmed_email :string
28+
# unlock_token :string
29+
# created_at :datetime not null
30+
# updated_at :datetime not null
31+
#
32+
# Indexes
33+
#
34+
# index_users_on_confirmation_token (confirmation_token) UNIQUE
35+
# index_users_on_email (email) UNIQUE
36+
# index_users_on_github_username (github_username) UNIQUE
37+
# index_users_on_reset_password_token (reset_password_token) UNIQUE
38+
# index_users_on_unlock_token (unlock_token) UNIQUE
39+
#
340
class User < ApplicationRecord
441
# Include default devise modules. Others available are:
542
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable

app/models/users_chapter.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# frozen_string_literal: true
22

3+
# == Schema Information
4+
#
5+
# Table name: users_chapters
6+
#
7+
# id :bigint not null, primary key
8+
# main_chapter :boolean default(FALSE)
9+
# created_at :datetime not null
10+
# updated_at :datetime not null
11+
# chapter_id :bigint not null
12+
# user_id :bigint not null
13+
#
14+
# Indexes
15+
#
16+
# index_users_chapters_on_chapter_id (chapter_id)
17+
# index_users_chapters_on_user_id (user_id)
18+
#
19+
# Foreign Keys
20+
#
21+
# fk_rails_... (chapter_id => chapters.id)
22+
# fk_rails_... (user_id => users.id)
23+
#
324
class UsersChapter < ApplicationRecord
425
# Associations
526
belongs_to :chapter

lib/tasks/auto_annotate_models.rake

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# frozen_string_literal: true
2+
3+
# NOTE: only doing this in development as some production environments (Heroku)
4+
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
5+
# NOTE: to have a dev-mode tool do its thing in production.
6+
if Rails.env.development?
7+
require 'annotate'
8+
# rubocop:disable Metrics/BlockLength
9+
task set_annotation_options: :environment do
10+
# You can override any of these by setting an environment variable of the
11+
# same name.
12+
Annotate.set_defaults(
13+
'active_admin' => 'false',
14+
'additional_file_patterns' => [],
15+
'routes' => 'false',
16+
'models' => 'true',
17+
'position_in_routes' => 'before',
18+
'position_in_class' => 'before',
19+
'position_in_test' => 'before',
20+
'position_in_fixture' => 'before',
21+
'position_in_factory' => 'before',
22+
'position_in_serializer' => 'before',
23+
'show_foreign_keys' => 'true',
24+
'show_complete_foreign_keys' => 'false',
25+
'show_indexes' => 'true',
26+
'simple_indexes' => 'false',
27+
'model_dir' => 'app/models',
28+
'root_dir' => '',
29+
'include_version' => 'false',
30+
'require' => '',
31+
'exclude_tests' => 'false',
32+
'exclude_fixtures' => 'false',
33+
'exclude_factories' => 'false',
34+
'exclude_serializers' => 'false',
35+
'exclude_scaffolds' => 'true',
36+
'exclude_controllers' => 'true',
37+
'exclude_helpers' => 'true',
38+
'exclude_sti_subclasses' => 'false',
39+
'ignore_model_sub_dir' => 'false',
40+
'ignore_columns' => nil,
41+
'ignore_routes' => nil,
42+
'ignore_unknown_models' => 'false',
43+
'hide_limit_column_types' => 'integer,bigint,boolean',
44+
'hide_default_column_types' => 'json,jsonb,hstore',
45+
'skip_on_db_migrate' => 'false',
46+
'format_bare' => 'true',
47+
'format_rdoc' => 'false',
48+
'format_yard' => 'false',
49+
'format_markdown' => 'false',
50+
'sort' => 'false',
51+
'force' => 'false',
52+
'frozen' => 'false',
53+
'classified_sort' => 'true',
54+
'trace' => 'false',
55+
'wrapper_open' => nil,
56+
'wrapper_close' => nil,
57+
'with_comment' => 'true'
58+
)
59+
end
60+
# rubocop:enable Metrics/BlockLength
61+
62+
Annotate.load_tasks
63+
end

0 commit comments

Comments
 (0)