Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary hashrockets #182

Merged
merged 1 commit into from
Feb 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ than scoped accounts due to lock contention.
To get a particular account:

```ruby
account = DoubleEntry.account(:spending, :scope => user)
account = DoubleEntry.account(:spending, scope: user)
```

(This actually returns an Account::Instance object.)
Expand All @@ -119,9 +119,9 @@ To transfer money between accounts:
```ruby
DoubleEntry.transfer(
Money.new(20_00),
:from => one_account,
:to => another_account,
:code => :a_business_code_for_this_type_of_transfer,
from: one_account,
to: another_account,
code: :a_business_code_for_this_type_of_transfer,
)
```

Expand All @@ -136,10 +136,10 @@ You may associate arbitrary metadata with transfers, for example:
```ruby
DoubleEntry.transfer(
Money.new(20_00),
:from => one_account,
:to => another_account,
:code => :a_business_code_for_this_type_of_transfer,
:metadata => {:key1 => ['value 1', 'value 2'], :key2 => 'value 3'},
from: one_account,
to: another_account,
code: :a_business_code_for_this_type_of_transfer,
metadata: {key1: ['value 1', 'value 2'], key2: 'value 3'},
)
```

Expand All @@ -152,7 +152,7 @@ manually lock the accounts you're using:
```ruby
DoubleEntry.lock_accounts(account_a, account_b) do
# Perhaps transfer some money
DoubleEntry.transfer(Money.new(20_00), :from => account_a, :to => account_b, :code => :purchase)
DoubleEntry.transfer(Money.new(20_00), from: account_a, to: account_b, code: :purchase)
# Perform other tasks that should be commited atomically with the transfer of funds...
end
```
Expand Down Expand Up @@ -206,13 +206,13 @@ DoubleEntry.configure do |config|
raise 'not a User' unless user.class.name == 'User'
user.id
end
accounts.define(:identifier => :savings, :scope_identifier => user_scope, :positive_only => true)
accounts.define(:identifier => :checking, :scope_identifier => user_scope)
accounts.define(identifier: :savings, scope_identifier: user_scope, positive_only: true)
accounts.define(identifier: :checking, scope_identifier: user_scope)
end

