Skip to content

Commit

Permalink
不要な helper メソッドに対するシングルトンメソッドの定義の削除
Browse files Browse the repository at this point in the history
ruby/gem_rbs_collection#569 を取り込んだ
  • Loading branch information
euglena1215 committed May 28, 2024
1 parent 9b43423 commit a041faa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 61 deletions.
33 changes: 0 additions & 33 deletions webapp/ruby/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ def db_conn #:: Mysql2::Client[Mysql2::ResultAsHash]
Thread.current[:db_conn] ||= connect_db
end

# @rbs!
# def self.db_conn: () -> Mysql2::Client[Mysql2::ResultAsHash]

def connect_db #:: Mysql2::Client[Mysql2::ResultAsHash]
Mysql2::Client.new(
host: ENV.fetch('ISUCON13_MYSQL_DIALCONFIG_ADDRESS', '127.0.0.1'),
Expand All @@ -73,9 +70,6 @@ def connect_db #:: Mysql2::Client[Mysql2::ResultAsHash]
)
end

# @rbs!
# def self.connect_db: () -> Mysql2::Client[Mysql2::ResultAsHash]

#:: [T] () { (Mysql2::Client[Mysql2::ResultAsHash]) -> T } -> T
def db_transaction(&block)
db_conn.query('BEGIN')
Expand All @@ -92,19 +86,13 @@ def db_transaction(&block)
end
end

# @rbs!
# def self.db_transaction: [T] () { (Mysql2::Client[Mysql2::ResultAsHash]) -> T } -> T

# singleton(T) が動いてほしいなあ
#:: (singleton(ReserveLivestreamRequest) | singleton(PostLivecommentRequest) | singleton(ModerateRequest) | singleton(PostReactionRequest) | singleton(PostIconRequest) | singleton(PostUserRequest) | singleton(LoginRequest) data_class) -> (ReserveLivestreamRequest | PostLivecommentRequest | ModerateRequest | PostReactionRequest | PostIconRequest | PostUserRequest | LoginRequest)
def decode_request_body(data_class)
body = JSON.parse(request.body.tap(&:rewind).read, symbolize_names: true)
data_class.new(**data_class.members.map { |key| [key, body[key]] }.to_h)
end

# @rbs!
# def self.decode_request_body: (singleton(ReserveLivestreamRequest) | singleton(PostLivecommentRequest) | singleton(ModerateRequest) | singleton(PostReactionRequest) | singleton(PostIconRequest) | singleton(PostUserRequest) | singleton(LoginRequest) data_class) -> (ReserveLivestreamRequest | PostLivecommentRequest | ModerateRequest | PostReactionRequest | PostIconRequest | PostUserRequest | LoginRequest)

# @rbs str: String
# @rbs returns Integer
def cast_as_integer(str)
Expand All @@ -113,9 +101,6 @@ def cast_as_integer(str)
raise HttpError.new(400)
end

# @rbs!
# def self.cast_as_integer: (String str) -> Integer

def verify_user_session! #:: nil
sess = session[DEFAULT_SESSION_ID_KEY]
unless sess
Expand All @@ -135,9 +120,6 @@ def verify_user_session! #:: nil
nil
end

# @rbs!
# def self.verify_user_session!: () -> nil

# @rbs tx: Mysql2::Client[Mysql2::ResultAsHash]
# @rbs livestream_model: Hash[Symbol, Mysql2::row_value_type]
# @rbs returns Hash[Symbol, untyped]
Expand All @@ -159,9 +141,6 @@ def fill_livestream_response(tx, livestream_model)
)
end

# @rbs!
# def self.fill_livestream_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, Mysql2::row_value_type] livestream_model) -> Hash[Symbol, untyped]

# @rbs tx: Mysql2::Client[Mysql2::ResultAsHash]
# @rbs livecomment_model: Hash[Symbol, untyped]
# @rbs returns Hash[Symbol, untyped]
Expand All @@ -178,9 +157,6 @@ def fill_livecomment_response(tx, livecomment_model)
)
end

