source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/media_character.rb | Ruby | apache-2.0 | 187 | the-future | 449 | class MediaCharacter < ApplicationRecord
enum role: %i[main supporting recurring cameo]
belongs_to :media, polymorphic: true, inverse_of: :characters
belongs_to :character, inverse_of: :media_characters
has_many :voices, class_name: 'CharacterVoice', inverse_of: :media_character
accepts_nested_attributes_for... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/library_entry.rb | Ruby | apache-2.0 | 187 | the-future | 6,857 | # frozen_string_literal: true
class LibraryEntry < ApplicationRecord
VALID_RATINGS = (2..20).to_a.freeze
MEDIA_ASSOCIATIONS = %i[anime manga drama].freeze
belongs_to :user
belongs_to :media, polymorphic: true
belongs_to :anime, optional: true
belongs_to :manga, optional: true
belongs_to :drama, optional... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/group_category.rb | Ruby | apache-2.0 | 187 | the-future | 320 | class GroupCategory < ApplicationRecord
include Sluggable
include DescriptionSanitation
friendly_id :name, use: %i[slugged finders history]
has_many :groups, foreign_key: 'category_id'
before_destroy do
misc = GroupCategory.where(slug: 'misc').first
groups.update_all(category_id: misc.id)
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/anime_character.rb | Ruby | apache-2.0 | 187 | the-future | 225 | class AnimeCharacter < ApplicationRecord
enum role: %i[main supporting]
belongs_to :anime, required: true
belongs_to :character, required: true
has_many :castings, class_name: 'AnimeCasting', dependent: :destroy
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/community_recommendation_follow.rb | Ruby | apache-2.0 | 187 | the-future | 453 | class CommunityRecommendationFollow < ApplicationRecord
belongs_to :user, required: true
belongs_to :community_recommendation_request, required: true
scope :for_request, ->(request) { where(community_recommendation_request: request) }
after_create do
user.notifications.follow(community_recommendation_requ... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/profile_link_site.rb | Ruby | apache-2.0 | 187 | the-future | 208 | class ProfileLinkSite < ApplicationRecord
validates_presence_of :name, :validate_find, :validate_replace
def validate_find
Regexp.new(self[:validate_find]) unless self[:validate_find].nil?
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/titles_list.rb | Ruby | apache-2.0 | 187 | the-future | 4,121 | # frozen_string_literal: true
# Encapsulates the title logic for a Media, making it much easier to work with.
class TitlesList
# @param titles [{Symbol, String => String}] the titles in various locales
# @param canonical_locale [Symbol, String] the key of the canonical title in the titles hash
# @param original_... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/streamer.rb | Ruby | apache-2.0 | 187 | the-future | 356 | # frozen_string_literal: true
class Streamer < ApplicationRecord
has_many :streaming_links
has_many :videos
validates :site_name, presence: true
scope :by_name, ->(*names) { where('lower(site_name) IN (?)', names.flatten.map(&:downcase)) }
def self.find_by_name(name)
Streamer.where('lower(site_name) =... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/library_entry_log.rb | Ruby | apache-2.0 | 187 | the-future | 1,078 | class LibraryEntryLog < ApplicationRecord
belongs_to :linked_account, required: true
belongs_to :media, polymorphic: true, required: true
enum sync_status: %i[pending success error]
enum status: LibraryEntry.statuses
validates_presence_of :action_performed, :sync_status
def self.create_for(method, librar... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/repost.rb | Ruby | apache-2.0 | 187 | the-future | 292 | class Repost < ApplicationRecord
include WithActivity
belongs_to :user, required: true
belongs_to :post, required: true
def stream_activity
user.profile_feed.activities.new(
object: post,
nsfw: post.nsfw,
foreign_id: self,
verb: 'repost'
)
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/stat.rb | Ruby | apache-2.0 | 187 | the-future | 1,215 | class Stat < ApplicationRecord
belongs_to :user
validates :type, presence: true, uniqueness: { scope: :user_id }
# Gets a user-specific instance of a stat, automatically generating it if it doesn't exist.
# @return [Stat] the Stat for a user
def self.for_user(user)
Retriable.retriable(on: {
Active... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/user_ip_address.rb | Ruby | apache-2.0 | 187 | the-future | 358 | # frozen_string_literal: true
class UserIPAddress < ApplicationRecord
belongs_to :user, optional: false
validates :ip_address, presence: true
def asn
IPASN.find_by('start_ip <= ? AND end_ip >= ?', ip_address.to_s, ip_address.to_s)
end
def city
IPCity.find_by('start_ip <= ? AND end_ip >= ?', ip_add... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/wordfilter.rb | Ruby | apache-2.0 | 187 | the-future | 795 | # frozen_string_literal: true
class Wordfilter < ApplicationRecord
flag :locations, %i[post comment reaction]
enum action: {
censor: 10,
report: 20,
hold: 25,
hide: 30,
reject: 40
}, _prefix: 'action_'
validates :pattern, presence: true
before_validation do
self.pattern = pattern&.u... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/feed/activity_list.rb | Ruby | apache-2.0 | 187 | the-future | 6,094 | class Feed
class ActivityList
attr_accessor :data, :feed, :including, :limit_ratio
delegate :client, to: :feed
%i[limit offset ranking mark_read mark_seen].each do |key|
define_method(key) do |value|
data[key] = value
self
end
end
def initialize(feed, data = {})
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/feed/activity_group.rb | Ruby | apache-2.0 | 187 | the-future | 515 | class Feed
class ActivityGroup < OpenStruct
attr_reader :feed
def initialize(feed, data = {})
@feed = feed
data = data.symbolize_keys
data[:activities] = data[:activities]&.map do |activity|
Feed::Activity.new(feed, activity)
end
super(data)
end
def empty?
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/feed/activity.rb | Ruby | apache-2.0 | 187 | the-future | 1,189 | class Feed
class Activity < OpenStruct
attr_reader :feed
def initialize(feed, data = {})
@feed = feed
data = data.symbolize_keys
data[:time] = Time.iso8601(data[:time]) if data[:time].is_a? String
data[:object] = data[:subject] unless data.key?(:object)
super(data)
end
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/feed/notification_presenter.rb | Ruby | apache-2.0 | 187 | the-future | 4,981 | # frozen_string_literal: true
class Feed
# Encapsulates the generation of text from a Stream notification
class NotificationPresenter
# The base URL used when constructing links to notifications
CLIENT_URL = 'https://kitsu.app/'
attr_reader :activity, :user
delegate :group, to: :activity
dele... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/feed/activity_list/page.rb | Ruby | apache-2.0 | 187 | the-future | 4,367 | class Feed
class ActivityList
class Page
# Verbs which get their groups stripped to one activity
STRIPPED_VERBS = Set.new(%w[post comment follow review media_reaction]).freeze
attr_reader :opts, :data
# @param data a raw chunk of payload data from Stream's API
# @param opts the opt... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/feed/activity_list/fetcher.rb | Ruby | apache-2.0 | 187 | the-future | 3,333 | # frozen_string_literal: true
class Feed
class ActivityList
class Fetcher
attr_reader :stream_options, :fetcher_options, :unread_count, :unseen_count
def initialize(stream_options: {}, fetcher_options: {})
@stream_options = stream_options.deep_symbolize_keys
@fetcher_options = fetche... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/episodic.rb | Ruby | apache-2.0 | 187 | the-future | 1,538 | # frozen_string_literal: true
module Episodic
extend ActiveSupport::Concern
def recalculate_episode_length!
# Try for the statistical mode (most common value) of episode lengths
length, num = episodes.length_mode.values_at(:mode, :count)
# use length if num is nil
update(episode_length: length) i... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/titleable.rb | Ruby | apache-2.0 | 187 | the-future | 1,208 | module Titleable
extend ActiveSupport::Concern
included do
with_options if: ->(obj) { obj.titles.present? } do
validates :canonical_title, presence: true
validates :romanized_title, presence: true, if: :romanized_title_key
validates :original_title, presence: true, if: :original_title_key
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/media.rb | Ruby | apache-2.0 | 187 | the-future | 5,444 | module Media
extend ActiveSupport::Concern
STATUSES = %w[tba unreleased upcoming current finished].freeze
included do
include Titleable
include Rateable
include Rankable
include Trendable
include Sluggable
include Mappable
include DescriptionSanitation
include PosterImageUploader... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/holdable.rb | Ruby | apache-2.0 | 187 | the-future | 324 | # frozen_string_literal: true
# Allows a record to be held for manual moderator approval.
module Holdable
extend ActiveSupport::Concern
included do
enum held_reason: { spamfilter: 1, wordfilter: 2 }
scope :not_held, -> { where(held_reason: nil) }
scope :held, -> { where.not(held_reason: nil) }
end
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/localizable_model.rb | Ruby | apache-2.0 | 187 | the-future | 320 | module LocalizableModel
extend ActiveSupport::Concern
class_methods do
def localized_attr(name)
name = name.to_s
validate do
if attributes[name].keys.any? { |k| k.start_with?('en') }
errors.add(name, 'must have at least one English entry')
end
end
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/rankable.rb | Ruby | apache-2.0 | 187 | the-future | 497 | module Rankable
DEFAULT_RANKINGS = {
popularity_rank: :user_count,
rating_rank: :average_rating
}.freeze
extend ActiveSupport::Concern
class_methods do
def update_rankings(rankings = DEFAULT_RANKINGS)
rankings.each do |output_column, sort_column|
ids = where.not(sort_column => nil).o... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/rateable.rb | Ruby | apache-2.0 | 187 | the-future | 2,934 | module Rateable
extend ActiveSupport::Concern
MIN_RATINGS = 50
included do
validates :average_rating, numericality: {
less_than_or_equal_to: 100,
greater_than: 0
}, allow_nil: true
end
def calculate_rating_frequencies
base = LibraryEntry::VALID_RATINGS.map { |r| [r, 0] }.to_h
fre... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/retrieve_media.rb | Ruby | apache-2.0 | 187 | the-future | 228 | module RetrieveMedia
extend ActiveSupport::Concern
included do
before_validation do
self.media = retrieve_media
end
end
def retrieve_media
anime.presence || manga.presence || drama.presence
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/with_activity.rb | Ruby | apache-2.0 | 187 | the-future | 758 | module WithActivity
extend ActiveSupport::Concern
included do
after_commit ->(obj) {
real_action = obj.try(:deleted_at).nil? ? :update : :destroy
obj.complete_stream_activity.try(real_action)
}, on: :update
after_commit ->(obj) { obj.complete_stream_activity&.create }, on: :create
after... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/age_ratings.rb | Ruby | apache-2.0 | 187 | the-future | 566 | module AgeRatings
extend ActiveSupport::Concern
AGE_RATINGS = %i[G PG R R18].freeze
SAFE_AGE_RATINGS = %w[G PG R].freeze
UNSAFE_AGE_RATINGS = %w[R18].freeze
# SFW-ness is whitelist, not blacklist
def sfw?
age_rating.in?(SAFE_AGE_RATINGS) || age_rating.nil?
end
def nsfw?
!sfw?
end
include... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/unit.rb | Ruby | apache-2.0 | 187 | the-future | 342 | # frozen_string_literal: true
module Unit
extend ActiveSupport::Concern
included do
include Titleable
include Mappable
include UnitThumbnailUploader::Attachment(:thumbnail)
include DescriptionSanitation
validates :number, presence: true
enum status: {
autogenerated: 0,
validat... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/content_embeddable.rb | Ruby | apache-2.0 | 187 | the-future | 255 | module ContentEmbeddable
extend ActiveSupport::Concern
class_methods do
def embed_links_in(content_attr, to:)
attr_accessor :"#{to}_url"
EmbedLinkCallbacks.with_options(content_attr: content_attr, to: to).hook(self)
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/with_moderation_scores.rb | Ruby | apache-2.0 | 187 | the-future | 690 | # frozen_string_literal: true
module WithModerationScores
extend ActiveSupport::Concern
def update_moderation_scores(scores:, **kwargs)
# Update using update_all to do it all as a single UPDATE call
self.class.where(id:).update_all( # rubocop:disable Rails/SkipsModelValidations
updated_at: Time.now,... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/content_processable.rb | Ruby | apache-2.0 | 187 | the-future | 898 | module ContentProcessable
extend ActiveSupport::Concern
class_methods do
def processable(column, pipeline)
processed_column = "processed_#{column}"
memoized = "@#{processed_column}"
define_method(processed_column) do
existing_value = instance_variable_get(memoized)
return exi... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/trendable.rb | Ruby | apache-2.0 | 187 | the-future | 395 | module Trendable
extend ActiveSupport::Concern
def trending_service(user = nil)
TrendingService.new(self.class, user: user)
end
def trending(limit = 5)
trending_service.get(limit)
end
def trending_in_network(user, limit = 5)
trending_service(user).get_network(limit)
end
def trending_vote... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/description_sanitation.rb | Ruby | apache-2.0 | 187 | the-future | 287 | module DescriptionSanitation
extend ActiveSupport::Concern
included do
before_save :sanitize_description
end
def sanitize_description
return unless description
description.transform_values! { |desc| Sanitize.fragment(desc, Sanitize::Config::RESTRICTED) }
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/sluggable.rb | Ruby | apache-2.0 | 187 | the-future | 565 | module Sluggable
extend ActiveSupport::Concern
included do
extend FriendlyId
before_save do
# Force to nil
self.slug = nil if slug.blank?
end
end
class_methods do
# HACK: we need to return a relation but want to handle historical slugs
def by_slug(slug)
record = where(sl... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/streamable.rb | Ruby | apache-2.0 | 187 | the-future | 1,084 | # frozen_string_literal: true
module Streamable
extend ActiveSupport::Concern
included do
belongs_to :streamer, optional: false
validates :streamer, presence: true
validates :dubs, presence: true
validates :regions, length: { minimum: 1 }
scope :dubbed, ->(langs) { where('dubs @> ARRAY[?]::v... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/stat/category_breakdown.rb | Ruby | apache-2.0 | 187 | the-future | 3,032 | class Stat < ApplicationRecord
# Provides a base for both the anime and manga category breakdowns, so that most of the code can
# be shared. In future, as we move towards a larger set of media types, this will be helpful.
module CategoryBreakdown
extend ActiveSupport::Concern
# The default stats_data va... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/stat/favorite_year.rb | Ruby | apache-2.0 | 187 | the-future | 2,583 | class Stat < ApplicationRecord
module FavoriteYear
extend ActiveSupport::Concern
DEFAULT_STATS = {
'total' => 0,
'total_media' => 0,
'all_years' => {}
}.freeze
def recalculate!
years = library_entries.group("date_part('year', #{media_start_date})::integer").count
# cle... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/stat/activity_history.rb | Ruby | apache-2.0 | 187 | the-future | 1,899 | class Stat < ApplicationRecord
module ActivityHistory
extend ActiveSupport::Concern
def default_data
{
'days' => {},
'first' => user.created_at,
'last' => user.created_at
}
end
def recalculate!
self.stats_data = {}
date_trunc = "date_trunc('day', libr... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/stat/amount_consumed.rb | Ruby | apache-2.0 | 187 | the-future | 3,494 | class Stat < ApplicationRecord
# A common base for both the anime and manga amount-consumed stats. In future, as we add more
# media types, this is gonna be handy.
module AmountConsumed
extend ActiveSupport::Concern
# The default stats_data values, automatically handled by the Stat superclass
def de... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/concerns/global_stat/amount_consumed.rb | Ruby | apache-2.0 | 187 | the-future | 1,618 | # frozen_string_literal: true
class GlobalStat < ApplicationRecord
module AmountConsumed
extend ActiveSupport::Concern
class_methods do
delegate :recalculate!, to: :first_or_initialize
end
def recalculate!
update(stats_data: {
'percentiles' => {
'media' => percentiles_... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/list_import/my_anime_list_xml.rb | Ruby | apache-2.0 | 187 | the-future | 924 | class ListImport
class MyAnimeListXML < ListImport
include MALXMLUploader::Attachment(:input_file)
# We need an input file for XML importing
validates :input_text, absence: true
validates :input_file, presence: true
def count
xml.css('anime, manga').count
end
def each
xml.cs... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/list_import/my_anime_list.rb | Ruby | apache-2.0 | 187 | the-future | 2,237 | class ListImport
class MyAnimeList < ListImport
class ResponseError < StandardError; end
class RateLimitedError < ResponseError; end
MAL_HOST = 'https://myanimelist.net'.freeze
# Only accept usernames, not XML exports
validates :input_text, presence: true
validates :input_file_data, absence:... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/list_import/aozora.rb | Ruby | apache-2.0 | 187 | the-future | 650 | class ListImport
class Aozora < ListImport
validates :input_text, presence: true
validates :input_file_data, absence: true
def count
::Zorro::DB::AnimeProgress.count(for_user)
end
def each
::Zorro::DB::AnimeProgress.find(for_user).each do |entry|
row = Row.new(entry)
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/list_import/taiga_xml.rb | Ruby | apache-2.0 | 187 | the-future | 399 | class ListImport
class TaigaXML < ListImport
validates :input_text, absence: true
def count
xml.css('library anime').count
end
def each
xml.css('library anime').each do |anime|
row = Row.new(anime)
yield row.media, row.data
end
end
private
def xml
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/list_import/anilist.rb | Ruby | apache-2.0 | 187 | the-future | 3,213 | # frozen_string_literal: true
class ListImport
class Anilist < ListImport
ANILIST_API = 'https://graphql.anilist.co'
MEDIA_LIST_QUERY = <<-GRAPHQL
query($user_name: String) {
anime: MediaListCollection(userName: $user_name, type: ANIME) {
lists {
name
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/list_import/anime_planet.rb | Ruby | apache-2.0 | 187 | the-future | 1,977 | class ListImport
class AnimePlanet < ListImport
ANIME_PLANET_HOST = "http://#{ENV['ANIME_PLANET_PROXY_HOST']}/users/".freeze
# accepts a username as input
validates :input_text, length: {
minimum: 3,
maximum: 20
}, presence: true
# does not accept file uploads
validates :input_fil... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/list_import/anilist/row.rb | Ruby | apache-2.0 | 187 | the-future | 3,125 | # frozen_string_literal: true
class ListImport
class Anilist
class Row
def initialize(node, type)
@node = node
@type = type.to_s.downcase # anime | manga
end
def media
return anilist_mapping if anilist_mapping.present?
if mal_mapping.present?
Mapping.... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/list_import/taiga_xml/row.rb | Ruby | apache-2.0 | 187 | the-future | 1,392 | class ListImport
class TaigaXML
class Row
attr_reader :node
def initialize(node)
@node = node
end
def media
Mapping.lookup('myanimelist/anime', mal_id)
end
def mal_id
node.at_css('id').content.to_i
end
def status
case node.at_css(... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/list_import/anime_planet/row.rb | Ruby | apache-2.0 | 187 | the-future | 3,505 | class ListImport
class AnimePlanet
class Row
attr_reader :node, :type
def initialize(node, type)
@node = node
@type = type
end
def media
return @media if @media
key = "#{type}/#{media_info[:id]}"
@media = Mapping.lookup('animeplanet', key) ||
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/list_import/my_anime_list/row.rb | Ruby | apache-2.0 | 187 | the-future | 1,924 | class ListImport
class MyAnimeList
class Row
attr_reader :obj
def initialize(obj, date_format)
@obj = obj.deep_symbolize_keys
@date_format = date_format
end
def type
@type ||= if obj.key? :anime_title then :anime
elsif obj.key? :manga_title then ... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/list_import/my_anime_list_xml/row.rb | Ruby | apache-2.0 | 187 | the-future | 2,568 | class ListImport
class MyAnimeListXML
class Row
attr_reader :node
def initialize(node)
raise "Invalid type #{node.name}" unless node.name.in? %w[anime manga]
@node = node
end
def type
node.name.classify.safe_constantize
end
def media
key = "my... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/list_import/aozora/row.rb | Ruby | apache-2.0 | 187 | the-future | 996 | class ListImport
class Aozora
class Row
attr_reader :entry
def initialize(entry)
@entry = entry
end
def media
Anime.find_by_mapping('aozora', entry['_p_anime'].split('$').last)
end
def status
case entry['list']
when 'Watching' then :current
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/stat/manga_amount_consumed.rb | Ruby | apache-2.0 | 187 | the-future | 282 | class Stat < ApplicationRecord
class MangaAmountConsumed < Stat
include Stat::AmountConsumed
def media_kind
:manga
end
def unit_kind
:chapter
end
def global_stat
@global_stat ||= GlobalStat::MangaAmountConsumed.first
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/stat/manga_favorite_year.rb | Ruby | apache-2.0 | 187 | the-future | 300 | class Stat < ApplicationRecord
class MangaFavoriteYear < Stat
include Stat::FavoriteYear
# recalculate
def media_column
:manga
end
def media_start_date
'manga.start_date'
end
# increment & decrement
def self.media_type
'Manga'
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/stat/anime_amount_consumed.rb | Ruby | apache-2.0 | 187 | the-future | 282 | class Stat < ApplicationRecord
class AnimeAmountConsumed < Stat
include Stat::AmountConsumed
def media_kind
:anime
end
def unit_kind
:episode
end
def global_stat
@global_stat ||= GlobalStat::AnimeAmountConsumed.first
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/stat/anime_favorite_year.rb | Ruby | apache-2.0 | 187 | the-future | 300 | class Stat < ApplicationRecord
class AnimeFavoriteYear < Stat
include Stat::FavoriteYear
# recalculate
def media_column
:anime
end
def media_start_date
'anime.start_date'
end
# increment & decrement
def self.media_type
'Anime'
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/pro_subscription/google_play_subscription.rb | Ruby | apache-2.0 | 187 | the-future | 317 | class ProSubscription
class GooglePlaySubscription < ProSubscription
def billing_service
:google_play
end
def service
@service ||= GooglePlaySubscriptionService.new(billing_id, tier)
end
alias_method :cancel!, :destroy!
after_destroy do
service.cancel
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/pro_subscription/stripe_subscription.rb | Ruby | apache-2.0 | 187 | the-future | 510 | class ProSubscription
class StripeSubscription < ProSubscription
def billing_service
:stripe
end
def subscription
@subscription ||= Stripe::Subscription.retrieve(billing_id)
end
alias_method :cancel!, :destroy!
after_destroy do
subscription.delete
end
before_valid... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/linked_account/my_anime_list.rb | Ruby | apache-2.0 | 187 | the-future | 452 | class LinkedAccount
class MyAnimeList < LinkedAccount
validate :verify_mal_credentials, if: :token_changed?
def verify_mal_credentials
errors.add(:token, 'Username or password was incorrect.') unless list_sync.logged_in?
end
def list_sync
@list_sync ||= ListSync::MyAnimeList.new(self)
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/models/linked_account/youtube_channel.rb | Ruby | apache-2.0 | 187 | the-future | 846 | class LinkedAccount
class YoutubeChannel < LinkedAccount
def client
@client ||= YoutubeService::Client.new(token)
end
def subscription
@subscription ||= YoutubeService::Subscription.new(self)
end
delegate :topic_url, to: :subscription
before_validation do
self.external_user... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/shrine_derivative_worker.rb | Ruby | apache-2.0 | 187 | the-future | 638 | class ShrineDerivativeWorker
include Sidekiq::Worker
def self.perform_async(attacher)
super(
attacher.class.name,
attacher.record.to_global_id.to_s,
attacher.name.to_s,
attacher.file_data
)
end
def perform(attacher_class, record, name, file_data)
attacher_class = attacher_c... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/airing_notification_send_worker.rb | Ruby | apache-2.0 | 187 | the-future | 451 | class AiringNotificationSendWorker
include Sidekiq::Worker
def perform(kind, id)
media = kind.safe_constantize.find(id)
number = media.release_schedule.occurrences_between(
media.start_date - 1.week,
6.hours.ago
).count + 1
unit = media.unit(number)
media.airing_feed.activities.new... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/airing_notification_schedule_worker.rb | Ruby | apache-2.0 | 187 | the-future | 481 | class AiringNotificationScheduleWorker
include Sidekiq::Worker
def perform(klass_name)
return unless Flipper.enabled?(:airing_notifications)
klass = klass_name.safe_constantize
klass.current.where.not(release_schedule: nil).each do |media|
airings = media.release_schedule.occurrences_between(Tim... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/spamfilter_worker.rb | Ruby | apache-2.0 | 187 | the-future | 647 | # frozen_string_literal: true
class SpamfilterWorker
include Sidekiq::Worker
def self.perform_async(record, content_field:)
super(
record.to_global_id.to_s,
content_field.to_s
)
end
def perform(record, content_field)
record = GlobalID::Locator.locate(record)
spamfilter = Spamfilt... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/stat_worker.rb | Ruby | apache-2.0 | 187 | the-future | 1,989 | # frozen_string_literal: true
class StatWorker
include Sidekiq::Worker
# @param stat [String] the class name of the stat to act upon
# @param user_id [Integer] the ID of the user whose stat we are modifying
# @param action ['update','create','destroy'] the action to perform
# @param model [Hash] the model d... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/global_stat_recalculation_worker.rb | Ruby | apache-2.0 | 187 | the-future | 218 | class GlobalStatRecalculationWorker
include Sidekiq::Worker
sidekiq_options queue: 'later'
def perform
GlobalStat::AnimeAmountConsumed.recalculate!
GlobalStat::MangaAmountConsumed.recalculate!
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/trending_fanout_worker.rb | Ruby | apache-2.0 | 187 | the-future | 463 | class TrendingFanoutWorker
include Sidekiq::Worker
# Since we don't currently display network trending on site, this is a very low priority.
sidekiq_options queue: 'eventually'
def perform(namespace, half_life, user, id, weight)
user = User.find_by(id: user)
return unless user
namespace = namespace... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/group_unread_fanout_worker.rb | Ruby | apache-2.0 | 187 | the-future | 343 | class GroupUnreadFanoutWorker
include Sidekiq::Worker
sidekiq_options queue: 'soon'
def perform(group_id, source_user_id = nil)
group = Group.find(group_id)
source_user = User.find(source_user_id) if source_user_id
group.update(last_activity_at: Time.now)
GroupUnreadFanoutService.new(group, sourc... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/community_recommendation_reason_worker.rb | Ruby | apache-2.0 | 187 | the-future | 222 | class CommunityRecommendationReasonWorker
include Sidekiq::Worker
sidekiq_options queue: 'soon'
def perform(post, community_recommendation)
community_recommendation.send_community_recommendation(post)
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/list_import_worker.rb | Ruby | apache-2.0 | 187 | the-future | 230 | class ListImportWorker
include Sidekiq::Worker
sidekiq_options queue: 'now'
def perform(import_id)
import = ListImport.find_by(id: import_id)
return if import == ListImport::MyAnimeList
import&.apply!
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/update_rating_frequency_worker.rb | Ruby | apache-2.0 | 187 | the-future | 511 | class UpdateRatingFrequencyWorker
include Sidekiq::Worker
sidekiq_options queue: 'soon'
def perform(klass_name, klass_id, rating, diff)
update_query = <<-EOF
rating_frequencies = rating_frequencies
|| hstore('#{rating}', (
COALESCE(rating_frequencies->'#{rating}', '0')::integer + #{di... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/activity_deletion_worker.rb | Ruby | apache-2.0 | 187 | the-future | 326 | class ActivityDeletionWorker
include Sidekiq::Worker
sidekiq_options queue: 'now'
# activities is a structure of [[['user', '5554'], { foreign_id: 'repost:1234' }], ...]
def perform(activities)
activities.each do |((group, id), activity)|
Feed.new(group, id).activities.destroy(*activity)
end
en... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/destruction_worker.rb | Ruby | apache-2.0 | 187 | the-future | 245 | class DestructionWorker
include Sidekiq::Worker
sidekiq_options queue: 'soon'
def perform(klass, id)
klass.constantize.unscoped.find(id).destroy!
rescue ActiveRecord::RecordNotFound # rubocop:disable Lint/HandleExceptions
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/ama_starting_worker.rb | Ruby | apache-2.0 | 187 | the-future | 331 | class AMAStartingWorker
include Sidekiq::Worker
sidekiq_options queue: 'soon'
def self.perform_at(time, ama)
super(time, ama.to_global_id.to_s)
end
def self.perform_async(ama)
super(ama.to_global_id.to_s)
end
def perform(ama)
ama = GlobalID::Locator.locate(ama)
ama.send_ama_notification... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/user_content_reparent_worker.rb | Ruby | apache-2.0 | 187 | the-future | 383 | class UserContentReparentWorker
include Sidekiq::Worker
def perform(source_id, target_id)
Post.where(user_id: source_id).update_all(user_id: target_id)
Comment.where(user_id: source_id).update_all(user_id: target_id)
PostLike.where(user_id: source_id).update_all(user_id: target_id)
CommentLike.wher... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/hulu_mapping_worker.rb | Ruby | apache-2.0 | 187 | the-future | 243 | class HuluMappingWorker
include Sidekiq::Worker
def perform
since = (Time.now - 24.hours).strftime('%F')
HuluImport::HuluSeries.each do |series|
series.episodes(since: since).each(&:video!) if series.media
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/getstream_event_worker.rb | Ruby | apache-2.0 | 187 | the-future | 484 | # frozen_string_literal: true
class GetstreamEventWorker
include Sidekiq::Worker
sidekiq_options queue: 'soon'
def perform(feed, event, activity)
group, id = feed.split(':')
feed = Feed.new(group, id)
case event
when 'new'
activity = Feed::Activity.new(feed, activity)
if group == 'n... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/buffered_stream_client/unfollow_buffer_flush_worker.rb | Ruby | apache-2.0 | 187 | the-future | 208 | class BufferedStreamClient
class UnfollowBufferFlushWorker
include Sidekiq::Worker
sidekiq_options queue: 'now', retry: false
def perform
UnfollowBuffer.new.flush_batch
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/buffered_stream_client/buffer_flush_worker.rb | Ruby | apache-2.0 | 187 | the-future | 282 | class BufferedStreamClient
class BufferFlushWorker
include Sidekiq::Worker
sidekiq_options queue: 'soon'
def perform(klass_name, queue)
klass = klass_name.safe_constantize
buffer = klass.new(queue)
buffer.flush(StreamRails.client)
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/buffered_stream_client/buffer_action_worker.rb | Ruby | apache-2.0 | 187 | the-future | 636 | class BufferedStreamClient
class BufferActionWorker
include Sidekiq::Worker
sidekiq_options queue: 'soon'
def perform(group, id, method, *parameters)
if method == 'unfollow'
target_group, target_id, options = parameters
return @buffer.unfollow_buffer.push(
options.merge(
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/buffered_stream_client/follow_buffer_flush_worker.rb | Ruby | apache-2.0 | 187 | the-future | 204 | class BufferedStreamClient
class FollowBufferFlushWorker
include Sidekiq::Worker
sidekiq_options queue: 'now', retry: false
def perform
FollowBuffer.new.flush_batch
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/list_sync/error_handling.rb | Ruby | apache-2.0 | 187 | the-future | 743 | module ListSync
module ErrorHandling
extend ActiveSupport::Concern
def capture_sync_errors(linked_account, pending_logs)
yield
rescue ListSync::NotFoundError
error! pending_logs, 'No equivalent'
rescue ListSync::AuthenticationError
linked_account.update!(sync_to: false, disabled_rea... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/list_sync/destroy_worker.rb | Ruby | apache-2.0 | 187 | the-future | 784 | module ListSync
class DestroyWorker
include Sidekiq::Worker
include ListSync::ErrorHandling
sidekiq_options retry: 3, queue: 'soon'
def perform(linked_account_id, media_type, media_id)
return if Rails.env.staging?
begin
linked_account = LinkedAccount.find(linked_account_id)
... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/list_sync/sync_worker.rb | Ruby | apache-2.0 | 187 | the-future | 816 | module ListSync
class SyncWorker
include Sidekiq::Worker
include ListSync::ErrorHandling
sidekiq_options retry: false, queue: 'soon', debounce: true
def perform(linked_account_id, user_id)
return if Rails.env.staging?
user = User.find(user_id)
linked_account = LinkedAccount.find(lin... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/list_sync/update_worker.rb | Ruby | apache-2.0 | 187 | the-future | 735 | module ListSync
class UpdateWorker
include Sidekiq::Worker
include ListSync::ErrorHandling
sidekiq_options retry: 3, queue: 'soon'
def perform(linked_account_id, library_entry_id)
return if Rails.env.staging?
begin
linked_account = LinkedAccount.find(linked_account_id)
lib... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/accounts/send_confirmation_email_worker.rb | Ruby | apache-2.0 | 187 | the-future | 341 | module Accounts
class SendConfirmationEmailWorker
include Sidekiq::Worker
sidekiq_options queue: 'now'
def perform(user_id)
user = User.find(user_id)
SendConfirmationEmail.call(user: user)
end
def self.perform_async(user)
user = user.id if user.respond_to?(:id)
super(use... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/workers/zorro/follow_import_worker.rb | Ruby | apache-2.0 | 187 | the-future | 230 | module Zorro
class FollowImportWorker
include Sidekiq::Worker
sidekiq_options queue: 'soon'
def perform(user_id)
user = User.find(user_id)
Zorro::Importer::FollowImporter.run_for(user)
end
end
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/indices/typesense_anime_index.rb | Ruby | apache-2.0 | 187 | the-future | 3,298 | # frozen_string_literal: true
class TypesenseAnimeIndex < TypesenseBaseIndex
SAVE_FREQUENCIES = {
'id' => 1,
'poster_image_data' => 1,
'titles' => 1,
'canonical_title' => 1,
'abbrevated_titles' => 1,
'description' => 1,
'total_length' => 1,
'episode_count' => 1,
'episode_length' =... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/indices/typesense_base_index.rb | Ruby | apache-2.0 | 187 | the-future | 754 | # frozen_string_literal: true
class TypesenseBaseIndex < Typesensual::Index
schema do
enable_nested_fields
field 'created_at', type: 'int32', optional: true
end
private
def format_date(date)
return { is_null: true } unless date
{
is_null: false,
year: date.year,
month: date... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/indices/algolia_media_index.rb | Ruby | apache-2.0 | 187 | the-future | 1,170 | class AlgoliaMediaIndex < BaseIndex
self.index_name = 'media'
# Titles & description
attributes :titles, :abbreviated_titles, :canonical_title, :description
# Properties of the media
attributes :age_rating, :subtype, :season, :year, :season_year, :interest
attributes :start_date, :end_date, format: Algoli... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/indices/base_index.rb | Ruby | apache-2.0 | 187 | the-future | 9,283 | # frozen_string_literal: true
class BaseIndex
class_attribute :_attributes, :_index, :_associations
attr_reader :_model, :_new, :_associated
class << self
def attribute(*names, frequency: nil, format: nil, method: nil)
self._attributes ||= []
self._attributes += names.map do |name|
{ nam... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/indices/algolia_characters_index.rb | Ruby | apache-2.0 | 187 | the-future | 459 | class AlgoliaCharactersIndex < BaseIndex
self.index_name = 'characters'
# Names & Bio
attributes :names, :canonical_name, :other_names, :description
# Display Only
attribute :slug
attribute :image, format: ShrineAttachmentValueFormatter, method: :image_attacher
has_many :media, via: 'media_characters.m... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/indices/algolia_users_index.rb | Ruby | apache-2.0 | 187 | the-future | 264 | class AlgoliaUsersIndex < BaseIndex
self.index_name = 'users'
attributes :name, :past_names, :slug, :title, :pro_expires_at
attribute :followers_count, frequency: 2.5
attribute :avatar, format: ShrineAttachmentValueFormatter, method: :avatar_attacher
end |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/indices/typesense_groups_index.rb | Ruby | apache-2.0 | 187 | the-future | 1,936 | # frozen_string_literal: true
class TypesenseGroupsIndex < TypesenseBaseIndex
SAVE_FREQUENCIES = {
'id' => 1,
'avatar_data' => 1,
'name' => 1,
'slug' => 1,
'tagline' => 1,
'about' => 1,
'locale' => 1,
'privacy' => 1,
'is_nsfw' => 1,
'members_count' => 0.1,
'last_activity_a... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/indices/typesense_users_index.rb | Ruby | apache-2.0 | 187 | the-future | 1,549 | # frozen_string_literal: true
class TypesenseUsersIndex < TypesenseBaseIndex
SAVE_FREQUENCIES = {
'id' => 1,
'avatar_data' => 1,
'name' => 1,
'past_names' => 1,
'slug' => 1,
'followers_count' => 0.025
}.freeze
index_name 'users'
schema do
field 'avatar_image', type: 'object', opti... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/indices/algolia_groups_index.rb | Ruby | apache-2.0 | 187 | the-future | 347 | class AlgoliaGroupsIndex < BaseIndex
self.index_name = 'groups'
attributes :name, :about, :locale, :tagline, :privacy, :nsfw, :slug
attribute :last_activity_at, frequency: 2.5
attribute :members_count, frequency: 10
attribute :avatar, format: ShrineAttachmentValueFormatter, method: :avatar_attacher
has_on... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/indices/typesense_manga_index.rb | Ruby | apache-2.0 | 187 | the-future | 2,014 | # frozen_string_literal: true
class TypesenseMangaIndex < TypesenseBaseIndex
SAVE_FREQUENCIES = {
'id' => 1,
'poster_image_data' => 1,
'titles' => 1,
'canonical_title' => 1,
'abbrevated_titles' => 1,
'description' => 1,
'chapter_count' => 1,
'volume_count' => 1,
'age_rating' => 1,... |
github | hummingbird-me/kitsu-server | https://github.com/hummingbird-me/kitsu-server | app/indices/concerns/typesense_media_index.rb | Ruby | apache-2.0 | 187 | the-future | 2,649 | # frozen_string_literal: true
module TypesenseMediaIndex
extend ActiveSupport::Concern
included do
schema do
token_separators(*%w[/ - ( ) + ; : & , .])
# Locale-specific strings
# Pulled from https://typesense.org/docs/0.24.0/api/collections.html#schema-parameters
field '.*\.ja-.*', t... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.