config.define_transfers do |transfers|
transfers.define(:from => :checking, :to => :savings, :code => :deposit)
transfers.define(:from => :savings, :to => :checking, :code => :withdraw)
transfers.define(from: :checking, to: :savings, code: :deposit)
transfers.define(from: :savings, to: :checking, code: :withdraw)
end
end
```
Expand All @@ -225,7 +225,7 @@ Transfers between accounts of different currencies are not allowed.
```ruby
DoubleEntry.configure do |config|
config.define_accounts do |accounts|
accounts.define(:identifier => :savings, :scope_identifier => user_scope, :currency => 'AUD')
accounts.define(identifier: :savings, scope_identifier: user_scope, currency: 'AUD')
end
end
```
Expand Down
6 changes: 3 additions & 3 deletions lib/active_record/locking_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def with_restart_on_deadlock
yield
rescue ActiveRecord::StatementInvalid => exception
if exception.message =~ /deadlock/i || exception.message =~ /database is locked/i
ActiveSupport::Notifications.publish('deadlock_restart.double_entry', :exception => exception)
ActiveSupport::Notifications.publish('deadlock_restart.double_entry', exception: exception)

raise ActiveRecord::RestartTransaction
else
Expand Down Expand Up @@ -46,7 +46,7 @@ def ignoring_duplicates
yield
rescue ActiveRecord::StatementInvalid, ActiveRecord::RecordNotUnique => exception
if exception.message =~ /duplicate/i || exception.message =~ /ConstraintException/
ActiveSupport::Notifications.publish('duplicate_ignore.double_entry', :exception => exception)
ActiveSupport::Notifications.publish('duplicate_ignore.double_entry', exception: exception)

# Just ignore it...someone else has already created the record.
else
Expand All @@ -63,7 +63,7 @@ def retry_deadlocks
if exception.message =~ /deadlock/i || exception.message =~ /database is locked/i
# Somebody else is in the midst of creating the record. We'd better
# retry, so we ensure they're done before we move on.
ActiveSupport::Notifications.publish('deadlock_retry.double_entry', :exception => exception)
ActiveSupport::Notifications.publish('deadlock_retry.double_entry', exception: exception)

retry
else
Expand Down
36 changes: 18 additions & 18 deletions lib/double_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def account(identifier, options = {})
# savings_account = DoubleEntry.account(:savings, scope: user)
# DoubleEntry.transfer(
# 20.dollars,
# :from => checking_account,
# :to => savings_account,
# :code => :save,
# from: checking_account,
# to: savings_account,
# code: :save,
# )
# @param [Money] amount The quantity of money to transfer from one account
# to the other.
Expand All @@ -91,35 +91,35 @@ def transfer(amount, options = {})
# Get the current or historic balance of an account.
#
# @example Obtain the current balance of my checking account
# checking_account = DoubleEntry.account(:checking, :scope => user)
# checking_account = DoubleEntry.account(:checking, scope: user)
# DoubleEntry.balance(checking_account)
# @example Obtain the current balance of my checking account (without account or user model)
# DoubleEntry.balance(:checking, :scope => user_id)
# DoubleEntry.balance(:checking, scope: user_id)
# @example Obtain a historic balance of my checking account
# checking_account = DoubleEntry.account(:checking, :scope => user)
# DoubleEntry.balance(checking_account, :at => Time.new(2012, 1, 1))
# checking_account = DoubleEntry.account(:checking, scope: user)
# DoubleEntry.balance(checking_account, at: Time.new(2012, 1, 1))
# @example Obtain the net balance of my checking account during may
# checking_account = DoubleEntry.account(:checking, :scope => user)
# checking_account = DoubleEntry.account(:checking, scope: user)
# DoubleEntry.balance(
# checking_account,
# :from => Time.new(2012, 5, 1, 0, 0, 0),
# :to => Time.new(2012, 5, 31, 23, 59, 59),
# from: Time.new(2012, 5, 1, 0, 0, 0),
# to: Time.new(2012, 5, 31, 23, 59, 59),
# )
# @example Obtain the balance of salary deposits made to my checking account during may
# checking_account = DoubleEntry.account(:checking, :scope => user)
# checking_account = DoubleEntry.account(:checking, scope: user)
# DoubleEntry.balance(
# checking_account,
# :code => :salary,
# :from => Time.new(2012, 5, 1, 0, 0, 0),
# :to => Time.new(2012, 5, 31, 23, 59, 59),
# code: :salary,
# from: Time.new(2012, 5, 1, 0, 0, 0),
# to: Time.new(2012, 5, 31, 23, 59, 59),
# )
# @example Obtain the balance of salary & lottery deposits made to my checking account during may
# checking_account = DoubleEntry.account(:checking, :scope => user)
# checking_account = DoubleEntry.account(:checking, scope: user)
# DoubleEntry.balance(
# checking_account,
# :codes => [ :salary, :lottery ],
# :from => Time.new(2012, 5, 1, 0, 0, 0),
# :to => Time.new(2012, 5, 31, 23, 59, 59),
# codes: [ :salary, :lottery ],
# from: Time.new(2012, 5, 1, 0, 0, 0),
# to: Time.new(2012, 5, 31, 23, 59, 59),
# )
# @param [DoubleEntry::Account:Instance, Symbol] account Find the balance
# for this account
Expand Down
4 changes: 2 additions & 2 deletions lib/double_entry/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def accounts
# @api private
def account(identifier, options = {})
account = accounts.find(identifier, (options[:scope].present? || options[:scope_identity].present?))
Instance.new(:account => account, :scope => options[:scope], :scope_identity => options[:scope_identity])
Instance.new(account: account, scope: options[:scope], scope_identity: options[:scope_identity])
end

# @api private
Expand Down Expand Up @@ -67,7 +67,7 @@ def backing_collection

class Instance
attr_reader :account, :scope
delegate :identifier, :scope_identifier, :scoped?, :positive_only, :negative_only, :currency, :to => :account
delegate :identifier, :scope_identifier, :scoped?, :positive_only, :negative_only, :currency, to: :account

def initialize(args)
@account = args[:account]
Expand Down
6 changes: 3 additions & 3 deletions lib/double_entry/account_balance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module DoubleEntry
#
# Account balances are created on demand when transfers occur.
class AccountBalance < ActiveRecord::Base
delegate :currency, :to => :account
delegate :currency, to: :account

def balance
self[:balance] && Money.new(self[:balance], currency)
Expand All @@ -25,11 +25,11 @@ def account=(account)
end

def account
DoubleEntry.account(self[:account].to_sym, :scope_identity => self[:scope])
DoubleEntry.account(self[:account].to_sym, scope_identity: self[:scope])
end

def self.find_by_account(account, options = {})
scope = where(:scope => account.scope_identity, :account => account.identifier.to_s)
scope = where(scope: account.scope_identity, account: account.identifier.to_s)
scope = scope.lock(true) if options[:lock]
scope.first
end
Expand Down
10 changes: 5 additions & 5 deletions lib/double_entry/balance_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ def scope?
# @api private
class RelationBuilder
attr_reader :options
delegate :account, :scope, :scope?, :from, :to, :between?, :at, :at?, :codes, :code?, :to => :options
delegate :account, :scope, :scope?, :from, :to, :between?, :at, :at?, :codes, :code?, to: :options

def initialize(options)
@options = options
end

def build
lines = Line.where(:account => account)
lines = Line.where(account: account)
lines = lines.where('created_at <= ?', at) if at?
lines = lines.where(:created_at => from..to) if between?
lines = lines.where(:code => codes) if code?
lines = lines.where(:scope => scope) if scope?
lines = lines.where(created_at: from..to) if between?
lines = lines.where(code: codes) if code?
lines = lines.where(scope: scope) if scope?
lines
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/double_entry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ def initialize
:scope_identifier_max_length=,
:account_identifier_max_length,
:account_identifier_max_length=,
:to => 'DoubleEntry::Account',
to: 'DoubleEntry::Account',
)

delegate(
:transfers,
:transfers=,
:code_max_length,
:code_max_length=,
:to => 'DoubleEntry::Transfer',
to: 'DoubleEntry::Transfer',
)

def define_accounts
Expand Down
8 changes: 4 additions & 4 deletions lib/double_entry/line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ module DoubleEntry
# by account, or account and code, over a particular period.
#
class Line < ActiveRecord::Base
belongs_to :detail, :polymorphic => true
has_many :metadata, :class_name => 'DoubleEntry::LineMetadata' unless -> { DoubleEntry.config.json_metadata }
belongs_to :detail, polymorphic: true
has_many :metadata, class_name: 'DoubleEntry::LineMetadata' unless -> { DoubleEntry.config.json_metadata }
scope :with_id_greater_than, ->(id) { where('id > ?', id) }

def amount
Expand Down Expand Up @@ -102,7 +102,7 @@ def account=(account)
end

def account
DoubleEntry.account(self[:account].to_sym, :scope_identity => scope)
DoubleEntry.account(self[:account].to_sym, scope_identity: scope)
end

def currency
Expand All @@ -117,7 +117,7 @@ def partner_account=(partner_account)
end

def partner_account
DoubleEntry.account(self[:partner_account].to_sym, :scope_identity => partner_scope)
DoubleEntry.account(self[:partner_account].to_sym, scope_identity: partner_scope)
end

def partner
Expand Down
4 changes: 2 additions & 2 deletions lib/double_entry/locking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def lock_and_call
# If one or more account balance records don't exist, set
# accounts_with_balances to the corresponding accounts, and return false.
def grab_locks
account_balances = @accounts.map { |account| AccountBalance.find_by_account(account, :lock => true) }
account_balances = @accounts.map { |account| AccountBalance.find_by_account(account, lock: true) }

if account_balances.any?(&:nil?)
@accounts_without_balances = @accounts.zip(account_balances).
Expand All @@ -168,7 +168,7 @@ def create_missing_account_balances
# Get the initial balance from the lines table.
balance = account.balance
# Try to create the balance record, but ignore it if someone else has done it in the meantime.
AccountBalance.create_ignoring_duplicates!(:account => account, :balance => balance)
AccountBalance.create_ignoring_duplicates!(account: account, balance: balance)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/double_entry/transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def create_lines(amount, code, detail, from_account, to_account, metadata)
def create_line_metadata(credit, debit, metadata)
metadata.each_pair do |key, value|
Array(value).each do |each_value|
LineMetadata.create!(:line => credit, :key => key, :value => each_value)
LineMetadata.create!(:line => debit, :key => key, :value => each_value)
LineMetadata.create!(line: credit, key: key, value: each_value)
LineMetadata.create!(line: debit, key: key, value: each_value)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/double_entry/validation/line_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def perform(fixer: nil)

unless active_accounts.empty?
LineCheck.create!(
:errors_found => incorrect_accounts.any?,
:last_line_id => current_line_id,
:log => log,
errors_found: incorrect_accounts.any?,
last_line_id: current_line_id,
log: log,
)
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/generators/double_entry/install/templates/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
# raise 'not a User' unless user.class.name == 'User'
# user.id
# end
# accounts.define(:identifier => :savings, :scope_identifier => user_scope, :positive_only => true)
# accounts.define(:identifier => :checking, :scope_identifier => user_scope)
# accounts.define(identifier: :savings, scope_identifier: user_scope, positive_only: true)
# accounts.define(identifier: :checking, scope_identifier: user_scope)
# end
#
# config.define_transfers do |transfers|
# transfers.define(:from => :checking, :to => :savings, :code => :deposit)
# transfers.define(:from => :savings, :to => :checking, :code => :withdraw)
# transfers.define(from: :checking, to: :savings, code: :deposit)
# transfers.define(from: :savings, to: :checking, code: :withdraw)
# end
end
Loading