Skip to content

Instantly share code, notes, and snippets.

@tubbo
Forked from kitsuneyo/Terminal
Last active January 26, 2017 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tubbo/ce570c339645e366a9fb3470368bc138 to your computer and use it in GitHub Desktop.
Save tubbo/ce570c339645e366a9fb3470368bc138 to your computer and use it in GitHub Desktop.
# models/company/note.rb
class Company < ApplicationRecord
class Note < ::Note
alias_attribute :company_id, :article_id
alias_attribute :company, :article
# VALIDATIONS
COMPANY_NOTE_CATEGORIES = %w(
History Organisation Products Technology Significance
)
validates :category, inclusion: { in: COMPANY_NOTE_CATEGORIES }
end
end
# models/game/note.rb
require_dependency 'note'
module Game
class Note < ::Note
alias_attribute :game_id, :article_id
alias_attribute :game, :article
# VALIDATIONS
GAME_NOTE_CATEGORIES = %w(
Development Publishing Technology Sound Reception
)
validates :category, inclusion: { in: GAME_NOTE_CATEGORIES }
end
end
class Note < ApplicationRecord
# AUDIT
audited on: [:update, :destroy]
# RELATIONSHIPS
belongs_to :article
belongs_to :created_by, class_name: 'User'
# VALIDATIONS
VALID_NOTE_TYPES = %w(Game::Note Company::Note Person::Note)
validates :type, presence: true, inclusion: { in: VALID_NOTE_TYPES }
validates :category, presence: true
validates :body, presence: true, length: { minimum: 5, maximum: 2000 }
validates :cite_url, length: { minimum: 5, maximum: 250 }, allow_blank: true
validates :cite_title, length: { maximum: 250 }, allow_blank: true
validates :cite_website, length: { maximum: 100 }, allow_blank: true
end
# models/person/note.rb
class Person::Note < ApplicationRecord::Note
alias_attribute :person_id, :article_id
alias_attribute :person, :article
# VALIDATIONS
PERSON_NOTE_CATEGORIES = %w(
Personal Education Career Family Achievements
)
validates :category, inclusion: { in: PERSON_NOTE_CATEGORIES }
end
Game::Note.new
(irb):3: warning: toplevel constant Note referenced by Game::Note
=> #<Note id: nil, article_id: nil, type: nil, category: nil, body: nil, cite_url: nil, cite_title: nil, cite_website: nil, created_by_id: nil, created_at: nil, updated_at: nil>
# ^^ This is a new Note class object, not a Game::Note class object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment