Skip to content

Commit

Permalink
Merge pull request #1054 from DalenW/rbs
Browse files Browse the repository at this point in the history
RBS
  • Loading branch information
semmons99 committed Mar 18, 2024
2 parents 3a45a68 + 20d54f8 commit 73b84b5
Show file tree
Hide file tree
Showing 18 changed files with 1,956 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ doc/

# Spec artifacts
/coverage
.gem_rbs_collection
.idea
4 changes: 4 additions & 0 deletions lib/money/money/allocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class Allocation
#
# The results should always add up to the original amount.
#
# The parts can be specified as:
# Numeric — performs the split between a given number of parties evenly
# Array<Numeric> — allocates the amounts proportionally to the given array
#
# @param amount [Numeric] The total amount to be allocated.
# @param parts [Numeric, Array<Numeric>] Number of parts to split into or an array (proportions for allocation)
# @param whole_amounts [Boolean] Specifies whether to allocate whole amounts only. Defaults to true.
Expand Down
2 changes: 2 additions & 0 deletions money.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec", "~> 3.4"
s.add_development_dependency "yard", "~> 0.9.11"
s.add_development_dependency "kramdown", "~> 2.3"
s.add_development_dependency "rbs" if RUBY_VERSION >= "2.7.0"
s.add_development_dependency "typeprof" if RUBY_VERSION >= "2.7.0"

s.required_ruby_version = '>= 3.1'

Expand Down
58 changes: 58 additions & 0 deletions rbs_collection.lock.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
sources:
- type: git
name: ruby/gem_rbs_collection
revision: d0d7aeed98fa74427b30b336fc402ea86d526f35
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
path: ".gem_rbs_collection"
gems:
- name: cgi
version: '0'
source:
type: stdlib
- name: concurrent-ruby
version: '1.1'
source:
type: git
name: ruby/gem_rbs_collection
revision: d0d7aeed98fa74427b30b336fc402ea86d526f35
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: i18n
version: '1.10'
source:
type: git
name: ruby/gem_rbs_collection
revision: d0d7aeed98fa74427b30b336fc402ea86d526f35
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
- name: logger
version: '0'
source:
type: stdlib
- name: monitor
version: '0'
source:
type: stdlib
- name: optparse
version: '0'
source:
type: stdlib
- name: tempfile
version: '0'
source:
type: stdlib
- name: uri
version: '0'
source:
type: stdlib
- name: yard
version: '0.9'
source:
type: git
name: ruby/gem_rbs_collection
revision: d0d7aeed98fa74427b30b336fc402ea86d526f35
remote: https://github.com/ruby/gem_rbs_collection.git
repo_dir: gems
gemfile_lock_path: Gemfile.lock
20 changes: 20 additions & 0 deletions rbs_collection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Download sources
sources:
- type: git
name: ruby/gem_rbs_collection
remote: https://github.com/ruby/gem_rbs_collection.git
revision: main
repo_dir: gems

# You can specify local directories as sources also.
# - type: local
# path: path/to/your/local/repository

# 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
117 changes: 117 additions & 0 deletions sig/lib/money/bank/base.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
class Money
# Provides classes that aid in the ability of exchange one currency with
# another.
module Bank
# The lowest Money::Bank error class.
# All Money::Bank errors should inherit from it.
class Error < StandardError
end

# Raised when the bank doesn't know about the conversion rate
# for specified currencies.
class UnknownRate < Error
end

# Money::Bank::Base is the basic interface for creating a money exchange
# object, also called Bank.
#
# A Bank is responsible for storing exchange rates, take a Money object as
# input and returns the corresponding Money object converted into an other
# currency.
#
# This class exists for aiding in the creating of other classes to exchange
# money between different currencies. When creating a subclass you will
# need to implement the following methods to exchange money between
# currencies:
#
# - #exchange_with(Money) #=> Money
#
# See Money::Bank::VariableExchange for a real example.
#
# Also, you can extend +Money::Bank::VariableExchange+ instead of
# +Money::Bank::Base+ if your bank implementation needs to store rates
# internally.
#
# @abstract Subclass and override +#exchange_with+ to implement a custom
# +Money::Bank+ class. You can also override +#setup+ instead of
# +#initialize+ to setup initial variables, etc.
class Base
@singleton: Money::Bank::Base

# Returns the singleton instance of the Base bank.
#
# @return [Money::Bank::Base]
def self.instance: () -> Money::Bank::Base

# The rounding method to use when exchanging rates.
#
# @return [Proc]
attr_reader rounding_method: untyped

# Initializes a new +Money::Bank::Base+ object. An optional block can be
# passed to dictate the rounding method that +#exchange_with+ can use.
#
# @yield [n] Optional block to use when rounding after exchanging one
# currency for another.
# @yieldparam [Float] n The resulting float after exchanging one currency
# for another.
# @yieldreturn [Integer]
#
# @return [Money::Bank::Base]
#
# @example
# Money::Bank::Base.new #=> #<Money::Bank::Base @rounding_method=nil>
# Money::Bank::Base.new {|n|
# n.floor
# } #=> #<Money::Bank::Base @round_method=#<Proc>>
def initialize: () { () -> untyped } -> void

# Called after initialize. Subclasses can use this method to setup
# variables, etc that they normally would in +#initialize+.
#
# @abstract Subclass and override +#setup+ to implement a custom
# +Money::Bank+ class.
#
# @return [self]
def setup: () -> nil

# Exchanges the given +Money+ object to a new +Money+ object in
# +to_currency+.
#
# @abstract Subclass and override +#exchange_with+ to implement a custom
# +Money::Bank+ class.
#
# @raise NotImplementedError
#
# @param [Money] from The +Money+ object to exchange from.
# @param [Money::Currency, String, Symbol] to_currency The currency
# string or object to exchange to.
# @yield [n] Optional block to use to round the result after making
# the exchange.
# @yieldparam [Float] n The result after exchanging from one currency to
# the other.
# @yieldreturn [Integer]
#
# @return [Money]
def exchange_with: (Money from, (Money::Currency | string | Symbol) to_currency) { () -> int } -> Money

# Given two currency strings or object, checks whether they're both the
# same currency. Return +true+ if the currencies are the same, +false+
# otherwise.
#
# @param [Money::Currency, String, Symbol] currency1 The first currency
# to compare.
# @param [Money::Currency, String, Symbol] currency2 The second currency
# to compare.
#
# @return [Boolean]
#
# @example
# same_currency?("usd", "USD") #=> true
# same_currency?("usd", "EUR") #=> false
# same_currency?("usd", Currency.new("USD")) #=> true
# same_currency?("usd", "USD") #=> true
def same_currency?: ((Money::Currency | string | Symbol) currency1, (Money::Currency | string | Symbol) currency2) -> bool
end
end
end

0 comments on commit 73b84b5

Please sign in to comment.