# @rbs!
# def self.fill_livecomment_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, untyped] livecomment_model) -> Hash[Symbol, untyped]

# @rbs tx: Mysql2::Client[Mysql2::ResultAsHash]
# @rbs report_model: Hash[Symbol, untyped]
# @rbs returns Hash[Symbol, untyped]
Expand All @@ -197,9 +173,6 @@ def fill_livecomment_report_response(tx, report_model)
)
end

# @rbs!
# def self.fill_livecomment_report_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, untyped] report_model) -> Hash[Symbol, untyped]

# @rbs tx: Mysql2::Client[Mysql2::ResultAsHash]
# @rbs reaction_model: Hash[Symbol, Mysql2::row_value_type]
# @rbs returns Hash[Symbol, untyped]
Expand All @@ -216,9 +189,6 @@ def fill_reaction_response(tx, reaction_model)
)
end

# @rbs!
# def self.fill_reaction_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, Mysql2::row_value_type] reaction_model) -> Hash[Symbol, untyped]

# @rbs tx: Mysql2::Client[Mysql2::ResultAsHash]
# @rbs user_model: Hash[Symbol, Mysql2::row_value_type]
# @rbs returns Hash[Symbol, untyped]
Expand Down Expand Up @@ -247,9 +217,6 @@ def fill_user_response(tx, user_model)
icon_hash:,
}
end

# @rbs!
# def self.fill_user_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, Mysql2::row_value_type] user_model) -> Hash[Symbol, untyped]
end

# 初期化
Expand Down
12 changes: 6 additions & 6 deletions webapp/ruby/rbs_collection.lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gems:
source:
type: git
name: ruby/gem_rbs_collection
revision: 1cbe291950e00d97d5a9a1929388523eb2d5b939
revision: 40bc6f347bd515583de8d04422ffdffd3e7766f0
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: cgi
Expand All @@ -22,15 +22,15 @@ gems:
source:
type: git
name: ruby/gem_rbs_collection
revision: 1cbe291950e00d97d5a9a1929388523eb2d5b939
revision: 40bc6f347bd515583de8d04422ffdffd3e7766f0
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: mysql2-cs-bind
version: '0.1'
source:
type: git
name: ruby/gem_rbs_collection
revision: 1cbe291950e00d97d5a9a1929388523eb2d5b939
revision: 40bc6f347bd515583de8d04422ffdffd3e7766f0
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: openssl
Expand All @@ -42,23 +42,23 @@ gems:
source:
type: git
name: ruby/gem_rbs_collection
revision: 1cbe291950e00d97d5a9a1929388523eb2d5b939
revision: 40bc6f347bd515583de8d04422ffdffd3e7766f0
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: sinatra
version: '4.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 1cbe291950e00d97d5a9a1929388523eb2d5b939
revision: 40bc6f347bd515583de8d04422ffdffd3e7766f0
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: sinatra-contrib
version: '4.0'
source:
type: git
name: ruby/gem_rbs_collection
revision: 1cbe291950e00d97d5a9a1929388523eb2d5b939
revision: 40bc6f347bd515583de8d04422ffdffd3e7766f0
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: socket
Expand Down
22 changes: 0 additions & 22 deletions webapp/ruby/sig/generated/app.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,68 +27,46 @@ module Isupipe

def db_conn: () -> Mysql2::Client[Mysql2::ResultAsHash]

def self.db_conn: () -> Mysql2::Client[Mysql2::ResultAsHash]

def connect_db: () -> Mysql2::Client[Mysql2::ResultAsHash]

def self.connect_db: () -> Mysql2::Client[Mysql2::ResultAsHash]

# :: [T] () { (Mysql2::Client[Mysql2::ResultAsHash]) -> T } -> T
def db_transaction: [T] () { (Mysql2::Client[Mysql2::ResultAsHash]) -> T } -> T

def self.db_transaction: [T] () { (Mysql2::Client[Mysql2::ResultAsHash]) -> T } -> T

