Skip to content

Commit

Permalink
feat: Annotate Models
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarMWarraich committed Jul 1, 2024
1 parent c1ee279 commit e7397c5
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 7 deletions.
22 changes: 22 additions & 0 deletions app/models/generated_image.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# == Schema Information
#
# Table name: generated_images
#
# id :bigint not null, primary key
# info :json
# negative_prompt :string
# parameters :json
# prompt :string
# style_template :string
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
#
# Indexes
#
# index_generated_images_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
class GeneratedImage < ApplicationRecord
belongs_to :user
has_one_attached :sketch
Expand Down
13 changes: 11 additions & 2 deletions app/models/progress_holder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@
#
# id :bigint not null, primary key
# task_ref :string
# live_preview_id :integer
# user_id :bigint not null
# created_at :datetime not null
# updated_at :datetime not null
# live_preview_id :integer
# user_id :bigint not null
#
# Indexes
#
# index_progress_holders_on_task_ref (task_ref) UNIQUE
# index_progress_holders_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
class ProgressHolder < ApplicationRecord
include ActionView::RecordIdentifier
Expand Down
59 changes: 59 additions & 0 deletions lib/tasks/auto_annotate_models.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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'
task :set_annotation_options 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

Annotate.load_tasks
end
23 changes: 22 additions & 1 deletion test/fixtures/generated_images.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# == Schema Information
#
# Table name: generated_images
#
# id :bigint not null, primary key
# info :json
# negative_prompt :string
# parameters :json
# prompt :string
# style_template :string
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
#
# Indexes
#
# index_generated_images_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#

one:
prompt: MyString
Expand Down
21 changes: 20 additions & 1 deletion test/fixtures/progress_holders.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# == Schema Information
#
# Table name: progress_holders
#
# id :bigint not null, primary key
# task_ref :string
# created_at :datetime not null
# updated_at :datetime not null
# live_preview_id :integer
# user_id :bigint not null
#
# Indexes
#
# index_progress_holders_on_task_ref (task_ref) UNIQUE
# index_progress_holders_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#

one:
task_ref: MyString
Expand Down
11 changes: 10 additions & 1 deletion test/fixtures/users.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# == Schema Information
#
# Table name: users
#
# id :bigint not null, primary key
# email :string
# password_digest :string
# created_at :datetime not null
# updated_at :datetime not null
#

one:
email: MyString
Expand Down
22 changes: 22 additions & 0 deletions test/models/generated_image_test.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# == Schema Information
#
# Table name: generated_images
#
# id :bigint not null, primary key
# info :json
# negative_prompt :string
# parameters :json
# prompt :string
# style_template :string
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
#
# Indexes
#
# index_generated_images_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
require "test_helper"

class GeneratedImageTest < ActiveSupport::TestCase
Expand Down
13 changes: 11 additions & 2 deletions test/models/progress_holder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@
#
# id :bigint not null, primary key
# task_ref :string
# live_preview_id :integer
# user_id :bigint not null
# created_at :datetime not null
# updated_at :datetime not null
# live_preview_id :integer
# user_id :bigint not null
#
# Indexes
#
# index_progress_holders_on_task_ref (task_ref) UNIQUE
# index_progress_holders_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (user_id => users.id)
#
require "test_helper"

Expand Down

0 comments on commit e7397c5

Please sign in to comment.