Skip to content

Commit

Permalink
Add gem annotate
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-avlijas committed Feb 16, 2022
1 parent 5493a4e commit 11d120a
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ end
group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"
gem 'annotate'

# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ GEM
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
annotate (3.2.0)
activerecord (>= 3.2, < 8.0)
rake (>= 10.4, < 14.0)
bindex (0.8.1)
bootsnap (1.10.3)
msgpack (~> 1.2)
Expand Down Expand Up @@ -206,6 +209,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
annotate
bootsnap
cssbundling-rails
debug
Expand Down
12 changes: 12 additions & 0 deletions app/models/amount_discount.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# == Schema Information
#
# Table name: promotion_codes
#
# id :bigint not null, primary key
# amount :decimal(8, 2) not null
# can_combine :boolean default(FALSE), not null
# code :string not null
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
class AmountDiscount < PromotionCode
end

8 changes: 8 additions & 0 deletions app/models/basket.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# == Schema Information
#
# Table name: baskets
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#
class Basket < ApplicationRecord
has_many :line_items, dependent: :destroy

Expand Down
21 changes: 21 additions & 0 deletions app/models/line_item.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# == Schema Information
#
# Table name: line_items
#
# id :bigint not null, primary key
# quantity :integer default(1), not null
# created_at :datetime not null
# updated_at :datetime not null
# basket_id :bigint not null
# product_id :bigint not null
#
# Indexes
#
# index_line_items_on_basket_id (basket_id)
# index_line_items_on_product_id (product_id)
#
# Foreign Keys
#
# fk_rails_... (basket_id => baskets.id)
# fk_rails_... (product_id => products.id)
#
class LineItem < ApplicationRecord
belongs_to :product
belongs_to :basket
Expand Down
12 changes: 12 additions & 0 deletions app/models/percent_discount.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# == Schema Information
#
# Table name: promotion_codes
#
# id :bigint not null, primary key
# amount :decimal(8, 2) not null
# can_combine :boolean default(FALSE), not null
# code :string not null
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
class PercentDiscount < PromotionCode
end

10 changes: 10 additions & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# == Schema Information
#
# Table name: products
#
# id :bigint not null, primary key
# name :string not null
# price :decimal(8, 2) not null
# created_at :datetime not null
# updated_at :datetime not null
#
class Product < ApplicationRecord
validates :name, presence: true
validates :price, numericality: { greater_than_or_equal_to: 0 }
Expand Down
12 changes: 12 additions & 0 deletions app/models/promotion_code.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# == Schema Information
#
# Table name: promotion_codes
#
# id :bigint not null, primary key
# amount :decimal(8, 2) not null
# can_combine :boolean default(FALSE), not null
# code :string not null
# type :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
class PromotionCode < ApplicationRecord
validates :code, presence: true
validates :type, presence: true, inclusion: { in: %w(PercentDiscount AmountDiscount) }
Expand Down
19 changes: 19 additions & 0 deletions app/models/quantity_discount.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# == Schema Information
#
# Table name: quantity_discounts
#
# id :bigint not null, primary key
# price :decimal(8, 2) not null
# quantity :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# product_id :bigint not null
#
# Indexes
#
# index_quantity_discounts_on_product_id (product_id)
#
# Foreign Keys
#
# fk_rails_... (product_id => products.id)
#
class QuantityDiscount < ApplicationRecord
belongs_to :product

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
10 changes: 10 additions & 0 deletions spec/fixtures/products.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# == Schema Information
#
# Table name: products
#
# id :bigint not null, primary key
# name :string not null
# price :decimal(8, 2) not null
# created_at :datetime not null
# updated_at :datetime not null
#
smart_hub:
name: Smart Hub
price: 49.99
Expand Down
8 changes: 8 additions & 0 deletions spec/models/basket_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# == Schema Information
#
# Table name: baskets
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#
require 'rails_helper'

RSpec.describe Basket, type: :model do
Expand Down

0 comments on commit 11d120a

Please sign in to comment.