Class: Category
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Category
- Defined in:
- app/models/category.rb
Overview
This model manage the categories of work’s risks
Relations
has many Audit has many CategoryRisk has many Risk through CategoryRisk has many User through Audit
Validations
-
validate presence of #title
-
validate uniqueness of #title
-
validate presence of #months
-
validate if #months is a Integer
Default scope
where active is true ordered by title
Instance Attribute Summary collapse
-
#active ⇒ Boolean
If category is active or not, can’t be Null, default True.
-
#code ⇒ String
Category code.
-
#created_at ⇒ Datetime
Date when the record was created.
-
#id ⇒ Integer
Is the unique identifier for Category.
-
#months ⇒ Integer
Periodicity of checks expressed in months, can’t be Null, default 0.
-
#protocol ⇒ String
Description of check required.
-
#title ⇒ String
Category Title, can’t be Null, default is an empty string.
-
#updated_at ⇒ Datetime
Date when the record was updated.
Instance Method Summary collapse
-
#audit ⇒ Array
Of Audit referenced from Audit#category_id.
-
#category_risks ⇒ Array
Of CategoryRisk referenced from CategoryRisk#category_id.
-
#check_destroy ⇒ Boolean
If category is unused and can be destroyed run Super, otherwise update for set active as false.
-
#delete ⇒ Object
for security reason is an alias of destroy.
-
#disabled ⇒ Array
Of disablec Category.
Methods inherited from ApplicationRecord
Instance Attribute Details
#active ⇒ Boolean
Returns if category is active or not, can’t be Null, default True.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/category.rb', line 43 class Category < ApplicationRecord has_many :audits, dependent: :restrict_with_exception has_many :category_risks, dependent: :restrict_with_exception has_many :risks, through: :category_risks has_many :users, through: :audits validates :title, presence: true, uniqueness: true validates :months, presence: true, numericality: { only_integer: true } default_scope { order('title asc').where(active: true) } scope :disabled, -> { unscoped.where(active: false) } before_destroy :check_destroy # for security reason is an alias of {destroy} def delete destroy end # @return [Boolean] if category is unused and can be destroyed run Super, otherwise update for set active as false. def check_destroy update(active: false) if users.present? || risks.present? false end end |
#code ⇒ String
Returns Category code.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/category.rb', line 43 class Category < ApplicationRecord has_many :audits, dependent: :restrict_with_exception has_many :category_risks, dependent: :restrict_with_exception has_many :risks, through: :category_risks has_many :users, through: :audits validates :title, presence: true, uniqueness: true validates :months, presence: true, numericality: { only_integer: true } default_scope { order('title asc').where(active: true) } scope :disabled, -> { unscoped.where(active: false) } before_destroy :check_destroy # for security reason is an alias of {destroy} def delete destroy end # @return [Boolean] if category is unused and can be destroyed run Super, otherwise update for set active as false. def check_destroy update(active: false) if users.present? || risks.present? false end end |
#created_at ⇒ Datetime
Returns date when the record was created.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/category.rb', line 43 class Category < ApplicationRecord has_many :audits, dependent: :restrict_with_exception has_many :category_risks, dependent: :restrict_with_exception has_many :risks, through: :category_risks has_many :users, through: :audits validates :title, presence: true, uniqueness: true validates :months, presence: true, numericality: { only_integer: true } default_scope { order('title asc').where(active: true) } scope :disabled, -> { unscoped.where(active: false) } before_destroy :check_destroy # for security reason is an alias of {destroy} def delete destroy end # @return [Boolean] if category is unused and can be destroyed run Super, otherwise update for set active as false. def check_destroy update(active: false) if users.present? || risks.present? false end end |
#id ⇒ Integer
Returns is the unique identifier for Category.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/category.rb', line 43 class Category < ApplicationRecord has_many :audits, dependent: :restrict_with_exception has_many :category_risks, dependent: :restrict_with_exception has_many :risks, through: :category_risks has_many :users, through: :audits validates :title, presence: true, uniqueness: true validates :months, presence: true, numericality: { only_integer: true } default_scope { order('title asc').where(active: true) } scope :disabled, -> { unscoped.where(active: false) } before_destroy :check_destroy # for security reason is an alias of {destroy} def delete destroy end # @return [Boolean] if category is unused and can be destroyed run Super, otherwise update for set active as false. def check_destroy update(active: false) if users.present? || risks.present? false end end |
#months ⇒ Integer
Returns periodicity of checks expressed in months, can’t be Null, default 0.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/category.rb', line 43 class Category < ApplicationRecord has_many :audits, dependent: :restrict_with_exception has_many :category_risks, dependent: :restrict_with_exception has_many :risks, through: :category_risks has_many :users, through: :audits validates :title, presence: true, uniqueness: true validates :months, presence: true, numericality: { only_integer: true } default_scope { order('title asc').where(active: true) } scope :disabled, -> { unscoped.where(active: false) } before_destroy :check_destroy # for security reason is an alias of {destroy} def delete destroy end # @return [Boolean] if category is unused and can be destroyed run Super, otherwise update for set active as false. def check_destroy update(active: false) if users.present? || risks.present? false end end |
#protocol ⇒ String
Returns description of check required.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/category.rb', line 43 class Category < ApplicationRecord has_many :audits, dependent: :restrict_with_exception has_many :category_risks, dependent: :restrict_with_exception has_many :risks, through: :category_risks has_many :users, through: :audits validates :title, presence: true, uniqueness: true validates :months, presence: true, numericality: { only_integer: true } default_scope { order('title asc').where(active: true) } scope :disabled, -> { unscoped.where(active: false) } before_destroy :check_destroy # for security reason is an alias of {destroy} def delete destroy end # @return [Boolean] if category is unused and can be destroyed run Super, otherwise update for set active as false. def check_destroy update(active: false) if users.present? || risks.present? false end end |
#title ⇒ String
Returns Category Title, can’t be Null, default is an empty string.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/category.rb', line 43 class Category < ApplicationRecord has_many :audits, dependent: :restrict_with_exception has_many :category_risks, dependent: :restrict_with_exception has_many :risks, through: :category_risks has_many :users, through: :audits validates :title, presence: true, uniqueness: true validates :months, presence: true, numericality: { only_integer: true } default_scope { order('title asc').where(active: true) } scope :disabled, -> { unscoped.where(active: false) } before_destroy :check_destroy # for security reason is an alias of {destroy} def delete destroy end # @return [Boolean] if category is unused and can be destroyed run Super, otherwise update for set active as false. def check_destroy update(active: false) if users.present? || risks.present? false end end |
#updated_at ⇒ Datetime
Returns date when the record was updated.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/category.rb', line 43 class Category < ApplicationRecord has_many :audits, dependent: :restrict_with_exception has_many :category_risks, dependent: :restrict_with_exception has_many :risks, through: :category_risks has_many :users, through: :audits validates :title, presence: true, uniqueness: true validates :months, presence: true, numericality: { only_integer: true } default_scope { order('title asc').where(active: true) } scope :disabled, -> { unscoped.where(active: false) } before_destroy :check_destroy # for security reason is an alias of {destroy} def delete destroy end # @return [Boolean] if category is unused and can be destroyed run Super, otherwise update for set active as false. def check_destroy update(active: false) if users.present? || risks.present? false end end |
Instance Method Details
#audit ⇒ Array
Returns of Audit referenced from Audit#category_id.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/category.rb', line 43 class Category < ApplicationRecord has_many :audits, dependent: :restrict_with_exception has_many :category_risks, dependent: :restrict_with_exception has_many :risks, through: :category_risks has_many :users, through: :audits validates :title, presence: true, uniqueness: true validates :months, presence: true, numericality: { only_integer: true } default_scope { order('title asc').where(active: true) } scope :disabled, -> { unscoped.where(active: false) } before_destroy :check_destroy # for security reason is an alias of {destroy} def delete destroy end # @return [Boolean] if category is unused and can be destroyed run Super, otherwise update for set active as false. def check_destroy update(active: false) if users.present? || risks.present? false end end |
#category_risks ⇒ Array
Returns of CategoryRisk referenced from CategoryRisk#category_id.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/category.rb', line 43 class Category < ApplicationRecord has_many :audits, dependent: :restrict_with_exception has_many :category_risks, dependent: :restrict_with_exception has_many :risks, through: :category_risks has_many :users, through: :audits validates :title, presence: true, uniqueness: true validates :months, presence: true, numericality: { only_integer: true } default_scope { order('title asc').where(active: true) } scope :disabled, -> { unscoped.where(active: false) } before_destroy :check_destroy # for security reason is an alias of {destroy} def delete destroy end # @return [Boolean] if category is unused and can be destroyed run Super, otherwise update for set active as false. def check_destroy update(active: false) if users.present? || risks.present? false end end |
#check_destroy ⇒ Boolean
Returns if category is unused and can be destroyed run Super, otherwise update for set active as false.
63 64 65 66 |
# File 'app/models/category.rb', line 63 def check_destroy update(active: false) if users.present? || risks.present? false end |
#delete ⇒ Object
for security reason is an alias of destroy
58 59 60 |
# File 'app/models/category.rb', line 58 def delete destroy end |
#disabled ⇒ Array
Returns of disablec Category.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/category.rb', line 43 class Category < ApplicationRecord has_many :audits, dependent: :restrict_with_exception has_many :category_risks, dependent: :restrict_with_exception has_many :risks, through: :category_risks has_many :users, through: :audits validates :title, presence: true, uniqueness: true validates :months, presence: true, numericality: { only_integer: true } default_scope { order('title asc').where(active: true) } scope :disabled, -> { unscoped.where(active: false) } before_destroy :check_destroy # for security reason is an alias of {destroy} def delete destroy end # @return [Boolean] if category is unused and can be destroyed run Super, otherwise update for set active as false. def check_destroy update(active: false) if users.present? || risks.present? false end end |