double_entry 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +1 -1
- data/lib/double_entry.rb +2 -10
- data/lib/double_entry/account.rb +24 -18
- data/lib/double_entry/balance_calculator.rb +2 -3
- data/lib/double_entry/configuration.rb +2 -6
- data/lib/double_entry/reporting/aggregate.rb +1 -1
- data/lib/double_entry/reporting/aggregate_array.rb +1 -1
- data/lib/double_entry/transfer.rb +17 -7
- data/lib/double_entry/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32faa0991a3e20450e5c310ed76831804f8f8489
|
4
|
+
data.tar.gz: b4d643d8739f316dc7d0b3404bfd13d6bbc5f678
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f23c6af662e48e0dd8e520111628faf5f9d59e5d6b3e10d5a9cd3cb94ec9f6f5d9829d5bc86636ec4f5cac7dc6ca502a6ef011baba6e4c3b70aa7944b5a042d
|
7
|
+
data.tar.gz: 34d17bcd0b139a5dad177a588c737a5ef2b3704db52b83812b6dae3e2ac600a4eef4a2b4a642d11474e2cf074eeaebdb3d64e489e1c34033f4c67283bcb0791d
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/lib/double_entry.rb
CHANGED
@@ -41,7 +41,7 @@ module DoubleEntry
|
|
41
41
|
# match that defined on the account.
|
42
42
|
#
|
43
43
|
def account(identifier, options = {})
|
44
|
-
Account.account(
|
44
|
+
Account.account(identifier, options)
|
45
45
|
end
|
46
46
|
|
47
47
|
# Transfer money from one account to another.
|
@@ -77,7 +77,7 @@ module DoubleEntry
|
|
77
77
|
# accounts with the provided code is not allowed. Check configuration.
|
78
78
|
#
|
79
79
|
def transfer(amount, options = {})
|
80
|
-
Transfer.transfer(
|
80
|
+
Transfer.transfer(amount, options)
|
81
81
|
end
|
82
82
|
|
83
83
|
# Get the current or historic balance of an account.
|
@@ -135,14 +135,6 @@ module DoubleEntry
|
|
135
135
|
BalanceCalculator.calculate(account, options)
|
136
136
|
end
|
137
137
|
|
138
|
-
# Get the currency of an account.
|
139
|
-
#
|
140
|
-
# @param [DoubleEntry::Account:Instance, Symbol] account Find the currency for this account
|
141
|
-
# @return [Currency] the currency
|
142
|
-
def currency(account)
|
143
|
-
Account.currency(configuration.accounts, account)
|
144
|
-
end
|
145
|
-
|
146
138
|
# Lock accounts in preparation for transfers.
|
147
139
|
#
|
148
140
|
# This creates a transaction, and uses database-level locking to ensure
|
data/lib/double_entry/account.rb
CHANGED
@@ -2,21 +2,24 @@
|
|
2
2
|
module DoubleEntry
|
3
3
|
class Account
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
account = defined_accounts.find(identifier, options[:scope].present?)
|
8
|
-
DoubleEntry::Account::Instance.new(:account => account, :scope => options[:scope])
|
9
|
-
end
|
5
|
+
class << self
|
6
|
+
attr_writer :accounts
|
10
7
|
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
# @api private
|
9
|
+
def accounts
|
10
|
+
@accounts ||= Set.new
|
11
|
+
end
|
14
12
|
|
15
|
-
|
16
|
-
|
13
|
+
# @api private
|
14
|
+
def account(identifier, options = {})
|
15
|
+
account = accounts.find(identifier, options[:scope].present?)
|
16
|
+
Instance.new(:account => account, :scope => options[:scope])
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
# @api private
|
20
|
+
def currency(identifier)
|
21
|
+
accounts.detect { |a| a.identifier == identifier }.try(:currency)
|
22
|
+
end
|
20
23
|
end
|
21
24
|
|
22
25
|
# @api private
|
@@ -66,11 +69,12 @@ module DoubleEntry
|
|
66
69
|
end
|
67
70
|
|
68
71
|
class Instance
|
69
|
-
|
72
|
+
attr_reader :account, :scope
|
70
73
|
delegate :identifier, :scope_identifier, :scoped?, :positive_only, :currency, :to => :account
|
71
74
|
|
72
|
-
def initialize(
|
73
|
-
|
75
|
+
def initialize(args)
|
76
|
+
@account = args[:account]
|
77
|
+
@scope = args[:scope]
|
74
78
|
ensure_scope_is_valid
|
75
79
|
end
|
76
80
|
|
@@ -128,11 +132,13 @@ module DoubleEntry
|
|
128
132
|
end
|
129
133
|
end
|
130
134
|
|
131
|
-
|
135
|
+
attr_reader :identifier, :scope_identifier, :positive_only, :currency
|
132
136
|
|
133
|
-
def initialize(
|
134
|
-
|
135
|
-
|
137
|
+
def initialize(args)
|
138
|
+
@identifier = args[:identifier]
|
139
|
+
@scope_identifier = args[:scope_identifier]
|
140
|
+
@positive_only = args[:positive_only]
|
141
|
+
@currency = args[:currency] || Money.default_currency
|
136
142
|
end
|
137
143
|
|
138
144
|
def scoped?
|
@@ -17,11 +17,10 @@ module DoubleEntry
|
|
17
17
|
options = Options.new(account, args)
|
18
18
|
relations = RelationBuilder.new(options)
|
19
19
|
lines = relations.build
|
20
|
-
currency = DoubleEntry.currency(account)
|
21
20
|
|
22
21
|
if options.between? || options.code?
|
23
22
|
# from and to or code lookups have to be done via sum
|
24
|
-
Money.new(lines.sum(:amount), currency)
|
23
|
+
Money.new(lines.sum(:amount), account.currency)
|
25
24
|
else
|
26
25
|
# all other lookups can be performed with running balances
|
27
26
|
result = lines.
|
@@ -29,7 +28,7 @@ module DoubleEntry
|
|
29
28
|
order('id DESC').
|
30
29
|
limit(1).
|
31
30
|
pluck(:balance)
|
32
|
-
result.empty? ? Money.zero(currency) : Money.new(result.first, currency)
|
31
|
+
result.empty? ? Money.zero(account.currency) : Money.new(result.first, account.currency)
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
@@ -3,12 +3,8 @@ module DoubleEntry
|
|
3
3
|
include Configurable
|
4
4
|
|
5
5
|
class Configuration
|
6
|
-
|
7
|
-
|
8
|
-
def initialize #:nodoc:
|
9
|
-
@accounts = Account::Set.new
|
10
|
-
@transfers = Transfer::Set.new
|
11
|
-
end
|
6
|
+
delegate :accounts, :accounts=, :to => "DoubleEntry::Account"
|
7
|
+
delegate :transfers, :transfers=, :to => "DoubleEntry::Transfer"
|
12
8
|
|
13
9
|
def define_accounts
|
14
10
|
yield accounts
|
@@ -2,13 +2,23 @@
|
|
2
2
|
module DoubleEntry
|
3
3
|
class Transfer
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
class << self
|
6
|
+
attr_writer :transfers
|
7
|
+
|
8
|
+
# @api private
|
9
|
+
def transfers
|
10
|
+
@transfers ||= Set.new
|
11
|
+
end
|
12
|
+
|
13
|
+
# @api private
|
14
|
+
def transfer(amount, options = {})
|
15
|
+
raise TransferIsNegative if amount < Money.zero
|
16
|
+
from = options[:from]
|
17
|
+
to = options[:to]
|
18
|
+
code = options[:code]
|
19
|
+
detail = options[:detail]
|
20
|
+
transfers.find!(from, to, code).process(amount, from, to, code, detail)
|
21
|
+
end
|
12
22
|
end
|
13
23
|
|
14
24
|
# @api private
|
data/lib/double_entry/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: double_entry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Sellitti
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2014-11-
|
18
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: money
|