repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/api/v3/notifications_controller.rb | app/controllers/api/v3/notifications_controller.rb | module Api
module V3
class NotificationsController < Api::V3::ApplicationController
before_action :doorkeeper_authorize!
# 获取用户的通知列表
#
# GET /api/v3/notifications
#
# @param offset [Integer] default: 0
# @param limit [Integer] default: 20, range: 1..150
# @return [... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/api/v3/devices_controller.rb | app/controllers/api/v3/devices_controller.rb | module Api
module V3
class DevicesController < Api::V3::ApplicationController
before_action :doorkeeper_authorize!
before_action do
requires! :platform, type: String, values: %w[ios android]
requires! :token, type: String
end
# 记录用户 Device 信息,用于 Push 通知。
#
# P... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/api/v3/users_controller.rb | app/controllers/api/v3/users_controller.rb | module Api
module V3
class UsersController < Api::V3::ApplicationController
before_action :doorkeeper_authorize!, only: %i[me follow unfollow block unblock blocked]
before_action :set_user, except: %i[index me]
# Get Hot User List
#
# GET /api/v3/users
#
# @param limit [... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/api/v3/root_controller.rb | app/controllers/api/v3/root_controller.rb | module Api
module V3
class RootController < Api::V3::ApplicationController
before_action :doorkeeper_authorize!, only: [:hello]
def not_found
raise ActiveRecord::RecordNotFound
end
# 简单的 API 测试接口,需要验证,便于快速测试 OAuth 以及其他 API 的基本格式是否正确
#
# GET /api/v3/hello
#
... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/api/v3/replies_controller.rb | app/controllers/api/v3/replies_controller.rb | module Api
module V3
class RepliesController < Api::V3::ApplicationController
before_action :doorkeeper_authorize!, only: %i[update destroy]
before_action :set_reply, only: %i[show update destroy]
# 获取回帖的详细内容(一般用于编辑回帖的时候)
#
# GET /api/v3/replies/:id
# @return [ReplyDetailSeria... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/api/v3/photos_controller.rb | app/controllers/api/v3/photos_controller.rb | module Api
module V3
class PhotosController < Api::V3::ApplicationController
before_action :doorkeeper_authorize!
# 上传图片,请使用 Multipart 的方式提交图片文件
#
# POST /api/v3/photos
#
# @param file - 文件信息,[required]
#
# == returns
# - image_url 图片 URL
def create
... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/api/v3/nodes_controller.rb | app/controllers/api/v3/nodes_controller.rb | module Api
module V3
class NodesController < Api::V3::ApplicationController
# 获取 Nodes 列表
#
# GET /api/v3/nodes
# @return [Array<NodeSerializer>]
def index
@nodes = Node.sorted.all
@meta = { total: Node.count }
end
##
# 获取单个 Node 详情
#
# ... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/api/v3/likes_controller.rb | app/controllers/api/v3/likes_controller.rb | module Api
module V3
class LikesController < Api::V3::ApplicationController
before_action :doorkeeper_authorize!
before_action do
requires! :obj_type, values: %w[topic reply]
requires! :obj_id
end
# 赞一个信息
#
# POST /api/v3/likes
#
# @param obj_type ... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/api/v3/application_controller.rb | app/controllers/api/v3/application_controller.rb | module Api
module V3
# @abstract
# FIXME: change to ActionController::API after jbuilder fix for Rails 5.2
class ApplicationController < ActionController::Base
include ActionController::Caching
include ActionView::Helpers::OutputSafetyHelper
include ActionView::Helpers::SanitizeHelper
... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/oauth/applications_controller.rb | app/controllers/oauth/applications_controller.rb | module Oauth
class ApplicationsController < Doorkeeper::ApplicationsController
before_action :authenticate_user!
include Homeland::UserNotificationHelper
before_action :set_application, only: %i[show edit update destroy]
def index
@applications = current_user.oauth_applications
@authoriz... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/oauth/authorized_applications_controller.rb | app/controllers/oauth/authorized_applications_controller.rb | module Oauth
class AuthorizedApplicationsController < Doorkeeper::ApplicationController
before_action :authenticate_resource_owner!
def destroy
Doorkeeper::AccessToken.revoke_all_for params[:id].to_i, current_resource_owner
redirect_to oauth_applications_url, notice: I18n.t(:notice, scope: %i[doo... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/users/omniauth_callbacks_controller.rb | app/controllers/users/omniauth_callbacks_controller.rb | class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
User.omniauth_providers.each do |provider|
send(:define_method, provider) do
process_callback
end
end
def failure
set_flash_message! :alert, :failure, kind: Homeland::Utils.omniauth_name(failed_strategy.name), reason... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/users/passwords_controller.rb | app/controllers/users/passwords_controller.rb | class Users::PasswordsController < Devise::PasswordsController
before_action :require_no_sso!
def create
self.resource = resource_class.new(resource_params.permit(:email))
unless verify_complex_captcha?(resource)
return render "devise/passwords/new"
end
self.resource = resource_class.find_or... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/users/user_actions.rb | app/controllers/users/user_actions.rb | module Users
module UserActions
extend ActiveSupport::Concern
included do
before_action :authenticate_user!, only: %i[block unblock blocked follow unfollow]
before_action :only_user!, only: %i[topics replies favorites
block unblock follow unfollow
followers following reward]
e... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/users/registrations_controller.rb | app/controllers/users/registrations_controller.rb | class Users::RegistrationsController < Devise::RegistrationsController
before_action :require_no_sso!, only: %i[new create]
# POST /resource
def create
cache_key = ["user-sign-up", request.remote_ip, Date.today]
# IP limit
sign_up_count = Rails.cache.read(cache_key) || 0
setting_limit = Setting.s... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/users/team_actions.rb | app/controllers/users/team_actions.rb | module Users
module TeamActions
extend ActiveSupport::Concern
included do
before_action :set_team, only: [:show]
end
private
def team_show
@topics = Topic.where(user_id: @team.user_ids, team_id: [nil, @team.id])
.fields_for_list
.last_actived.includes(:user)
@t... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/users/sessions_controller.rb | app/controllers/users/sessions_controller.rb | class Users::SessionsController < Devise::SessionsController
before_action :require_no_sso!, only: %i[new create]
def create
resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
if session[:omniauth]
@auth = Authorization.find_or_create_... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/application_controller/deviseable.rb | app/controllers/application_controller/deviseable.rb | class ApplicationController
module Deviseable
extend ActiveSupport::Concern
included do
before_action :configure_permitted_parameters, if: :devise_controller?
end
def store_location
session[:return_to] = request.url
end
def redirect_back_or_default(default)
redirect_to(ses... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/application_controller/current_info.rb | app/controllers/application_controller/current_info.rb | class ApplicationController
module CurrentInfo
extend ActiveSupport::Concern
included do
before_action do
Current.request_id = request.uuid
Current.user = current_user
end
end
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/application_controller/localize.rb | app/controllers/application_controller/localize.rb | class ApplicationController
module Localize
extend ActiveSupport::Concern
included do
helper_method :user_locale
around_action :set_time_zone
before_action :set_locale
end
def user_locale
params[:locale] || cookies[:locale] || http_head_locale || Setting.default_locale || I1... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/application_controller/turbolinks.rb | app/controllers/application_controller/turbolinks.rb | class ApplicationController
module Turbolinks
extend ActiveSupport::Concern
included do
helper_method :turbolinks_app?, :turbolinks_ios?, :turbolinks_app_version
end
def turbolinks_app?
@turbolinks_app ||= request.user_agent.to_s.include?("turbolinks-app")
end
def turbolinks_ios... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/application_controller/user_notifications.rb | app/controllers/application_controller/user_notifications.rb | class ApplicationController
module UserNotifications
extend ActiveSupport::Concern
included do
helper_method :unread_notify_count
end
def unread_notify_count
return 0 if current_user.blank?
@unread_notify_count ||= Notification.unread_count(current_user)
end
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/controllers/notifications/notifications_controller.rb | app/controllers/notifications/notifications_controller.rb | module Notifications
class NotificationsController < Notifications::ApplicationController
def index
@notifications = notifications.includes(:actor).order("id desc").page(params[:page])
@unread_ids = @notifications.reject(&:read?).collect(&:id)
@notification_groups = @notifications.group_by { |no... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/components/reply_to_component.rb | app/components/reply_to_component.rb | class ReplyToComponent < ApplicationComponent
attr_reader :reply, :show_body
delegate :markdown, to: :helpers
def initialize(reply:, topic:, show_body: false)
@reply = reply
@topic = topic
@show_body = show_body
end
def reply_to
reply.reply_to
end
def user
reply_to&.user
end
d... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/components/topic_component.rb | app/components/topic_component.rb | class TopicComponent < ApplicationComponent
attr_reader :topic, :type
delegate :topic_excellent_tag, :topic_close_tag, :timeago, to: :helpers
with_collection_parameter :topic
def initialize(topic:, type: "normal")
@topic = topic
@type = type
end
def render?
!!@topic
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/components/application_component.rb | app/components/application_component.rb | class ApplicationComponent < ViewComponent::Base
delegate :user_avatar_tag, :user_name_tag, :icon_tag, :icon_bold_tag, :owner?, :main_app, to: :helpers
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/components/alert_component.rb | app/components/alert_component.rb | class AlertComponent < ApplicationComponent
def render?
!!flash.any?
end
def alert_class(type)
type = type.to_s
type = "alert-success" if type == "notice"
type = "alert-danger" if type == "alert"
["alert alert-dismissible fade show flex items-center md:justify-between", type].join(" ")
end... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/components/profile_card_component.rb | app/components/profile_card_component.rb | class ProfileCardComponent < ApplicationComponent
delegate :follow_user_tag, to: :helpers
attr_reader :user
def initialize(user:)
@user = user
end
def render?
!!user
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/components/reply_component.rb | app/components/reply_component.rb | class ReplyComponent < ApplicationComponent
attr_reader :reply
delegate :timeago, :likeable_tag, to: :helpers
def initialize(reply:, topic:, reply_counter: 0, show_raw: false)
@reply = reply
@topic = topic
@show_raw = show_raw
@reply_counter = reply_counter
end
def render?
@reply && @to... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/user_sso.rb | app/models/user_sso.rb | class UserSSO < ActiveRecord::Base
belongs_to :user
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/current.rb | app/models/current.rb | class Current < ActiveSupport::CurrentAttributes
attribute :request_id
attribute :user
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/search_document.rb | app/models/search_document.rb | class SearchDocument < ActiveRecord::Base
belongs_to :searchable, polymorphic: true
def self.index(obj)
return unless obj.respond_to? :search_document
doc = obj.search_document
if doc.nil?
SearchDocument.create(searchable: obj)
doc = obj.reload.search_document
end
indexed_json = ob... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/topic.rb | app/models/topic.rb | class Topic < ApplicationRecord
include UserAvatarDelegate
include Searchable
include Closeable
include MentionTopic
include Mentionable
include MarkdownBody
include SoftDelete
include TopicReference
include Topic::RateLimit
include Topic::Notify
include Topic::Search
include Topic::AutoCorrect
... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/ability.rb | app/models/ability.rb | class Ability
include CanCan::Ability
attr_reader :user
def initialize(u)
@user = u
if @user.blank?
roles_for_anonymous
elsif @user.admin?
can :manage, :all
elsif @user.member?
roles_for_members
elsif @user.hr?
roles_for_members
elsif @user.vip?
roles_for_me... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/cache_version.rb | app/models/cache_version.rb | # Save speical cache version
# For example:
# Record last update, pin topic time for update cache_key to expire cache that used this key.
#
# Usage:
# Topic after_suggest ->
# CacheVersion.topic_last_suggested_at = Time.now
# In View <% cache("topic/index/sidebar_suggest:#{CacheVersion.topic_last_suggested_at}"... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/node.rb | app/models/node.rb | class Node < ApplicationRecord
has_many :topics
validates :name, presence: true
validates :name, uniqueness: true
scope :hots, -> { order(topics_count: :desc) }
scope :sorted, -> { order(sort: :desc) }
def self.name_options
self.all.collect { |node| [node.name, node.id] }
end
def self.find_built... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/team_user.rb | app/models/team_user.rb | class TeamUser < ApplicationRecord
enum :role, %i[owner member]
enum :status, %i[pendding accepted]
belongs_to :team, touch: true, counter_cache: true
belongs_to :user
validates :login, :team_id, :role, presence: true, on: :invite
validates :user_id, uniqueness: { scope: :team_id, message: I18n.t("teams.u... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/location.rb | app/models/location.rb | class Location < ApplicationRecord
has_many :users
scope :hot, -> { order(users_count: :desc).where.not(users_count: 0) }
validates :name, presence: true, uniqueness: { case_sensitive: false }
before_save { |loc| loc.name = loc.name.downcase.strip }
def self.location_find_by_name(name)
return nil if n... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/comment.rb | app/models/comment.rb | class Comment < ApplicationRecord
include UserAvatarDelegate
include Mentionable
include MarkdownBody
belongs_to :commentable, polymorphic: true
belongs_to :user, optional: true
validates :body, presence: true
attr_writer :mentioned_user_ids
def mentioned_user_ids
@mentioned_user_ids ||= []
en... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/application_record.rb | app/models/application_record.rb | class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
include RedisCountable
include Countable
include FakeSecondCache
scope :recent, -> { order(id: :desc) }
scope :exclude_ids, ->(ids) { where.not(id: ids.map(&:to_i)) }
scope :by_week, -> { where("created_at > ?", 7.days.ago.utc) }
del... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/counter.rb | app/models/counter.rb | class Counter < ApplicationRecord
belongs_to :countable, polymorphic: true
validates :countable, presence: true
delegate :to_i, :to_s, :inspect, to: :value
def incr(by = 1)
increment!(:value, by).value
end
def decr(by = 1)
decrement!(:value, by).value
end
def respond_to_missing?
true
e... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/photo.rb | app/models/photo.rb | class Photo < ApplicationRecord
belongs_to :user, optional: true
mount_uploader :image, PhotoUploader
after_commit :remove_image!, on: :destroy
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/setting.rb | app/models/setting.rb | # RailsSettings Model
class Setting < RailsSettings::Base
LEGECY_ENVS = {
github_token: "github_api_key",
github_secret: "github_api_secret"
}
concerning :Legacy do
included do
end
class_methods do
def legecy_env_instead(key)
LEGECY_ENVS[key]
end
def legecy_envs
... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/profile.rb | app/models/profile.rb | class Profile < ApplicationRecord
belongs_to :user
CONTACT_FIELDS = %i[alipay paypal qq weibo wechat douban dingding aliwangwang
facebook instagram dribbble battle_tag psn_id steam_id]
# store :contacts, coder: JSON
# store :rewards, coder: JSON
# store_accessor :contacts, *CONTACT_FIELDS
store_access... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/team.rb | app/models/team.rb | class Team < User
has_one :profile, foreign_key: :user_id, dependent: :nullify
has_many :replies, foreign_key: :user_id
has_many :authorizations, foreign_key: :user_id
has_many :notifications, foreign_key: :user_id
has_one :sso, class_name: "UserSSO", foreign_key: :user_id, dependent: :destroy
has_many :te... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/authorization.rb | app/models/authorization.rb | class Authorization < ApplicationRecord
belongs_to :user
validates :uid, :provider, presence: true
validates :uid, uniqueness: { scope: :provider }
def self.find_user_by_provider(provider, uid)
where(provider: provider, uid: uid).first&.user
end
def self.create_auth(auth, user)
where(provider: au... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/device.rb | app/models/device.rb | class Device < ApplicationRecord
belongs_to :user
enum :platform, %i[ios android]
validates :platform, :token, presence: true
validates :token, uniqueness: { scope: %i[user_id platform] }
def alive?
return true if last_actived_at.blank?
(Date.current - last_actived_at.to_date).to_i <= 14
end
d... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/reply.rb | app/models/reply.rb | require "digest/md5"
class Reply < ApplicationRecord
include UserAvatarDelegate
include MentionTopic
include Mentionable
include MarkdownBody
include SoftDelete
include TopicReference
include Reply::Voteable
include Reply::Notify
belongs_to :user, counter_cache: true
belongs_to :topic, touch: true... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/notification.rb | app/models/notification.rb | # Auto generate with notifications gem.
class Notification < ActiveRecord::Base
include Notifications::Model
after_create :realtime_push_to_client
after_update :realtime_push_to_client
def realtime_push_to_client
if user
Notification.realtime_push_to_client(user)
PushJob.perform_later(user_id,... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/user.rb | app/models/user.rb | require "digest/md5"
class User < ApplicationRecord
include Searchable
include User::SoftDelete
include User::Avatar
include User::Deviseable
include User::RewardFields
include User::ProfileFields
include User::GitHubRepository
include User::TopicActions
include User::Followable
include User::Likea... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/concerns/soft_delete.rb | app/models/concerns/soft_delete.rb | module SoftDelete
extend ActiveSupport::Concern
included do
default_scope -> { where(deleted_at: nil) }
scope :with_deleted, -> { unscope(where: :deleted_at) }
alias_method :destroy!, :destroy
end
def destroy
run_callbacks(:destroy) do
if persisted?
t = Time.now.utc
upd... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/concerns/searchable.rb | app/models/concerns/searchable.rb | module Searchable
extend ActiveSupport::Concern
included do
has_one :search_document, as: :searchable, dependent: :delete
after_commit on: :create do
reindex!
end
after_update do
reindex! # if self&.indexed_changed?
end
end
def indexed_changed?
true
end
def reindex!
... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/concerns/fake_second_cache.rb | app/models/concerns/fake_second_cache.rb | # Add a fake second_level_cache method to the model for compatibility with the Homeland plugins.
module FakeSecondCache
extend ActiveSupport::Concern
class_methods do
def second_level_cache(args = {})
end
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/concerns/closeable.rb | app/models/concerns/closeable.rb | # 开启关闭帖子功能
module Closeable
extend ActiveSupport::Concern
included do
end
def closed?
closed_at.present?
end
def close!
transaction do
Reply.create_system_event!(action: "close", topic_id: id)
update!(closed_at: Time.now)
end
end
def open!
transaction do
update!(clo... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/concerns/user_avatar_delegate.rb | app/models/concerns/user_avatar_delegate.rb | module UserAvatarDelegate
extend ActiveSupport::Concern
def user_avatar_raw
user ? user[:avatar] : nil
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/concerns/redis_countable.rb | app/models/concerns/redis_countable.rb | # 增加访问量的功能
module RedisCountable
extend ActiveSupport::Concern
class Counter
attr_reader :key
def initialize(key, default: 0)
@key = (key.is_a?(Array) ? key.flatten.join(":") : key).downcase
redis.setnx(@key, default)
end
def redis
Homeland.redis
end
def incr(by = 1)
... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/concerns/mentionable.rb | app/models/concerns/mentionable.rb | module Mentionable
extend ActiveSupport::Concern
included do
before_save :extract_mentioned_users
after_create :send_mention_notification
after_destroy :delete_notification_mentions
end
def delete_notification_mentions
Notification.where(notify_type: "mention", target: self).delete_all
end
... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/concerns/topic_reference.rb | app/models/concerns/topic_reference.rb | module TopicReference
extend ActiveSupport::Concern
included do
after_commit :extract_references, on: %i[create update]
end
def extract_references
TopicReferenceJob.perform_later(self.class.name, id)
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/concerns/countable.rb | app/models/concerns/countable.rb | # Countable for storage by use ActiveRecord
module Countable
extend ActiveSupport::Concern
included do
scope :with_counters, -> { includes(@@countable_names) }
end
class_methods do
def countable(*names)
class_eval do
@@countable_names ||= []
names.each do |name|
@@coun... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/concerns/mention_topic.rb | app/models/concerns/mention_topic.rb | module MentionTopic
extend ActiveSupport::Concern
TOPIC_LINK_REGEXP = %r{://#{Setting.domain}/topics/(\d+)}i
included do
attr_accessor :mentioned_topic_ids
after_save :create_releated_for_mentioned_topics
end
def extract_mentioned_topic_ids
matched_ids = body.scan(TOPIC_LINK_REGEXP).flatten
... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/concerns/scoped_setting.rb | app/models/concerns/scoped_setting.rb | # Backward compatible to support RailsSettingsCached 0.x scoped settings
module ScopedSetting
extend ActiveSupport::Concern
included do
has_many :settings, as: :thing
end
class_methods do
def scoped_field(name, default: nil)
define_method(name) do
obj = settings.where(var: name).take || ... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/concerns/markdown_body.rb | app/models/concerns/markdown_body.rb | # 转换 body -> html
# [Plugin API]
module MarkdownBody
extend ActiveSupport::Concern
include ActionView::Helpers::OutputSafetyHelper
include ActionView::Helpers::TextHelper
include ApplicationHelper
def body_html
markdown(body)
end
def description
@description = Rails.cache.fetch([self, "descripti... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/topic/actions.rb | app/models/topic/actions.rb | class Topic
module Actions
extend ActiveSupport::Concern
included do
enum :grade, { ban: -1, normal: 0, excellent: 1 }
# Follow enum method override methods must in `included` block.
def ban!(reason: "")
transaction do
update!(grade: :ban)
if reason
... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/topic/notify.rb | app/models/topic/notify.rb | class Topic
module Notify
extend ActiveSupport::Concern
included do
before_save :notify_admin_editing_node_changed
after_commit on: :create do
NotifyTopicJob.perform_later(id)
end
end
private
def notify_admin_editing_node_changed
return unless node_id_changed?
... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/topic/rate_limit.rb | app/models/topic/rate_limit.rb | class Topic
module RateLimit
extend ActiveSupport::Concern
included do
before_validation :_rate_limit_create, on: :create
after_commit :_log_rate_limit_create, on: :create
end
private
def _rate_limit_key
@rate_limit_key ||= "users:#{user_id}:topic-create"
end
def _rat... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/topic/search.rb | app/models/topic/search.rb | class Topic
module Search
extend ActiveSupport::Concern
def indexed_changed?
saved_change_to_title? || saved_change_to_body?
end
def as_indexed_json
{
title: title,
body: Homeland::Html.plain(body_html)
}.as_json
end
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/topic/auto_correct.rb | app/models/topic/auto_correct.rb | class Topic
module AutoCorrect
extend ActiveSupport::Concern
included do
before_save :auto_correct_title
end
private
def auto_correct_title
return if title.blank?
self.title = ::AutoCorrect.format(title)
end
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/user/deviseable.rb | app/models/user/deviseable.rb | class User
# Omniauth
module Deviseable
extend ActiveSupport::Concern
included do
attr_accessor :omniauth_provider, :omniauth_uid
devise :database_authenticatable, :registerable, :recoverable, :lockable,
:rememberable, :trackable, :validatable, :omniauthable, :confirmable
after_... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/user/soft_delete.rb | app/models/user/soft_delete.rb | class User
module SoftDelete
extend ActiveSupport::Concern
included do
define_callbacks :soft_delete
end
def soft_delete
run_callbacks :soft_delete do
self.state = "deleted"
save(validate: false)
end
end
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/user/topic_actions.rb | app/models/user/topic_actions.rb | class User
# 用户对话题的动作
module TopicActions
extend ActiveSupport::Concern
included do
action_store :favorite, :topic
end
def favorites_count
favorite_topic_actions.count
end
# Determine user was read topic latest updates
def topic_read?(topic)
# Use last_reply_id as ca... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/user/likeable.rb | app/models/user/likeable.rb | class User
# 对话题、回帖点赞
module Likeable
extend ActiveSupport::Concern
included do
# Action for Topic
action_store :like, :topic, counter_cache: true
# Action for Reply
action_store :like, :reply, counter_cache: true
end
def like(likeable)
return false if likeable.blank?... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/user/roles.rb | app/models/user/roles.rb | class User
# 用户权限相关
module Roles
extend ActiveSupport::Concern
included do
enum :state, { deleted: -1, member: 1, blocked: 2, vip: 3, hr: 4, maintainer: 90, admin: 99 }
def self.state_options
self.states.map { |key, _| [I18n.t("activerecord.enums.user.state.#{key}"), key] }
end
... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/user/avatar.rb | app/models/user/avatar.rb | class User
module Avatar
extend ActiveSupport::Concern
LETTER_AVATAR_REGEXP = /([a-z0-9])/i
included do
mount_uploader :avatar, AvatarUploader
after_commit :remove_avatar!, on: :destroy
define_method :avatar? do
self[:avatar].present?
end
set_callback :soft_delete... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/user/reward_fields.rb | app/models/user/reward_fields.rb | class User
module RewardFields
extend ActiveSupport::Concern
REWARD_FIELDS = %i[alipay wechat]
included do
delegate :rewards, to: :profile, allow_nil: true
end
def reward_enabled?
REWARD_FIELDS.each do |key|
return true if reward_field(key).present?
end
false
... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/user/github_repository.rb | app/models/user/github_repository.rb | class User
module GitHubRepository
extend ActiveSupport::Concern
included do
end
def github_repositories
items = Rails.cache.read(github_repositories_cache_key)
if items.nil?
GitHubRepoFetcherJob.perform_later(id)
items = []
end
items.take(10)
end
def... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/user/blockable.rb | app/models/user/blockable.rb | class User
module Blockable
extend ActiveSupport::Concern
included do
action_store :block, :user
action_store :block, :node
end
def block_users?
block_user_actions.first.present?
end
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/user/profile_fields.rb | app/models/user/profile_fields.rb | class User
module ProfileFields
extend ActiveSupport::Concern
included do
delegate :contacts, to: :profile, allow_nil: true
delegate :theme, to: :profile, allow_nil: true
before_save :store_location
end
def profile_field(field)
return nil if contacts.nil?
contacts[fiel... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/user/redis_online_trackable.rb | app/models/user/redis_online_trackable.rb | # Track user online status
class User
module RedisOnlineTrackable
extend ActiveSupport::Concern
REDIS_ONLINE_KEY = "online_users_set"
# Track user online timestamp
# Example: Invoke `current_user.touch_last_online_ts` in a controller request.
def touch_last_online_ts(timestamp: Time.current)
... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/user/followable.rb | app/models/user/followable.rb | class User
module Followable
extend ActiveSupport::Concern
included do
action_store :follow, :topic
action_store :follow, :user, counter_cache: "followers_count",
user_counter_cache: "following_count"
end
def follow_user(user)
return unless user
create_action(:follow,... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/reply/notify.rb | app/models/reply/notify.rb | class Reply
module Notify
extend ActiveSupport::Concern
included do
after_commit on: :create, unless: -> { system_event? } do
NotifyReplyJob.perform_later(id)
end
end
def broadcast_to_client
message = { id: id, user_id: user_id, action: :create }
ActionCable.server.br... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/models/reply/voteable.rb | app/models/reply/voteable.rb | class Reply
module Voteable
extend ActiveSupport::Concern
UPVOTES = %w[+1 :+1: :thumbsup: :plus1: 👍 👍🏻 👍🏼 👍🏽 👍🏾 👍🏿]
included do
after_commit :check_vote_chars_for_like_topic, on: :create, unless: -> { system_event? }
end
def upvote?
(body || "").strip.start_with?(*UPVOTES... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/mailers/application_mailer.rb | app/mailers/application_mailer.rb | class ApplicationMailer < ActionMailer::Base
layout "mailer"
helper :topics, :users
# Mailer default options will update by lib/homeland/setup_mailer.rb in Rails runtime.
# This line just for work with Test case.
default charset: "utf-8"
default content_type: "text/html"
rescue_from Postmark::InactiveRe... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/mailers/user_mailer.rb | app/mailers/user_mailer.rb | class UserMailer < ApplicationMailer
def welcome(user_id)
@user = User.find_by_id(user_id)
return false if @user.blank?
mail(to: @user.email, subject: t("mail.welcome_subject", app_name: Setting.app_name).to_s)
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/channels/replies_channel.rb | app/channels/replies_channel.rb | class RepliesChannel < ApplicationCable::Channel
def subscribed
stream_from "topics/#{params[:topic_id]}/replies"
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/channels/notifications_channel.rb | app/channels/notifications_channel.rb | class NotificationsChannel < ApplicationCable::Channel
def subscribed
stream_from "notifications_count/#{current_user_id}"
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/channels/application_cable/channel.rb | app/channels/application_cable/channel.rb | module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/app/channels/application_cable/connection.rb | app/channels/application_cable/connection.rb | module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user_id
def connect
self.current_user_id = find_verified_user
end
def disconnect
logger.info "Active Connections: #{ActionCable.server.connections.length}"
end
protected
def find... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/db/seeds.rb | db/seeds.rb | # ============ init Section, Node ================
%w[Fun Movie Music Apple Goolge Coding].each do |name|
Node.create!(name: name, summary: "...")
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/db/schema.rb | db/schema.rb | # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rai... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/db/migrate/20200213140928_upgrade_user_state.rb | db/migrate/20200213140928_upgrade_user_state.rb | class UpgradeUserState < ActiveRecord::Migration[6.0]
def up
# vip: 3, admin: 99
execute <<-SQL
UPDATE users SET state = 3 WHERE verified = true
SQL
end
def down
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/db/migrate/20201119010515_remove_node_name_from_topics.rb | db/migrate/20201119010515_remove_node_name_from_topics.rb | class RemoveNodeNameFromTopics < ActiveRecord::Migration[6.1]
def change
remove_column :topics, :node_name
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/db/migrate/20200213155459_add_unique_index_to_users.rb | db/migrate/20200213155459_add_unique_index_to_users.rb | class AddUniqueIndexToUsers < ActiveRecord::Migration[6.0]
def up
execute <<~SQL
DELETE FROM users u WHERE u.id NOT IN (SELECT MIN(id) FROM users GROUP BY login)
SQL
execute <<~SQL
DELETE FROM users u WHERE u.id NOT IN (SELECT MIN(id) FROM users GROUP BY email)
SQL
remove_index :users... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/db/migrate/20160602020013_add_target_to_replies.rb | db/migrate/20160602020013_add_target_to_replies.rb | class AddTargetToReplies < ActiveRecord::Migration[5.0]
def change
add_column :replies, :action, :string
add_column :replies, :target_type, :string, after: :action
add_column :replies, :target_id, :string, after: :target_type
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/db/migrate/20200721022652_migrate_profile_data.rb | db/migrate/20200721022652_migrate_profile_data.rb | class MigrateProfileData < ActiveRecord::Migration[6.0]
disable_ddl_transaction!
def up
say_with_time "Migration profile_fields..." do
Setting.unscoped.where(thing_type: "User", var: "profile_fields").find_each do |setting|
Profile.upsert({ contacts: setting.value, user_id: setting.thing_id }, un... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/db/migrate/20170222062457_add_reply_to_id_to_replies.rb | db/migrate/20170222062457_add_reply_to_id_to_replies.rb | class AddReplyToIdToReplies < ActiveRecord::Migration[5.0]
def change
add_column :replies, :reply_to_id, :integer
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/db/migrate/20231003022420_create_active_storage_variant_records.active_storage.rb | db/migrate/20231003022420_create_active_storage_variant_records.active_storage.rb | # This migration comes from active_storage (originally 20191206030411)
class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
def change
return unless table_exists?(:active_storage_blobs)
# Use Active Record's configured type for primary key
create_table :active_storage_variant_records, i... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/db/migrate/20160302043713_add_user_id_index_on_notifications.rb | db/migrate/20160302043713_add_user_id_index_on_notifications.rb | class AddUserIdIndexOnNotifications < ActiveRecord::Migration[5.0]
def change
remove_index :notifications, :read
add_index :notifications, :user_id
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/db/migrate/20160912124102_add_team_users_count_to_users.rb | db/migrate/20160912124102_add_team_users_count_to_users.rb | class AddTeamUsersCountToUsers < ActiveRecord::Migration[5.0]
def up
add_column :users, :team_users_count, :integer
User.reset_column_information
say_with_time "Reset all teams' team_users counter cache" do
Team.select(:id).find_each { |team| Team.reset_counters(team.id, :team_users) }
end
en... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/db/migrate/20160707084438_create_team_users_join_table.rb | db/migrate/20160707084438_create_team_users_join_table.rb | class CreateTeamUsersJoinTable < ActiveRecord::Migration[5.0]
def change
add_column :users, :type, :string, limit: 20, after: :id
create_table(:team_users) do |t|
t.integer :team_id, index: true, null: false
t.integer :user_id, index: true, null: false
t.integer :role
t.integer :statu... | ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
ruby-china/homeland | https://github.com/ruby-china/homeland/blob/9f5dbde5b7ce92b72bfdfb14622a784a2805e412/db/migrate/20161215014636_remove_body_html_field.rb | db/migrate/20161215014636_remove_body_html_field.rb | class RemoveBodyHtmlField < ActiveRecord::Migration[5.0]
def change
remove_column :topics, :body_html
remove_column :replies, :body_html
remove_column :comments, :body_html
end
end
| ruby | MIT | 9f5dbde5b7ce92b72bfdfb14622a784a2805e412 | 2026-01-04T15:48:23.006961Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.