lib/sequel/extensions/currency_rates.rb in umbrellio-sequel-plugins-0.2.0 vs lib/sequel/extensions/currency_rates.rb in umbrellio-sequel-plugins-0.3.0
- old
+ new
@@ -5,23 +5,25 @@
module CurrencyRates
# Join a rates table
#
# @param aliaz [Symbol] alias to be used for joined table
# @param table [Symbol] table name to join to
+ # @param currency_column [Symbol] currency column by which table is joined
# @param time_column [Symbol] time column by which table is joined
#
# @example
# Order::Model.with_rates.select(Sequel[:amount].in_usd)
# @return [Sequel::Dataset] dataset
def with_rates(
aliaz = :currency_rates,
table: table_name,
rates_table: Sequel[:currency_rates],
+ currency_column: :currency,
time_column: :created_at
)
table = Sequel[table]
rates = Sequel[aliaz]
- join_expr = table[:currency] =~ rates[:currency]
+ join_expr = table[currency_column] =~ rates[:currency]
join_expr &= rates[:period].pg_range.contains(table[time_column])
left_join(rates_table.as(aliaz), join_expr)
end
# Returns a table name