Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: annotate models #93

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ group :development do
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"

gem 'annotate', '~> 3.2', '>= 3.2.0'

# Capistrano - deployment gems
gem 'capistrano', '~> 3.11'
gem 'capistrano-asdf'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ GEM
public_suffix (>= 2.0.2, < 5.0)
airbrussh (1.4.1)
sshkit (>= 1.6.1, != 1.7.0)
annotate (3.2.0)
activerecord (>= 3.2, < 8.0)
rake (>= 10.4, < 14.0)
ar_lazy_preload (1.1.2)
rails (>= 5.2)
ast (2.4.2)
Expand Down Expand Up @@ -375,6 +378,7 @@ PLATFORMS

DEPENDENCIES
active_storage_validations (~> 1.0)
annotate (~> 3.2, >= 3.2.0)
aws-sdk-s3 (~> 1.119)
bootsnap
cancancan (~> 3.4)
Expand Down
17 changes: 17 additions & 0 deletions app/models/chapter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: chapters
#
# id :bigint not null, primary key
# description :text
# location :string
# name :string
# created_at :datetime not null
# updated_at :datetime not null
# country_id :bigint
#
# Indexes
#
# index_chapters_on_country_id (country_id)
# index_chapters_on_name (name) UNIQUE
#
class Chapter < ApplicationRecord
# Attachments
has_one_attached :image
Expand Down
9 changes: 9 additions & 0 deletions app/models/country.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: countries
#
# id :bigint not null, primary key
# name :string
# created_at :datetime not null
# updated_at :datetime not null
#
class Country < ApplicationRecord
# Associations
has_many :chapters, dependent: :nullify
Expand Down
11 changes: 11 additions & 0 deletions app/models/feature_flag.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: feature_flags
#
# id :bigint not null, primary key
# description :text
# enabled :boolean
# name :string
# created_at :datetime not null
# updated_at :datetime not null
#
class FeatureFlag < ApplicationRecord
end
21 changes: 21 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: projects
#
# id :bigint not null, primary key
# description :text
# end_date :datetime
# name :string
# start_date :datetime
# created_at :datetime not null
# updated_at :datetime not null
# chapter_id :bigint not null
#
# Indexes
#
# index_projects_on_chapter_id (chapter_id)
#
# Foreign Keys
#
# fk_rails_... (chapter_id => chapters.id)
#
class Project < ApplicationRecord
belongs_to :chapter
end
37 changes: 37 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: users
#
# id :bigint not null, primary key
# confirmation_sent_at :datetime
# confirmation_token :string
# confirmed_at :datetime
# current_sign_in_at :datetime
# current_sign_in_ip :string
# email :string default(""), not null
# encrypted_password :string default(""), not null
# failed_attempts :integer default(0), not null
# github_username :string
# last_sign_in_at :datetime
# last_sign_in_ip :string
# locked_at :datetime
# name :string
# phone_number :string
# remember_created_at :datetime
# reset_password_sent_at :datetime
# reset_password_token :string
# role :integer
# sign_in_count :integer default(0), not null
# unconfirmed_email :string
# unlock_token :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_users_on_confirmation_token (confirmation_token) UNIQUE
# index_users_on_email (email) UNIQUE
# index_users_on_github_username (github_username) UNIQUE
# index_users_on_reset_password_token (reset_password_token) UNIQUE
# index_users_on_unlock_token (unlock_token) UNIQUE
#
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
Expand Down
21 changes: 21 additions & 0 deletions app/models/users_chapter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: users_chapters
#
# id :bigint not null, primary key
# main_chapter :boolean default(FALSE)
# created_at :datetime not null
# updated_at :datetime not null
# chapter_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_users_chapters_on_chapter_id (chapter_id)
# index_users_chapters_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (chapter_id => chapters.id)
# fk_rails_... (user_id => users.id)
#
class UsersChapter < ApplicationRecord
# Associations
belongs_to :chapter
Expand Down
63 changes: 63 additions & 0 deletions lib/tasks/auto_annotate_models.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# frozen_string_literal: true

# NOTE: only doing this in development as some production environments (Heroku)
# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
# NOTE: to have a dev-mode tool do its thing in production.
if Rails.env.development?
require 'annotate'
# rubocop:disable Metrics/BlockLength
task set_annotation_options: :environment do
# You can override any of these by setting an environment variable of the
# same name.
Annotate.set_defaults(
'active_admin' => 'false',
'additional_file_patterns' => [],
'routes' => 'false',
'models' => 'true',
'position_in_routes' => 'before',
'position_in_class' => 'before',
'position_in_test' => 'before',
'position_in_fixture' => 'before',
'position_in_factory' => 'before',
'position_in_serializer' => 'before',
'show_foreign_keys' => 'true',
'show_complete_foreign_keys' => 'false',
'show_indexes' => 'true',
'simple_indexes' => 'false',
'model_dir' => 'app/models',
'root_dir' => '',
'include_version' => 'false',
'require' => '',
'exclude_tests' => 'false',
'exclude_fixtures' => 'false',
'exclude_factories' => 'false',
'exclude_serializers' => 'false',
'exclude_scaffolds' => 'true',
'exclude_controllers' => 'true',
'exclude_helpers' => 'true',
'exclude_sti_subclasses' => 'false',
'ignore_model_sub_dir' => 'false',
'ignore_columns' => nil,
'ignore_routes' => nil,
'ignore_unknown_models' => 'false',
'hide_limit_column_types' => 'integer,bigint,boolean',
'hide_default_column_types' => 'json,jsonb,hstore',
'skip_on_db_migrate' => 'false',
'format_bare' => 'true',
'format_rdoc' => 'false',
'format_yard' => 'false',
'format_markdown' => 'false',
'sort' => 'false',
'force' => 'false',
'frozen' => 'false',
'classified_sort' => 'true',
'trace' => 'false',
'wrapper_open' => nil,
'wrapper_close' => nil,
'with_comment' => 'true'
)
end
# rubocop:enable Metrics/BlockLength

Annotate.load_tasks
end
Loading