From 339e65638cceec1a44a469edf16460c88610bb87 Mon Sep 17 00:00:00 2001 From: YutaGoto Date: Mon, 28 Nov 2022 20:54:53 +0900 Subject: [PATCH] :label: add sigs --- .gitignore | 3 + Steepfile | 8 +++ lib/ika3.rb | 4 -- lib/ika3/weapons.rb | 10 +-- rbs_collection.lock.yaml | 128 ++++++++++++++++++++++++++++++++++++ rbs_collection.yaml | 16 +++++ sig/ika3.rbs | 2 - sig/ika3/concerns/utils.rbs | 7 ++ sig/ika3/weapon.rbs | 33 ++++++++++ 9 files changed, 200 insertions(+), 11 deletions(-) create mode 100644 Steepfile create mode 100644 rbs_collection.lock.yaml create mode 100644 rbs_collection.yaml create mode 100644 sig/ika3/concerns/utils.rbs create mode 100644 sig/ika3/weapon.rbs diff --git a/.gitignore b/.gitignore index b04a8c8..537ff71 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ # rspec failure tracking .rspec_status + +# gem types +.gem_rbs_collection diff --git a/Steepfile b/Steepfile new file mode 100644 index 0000000..162b4f5 --- /dev/null +++ b/Steepfile @@ -0,0 +1,8 @@ +target :lib do + signature "sig" + + check "lib" + repo_path ".gem_rbs_collection" + library "hashie" +end + diff --git a/lib/ika3.rb b/lib/ika3.rb index 76badd0..80898dd 100644 --- a/lib/ika3.rb +++ b/lib/ika3.rb @@ -1,11 +1,7 @@ # frozen_string_literal: true -require "active_support/core_ext/array/wrap" -require "active_support/core_ext/hash/keys" - require "yaml" require "hashie" -require "json" require "ika3/version" require "ika3/concerns/utils" diff --git a/lib/ika3/weapons.rb b/lib/ika3/weapons.rb index 2d937d3..607c0b6 100644 --- a/lib/ika3/weapons.rb +++ b/lib/ika3/weapons.rb @@ -30,14 +30,14 @@ def find(weapon_key) end def find_by_name(weapon_name) - raise "unknown weapon: #{weapon_name}" unless weapon_names.values.include?(weapon_name) + raise "unknown weapon: #{weapon_name}" unless weapons.values.include?(weapon_name) - key = weapon_names.key(weapon_name) + key = weapons.key(weapon_name) find(key) end def filter_by_sub(sub_name) - raise "unknown sub weapon: #{sub_name}" unless sub_weapon_names.values.include?(sub_name) + raise "unknown sub weapon: #{sub_name}" unless sub_weapons.values.include?(sub_name) config.values.filter{|weapon| weapon[:sub] == sub_name} end @@ -56,7 +56,7 @@ def names config.keys end - def weapon_names + def weapons @weapon_hash ||= {} if @weapon_hash.empty? config.each do |key, value| @@ -66,7 +66,7 @@ def weapon_names @weapon_hash end - def sub_weapon_names + def sub_weapons @sub_weapon_hash ||= {} if @sub_weapon_hash.empty? config_sub_weapons.each do |key, value| diff --git a/rbs_collection.lock.yaml b/rbs_collection.lock.yaml new file mode 100644 index 0000000..4b913ac --- /dev/null +++ b/rbs_collection.lock.yaml @@ -0,0 +1,128 @@ +--- +sources: +- name: ruby/gem_rbs_collection + remote: https://github.com/ruby/gem_rbs_collection.git + revision: main + repo_dir: gems +path: ".gem_rbs_collection" +gems: +- name: hashie + version: '5.0' + source: + type: git + name: ruby/gem_rbs_collection + revision: 0a45b6d56b0e1b089731f5eb007912a7c36be121 + remote: https://github.com/ruby/gem_rbs_collection.git + repo_dir: gems +- name: activesupport + version: '6.0' + source: + type: git + name: ruby/gem_rbs_collection + revision: 0a45b6d56b0e1b089731f5eb007912a7c36be121 + remote: https://github.com/ruby/gem_rbs_collection.git + repo_dir: gems +- name: ast + version: '2.4' + source: + type: git + name: ruby/gem_rbs_collection + revision: 0a45b6d56b0e1b089731f5eb007912a7c36be121 + remote: https://github.com/ruby/gem_rbs_collection.git + repo_dir: gems +- name: csv + version: '0' + source: + type: stdlib +- name: fileutils + version: '0' + source: + type: stdlib +- name: i18n + version: '1.10' + source: + type: git + name: ruby/gem_rbs_collection + revision: 0a45b6d56b0e1b089731f5eb007912a7c36be121 + remote: https://github.com/ruby/gem_rbs_collection.git + repo_dir: gems +- name: ika3 + version: 0.1.0 + source: + type: rubygems +- name: json + version: '0' + source: + type: stdlib +- name: listen + version: '3.2' + source: + type: git + name: ruby/gem_rbs_collection + revision: 0a45b6d56b0e1b089731f5eb007912a7c36be121 + remote: https://github.com/ruby/gem_rbs_collection.git + repo_dir: gems +- name: logger + version: '0' + source: + type: stdlib +- name: minitest + version: '0' + source: + type: stdlib +- name: parallel + version: '1.20' + source: + type: git + name: ruby/gem_rbs_collection + revision: 0a45b6d56b0e1b089731f5eb007912a7c36be121 + remote: https://github.com/ruby/gem_rbs_collection.git + repo_dir: gems +- name: rainbow + version: '3.0' + source: + type: git + name: ruby/gem_rbs_collection + revision: 0a45b6d56b0e1b089731f5eb007912a7c36be121 + remote: https://github.com/ruby/gem_rbs_collection.git + repo_dir: gems +- name: securerandom + version: '0' + source: + type: stdlib +- name: steep + version: 1.2.1 + source: + type: rubygems +- name: strscan + version: '0' + source: + type: stdlib +- name: monitor + version: '0' + source: + type: stdlib +- name: date + version: '0' + source: + type: stdlib +- name: singleton + version: '0' + source: + type: stdlib +- name: mutex_m + version: '0' + source: + type: stdlib +- name: time + version: '0' + source: + type: stdlib +- name: pathname + version: '0' + source: + type: stdlib +- name: forwardable + version: '0' + source: + type: stdlib diff --git a/rbs_collection.yaml b/rbs_collection.yaml new file mode 100644 index 0000000..5185b1e --- /dev/null +++ b/rbs_collection.yaml @@ -0,0 +1,16 @@ +# Download sources +sources: + - name: ruby/gem_rbs_collection + remote: https://github.com/ruby/gem_rbs_collection.git + revision: main + repo_dir: gems + +# A directory to install the downloaded RBSs +path: .gem_rbs_collection + +gems: + # Skip loading rbs gem's RBS. + # It's unnecessary if you don't use rbs as a library. + - name: rbs + ignore: true + - name: hashie diff --git a/sig/ika3.rbs b/sig/ika3.rbs index 741c914..5930d13 100644 --- a/sig/ika3.rbs +++ b/sig/ika3.rbs @@ -1,4 +1,2 @@ module Ika3 - VERSION: String - # See the writing guide of rbs: https://github.com/ruby/rbs#guides end diff --git a/sig/ika3/concerns/utils.rbs b/sig/ika3/concerns/utils.rbs new file mode 100644 index 0000000..500876d --- /dev/null +++ b/sig/ika3/concerns/utils.rbs @@ -0,0 +1,7 @@ +module Ika3 + module Concerns + module Utils + def self?.load_yaml_file: (file: String) -> Object + end + end +end diff --git a/sig/ika3/weapon.rbs b/sig/ika3/weapon.rbs new file mode 100644 index 0000000..ed37e81 --- /dev/null +++ b/sig/ika3/weapon.rbs @@ -0,0 +1,33 @@ +module Ika3 + class Weapon < Hash + include Hashie::Extensions::MethodAccess + + ATTRIBUTES: ::Array[:name | :sub | :special] + + attr_accessor io: untyped + + include Ika3::Concerns::Utils + + def self.find: (untyped weapon_key) -> untyped + + def self.find_by_name: (untyped weapon_name) -> untyped + + def self.filter_by_sub: (untyped sub_name) -> untyped + + def self.reload_config!: () -> untyped + + private + + def self.names: () -> Array[Symbol] + + def self.weapons: () -> Array[Object] + + def self.sub_weapons: () -> Array[Object] + + def self.config: () -> untyped + + def self.config_sub_weapons: () -> untyped + + def self.valid?: (untyped weapon_key) -> bool + end +end