This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Validator { | |
static REQUIRED = "REQUIRED"; | |
static MIN_LENGTH = "MIN_LENGTH"; | |
static validate(value, flag, validatorValue) { | |
if (flag === this.REQUIRED) { | |
return value.trim().length > 0; | |
} | |
if (flag === this.MIN_LENGTH) { | |
return value.trim().length > validatorValue; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const REQUIRED = "REQUIRED"; | |
const MIN_LENGTH = "MIN_LENGTH"; | |
const validate = (value, flag, validatorValue) => { | |
if (flag === REQUIRED) { | |
return value.trim().length > 0; | |
} | |
if (flag === MIN_LENGTH) { | |
return value.trim().length > validatorValue; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Manifest < ActiveRecord::Base | |
validates :name, presence: true | |
validates :description, presence: true | |
def outdate | |
self.status = :outdated | |
end | |
def active? | |
self.status != :outdated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Manifest < ActiveRecord::Base | |
validates :name, presence: true | |
validates :description, presence: true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Assembly < ApplicationRecord | |
has_many :manifests | |
has_many :parts, through: :manifests | |
end | |
class Manifest < ApplicationRecord | |
belongs_to :assembly | |
belongs_to :part | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Assembly < ApplicationRecord | |
has_and_belongs_to_many :parts | |
end | |
class Part < ApplicationRecord | |
has_and_belongs_to_many :assemblies | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateReviews < ActiveRecord::Migration[6.0] | |
def change | |
create_table :reviews do |t| | |
t.references :reviewable, polymorphic: true, index: true | |
t.string :body | |
t.timestamps | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Review < ApplicationRecord | |
# name the interface to the Review model reviewable | |
# establish that it is polymorphic | |
belongs_to :reviewable, polymorphic: true | |
end | |
class Restaurant < ApplicationRecord | |
# establish a relationship to the Review model | |
# via the reviewable interface | |
has_many :reviews, as: :reviewable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
has_and_belongs_to_many :groups | |
end | |
class Group | |
has_and_belongs_to_many :users | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
has_one :profile | |
has_one :avatar, through: :profile | |
end | |
class Profile | |
belongs_to :user | |
has_one :avatar | |
end |