# singleton(T) が動いてほしいなあ
# :: (singleton(ReserveLivestreamRequest) | singleton(PostLivecommentRequest) | singleton(ModerateRequest) | singleton(PostReactionRequest) | singleton(PostIconRequest) | singleton(PostUserRequest) | singleton(LoginRequest) data_class) -> (ReserveLivestreamRequest | PostLivecommentRequest | ModerateRequest | PostReactionRequest | PostIconRequest | PostUserRequest | LoginRequest)
def decode_request_body: (singleton(ReserveLivestreamRequest) | singleton(PostLivecommentRequest) | singleton(ModerateRequest) | singleton(PostReactionRequest) | singleton(PostIconRequest) | singleton(PostUserRequest) | singleton(LoginRequest) data_class) -> (ReserveLivestreamRequest | PostLivecommentRequest | ModerateRequest | PostReactionRequest | PostIconRequest | PostUserRequest | LoginRequest)

def self.decode_request_body: (singleton(ReserveLivestreamRequest) | singleton(PostLivecommentRequest) | singleton(ModerateRequest) | singleton(PostReactionRequest) | singleton(PostIconRequest) | singleton(PostUserRequest) | singleton(LoginRequest) data_class) -> (ReserveLivestreamRequest | PostLivecommentRequest | ModerateRequest | PostReactionRequest | PostIconRequest | PostUserRequest | LoginRequest)

# @rbs str: String
# @rbs returns Integer
def cast_as_integer: (String str) -> Integer

def self.cast_as_integer: (String str) -> Integer

def verify_user_session!: () -> nil

def self.verify_user_session!: () -> nil

# @rbs tx: Mysql2::Client[Mysql2::ResultAsHash]
# @rbs livestream_model: Hash[Symbol, Mysql2::row_value_type]
# @rbs returns Hash[Symbol, untyped]
def fill_livestream_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, Mysql2::row_value_type] livestream_model) -> Hash[Symbol, untyped]

def self.fill_livestream_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, Mysql2::row_value_type] livestream_model) -> Hash[Symbol, untyped]

# @rbs tx: Mysql2::Client[Mysql2::ResultAsHash]
# @rbs livecomment_model: Hash[Symbol, untyped]
# @rbs returns Hash[Symbol, untyped]
def fill_livecomment_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, untyped] livecomment_model) -> Hash[Symbol, untyped]

def self.fill_livecomment_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, untyped] livecomment_model) -> Hash[Symbol, untyped]

# @rbs tx: Mysql2::Client[Mysql2::ResultAsHash]
# @rbs report_model: Hash[Symbol, untyped]
# @rbs returns Hash[Symbol, untyped]
def fill_livecomment_report_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, untyped] report_model) -> Hash[Symbol, untyped]

def self.fill_livecomment_report_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, untyped] report_model) -> Hash[Symbol, untyped]

# @rbs tx: Mysql2::Client[Mysql2::ResultAsHash]
# @rbs reaction_model: Hash[Symbol, Mysql2::row_value_type]
# @rbs returns Hash[Symbol, untyped]
def fill_reaction_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, Mysql2::row_value_type] reaction_model) -> Hash[Symbol, untyped]

def self.fill_reaction_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, Mysql2::row_value_type] reaction_model) -> Hash[Symbol, untyped]

# @rbs tx: Mysql2::Client[Mysql2::ResultAsHash]
# @rbs user_model: Hash[Symbol, Mysql2::row_value_type]
# @rbs returns Hash[Symbol, untyped]
def fill_user_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, Mysql2::row_value_type] user_model) -> Hash[Symbol, untyped]

def self.fill_user_response: (Mysql2::Client[Mysql2::ResultAsHash] tx, Hash[Symbol, Mysql2::row_value_type] user_model) -> Hash[Symbol, untyped]

class ReserveLivestreamRequest
extend Data::_DataClass
attr_reader tags: Array[Integer]
Expand Down

0 comments on commit a041faa

Please sign in to comment.