-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract generic Person and Credit base classes
- Loading branch information
Showing
15 changed files
with
83 additions
and
58 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class ActingCredit < Credit | ||
alias_attribute :character, :role | ||
|
||
def self.top_billing | ||
includes(:person).first(5) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,2 @@ | ||
class Actor < ApplicationRecord | ||
include PgSearch::Model | ||
pg_search_scope :pg_search, against: [:name], using: { tsearch: { prefix: true, tsvector_column: "tsv" } } | ||
|
||
has_many :credits | ||
|
||
scope :alphabetical, -> { order(name: :asc) } | ||
|
||
validates :name, presence: true | ||
validates :tmdb_id, uniqueness: { allow_blank: true } | ||
|
||
enum gender: { "Not specified" => 0, "Female" => 1, "Male" => 2, "Non-Binary" => 3 } | ||
|
||
def initials | ||
name.split.map(&:first).join | ||
end | ||
|
||
def profile? | ||
profile_path.present? | ||
end | ||
|
||
def profile_url(version="original") | ||
tmdb_image(profile_path, version) | ||
end | ||
class Actor < Person | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
class Credit < ApplicationRecord | ||
belongs_to :media, polymorphic: true | ||
belongs_to :actor | ||
belongs_to :person | ||
|
||
scope :ordered, -> { order(order: :asc) } | ||
scope :actors, -> { where(type: "ActingCredit") } | ||
|
||
delegate :name, :initials, :gender, :profile?, :profile_url, :profile_path, to: :actor, allow_nil: true | ||
|
||
def self.top_billing | ||
includes(:actor).first(5) | ||
end | ||
delegate :name, :initials, :gender, :profile?, :profile_url, :profile_path, to: :person, allow_nil: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class Person < ApplicationRecord | ||
include PgSearch::Model | ||
pg_search_scope :pg_search, against: [:name], using: { tsearch: { prefix: true, tsvector_column: "tsv" } } | ||
|
||
has_many :credits | ||
|
||
scope :alphabetical, -> { order(name: :asc) } | ||
|
||
validates :name, presence: true | ||
validates :tmdb_id, uniqueness: { allow_blank: true } | ||
|
||
enum gender: { "Not specified" => 0, "Female" => 1, "Male" => 2, "Non-Binary" => 3 } | ||
|
||
def initials | ||
name.split.map(&:first).join | ||
end | ||
|
||
def profile? | ||
profile_path.present? | ||
end | ||
|
||
def profile_url(version="original") | ||
tmdb_image(profile_path, version) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class ConvertActorsToPeople < ActiveRecord::Migration[5.2] | ||
def change | ||
rename_table :actors, :people | ||
add_column :people, :type, :string | ||
|
||
Person.update_all(type: "Actor") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class ConvertCreditsToPeople < ActiveRecord::Migration[5.2] | ||
def change | ||
rename_column :credits, :actor_id, :person_id | ||
rename_column :credits, :character, :role | ||
add_column :credits, :type, :string | ||
|
||
Credit.update_all(type: "ActingCredit") | ||
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