debitcredit 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15bf18b62ec5961c9bc1c4fef7717b386b5e9c4c
4
- data.tar.gz: bd563f7e9ced320e24ec88182013e30159584796
3
+ metadata.gz: 7cdda8ead625a293df8638761fa79a311cc68b02
4
+ data.tar.gz: 2f8d0b663c862ce70ef74bd8b8257be63f8ae006
5
5
  SHA512:
6
- metadata.gz: 15eaadb79408a7768a7ce639d300dfb6eb4a811a7b6e367e77facc8d5053ea829c3e3409ce32143e19e93afa447c01b264d7c991295757753bb96439ab78434b
7
- data.tar.gz: e2c2685de2c3cd0b7aa92415fb5195fc3783bea859b3f1dd1991c0ad679658cfb99391f7e4fe4de61e49b42c684a9f2f4e8934ab25e9996d22503cf46ac7f5d9
6
+ metadata.gz: 5a26e809d2ea8b7792b1ce45e332fde267440a4e63a833da1ae527932642760ba1d4dbb746076bebd14f389e97b9fbe51a5c443e457fdc93a6e5747e6dc7a34d
7
+ data.tar.gz: 5873e917d758255e97bbbe52e86e8dbea7c7154e1a0b4806dd25dfc8e6781889e694d8ab00eaf2930e8bf639716dad2036e37de19afee5ffe2a8e049f20116d0
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ rescue LoadError
5
5
  end
6
6
 
7
7
  require 'rdoc/task'
8
+ require 'thor'
8
9
 
9
10
  RDoc::Task.new(:rdoc) do |rdoc|
10
11
  rdoc.rdoc_dir = 'rdoc'
@@ -1,3 +1,4 @@
1
+ require 'docile'
1
2
  module Debitcredit
2
3
  class Account < ActiveRecord::Base
3
4
  belongs_to :reference, polymorphic: true
@@ -14,9 +15,32 @@ module Debitcredit
14
15
 
15
16
  scope :by_id, ->{order(:id)}
16
17
 
18
+ class NotFound < StandardError; end
19
+ class BadKind < StandardError; end
17
20
  class << self
18
- def [](name)
19
- find_by!(name: name)
21
+ def by_kind kind
22
+ Debitcredit.const_get "#{kind.to_s.capitalize}Account"
23
+ end
24
+
25
+ def [](name, kind = nil, overdraft = false)
26
+
27
+ unless account = find_by(name: name)
28
+ # XXX reference from @association.owner
29
+ raise NotFound, "account #{name} not found. Provide kind to create a new one" unless kind
30
+
31
+ return by_kind(kind).create!(
32
+ name: name.to_s,
33
+ overdraft_enabled: overdraft
34
+ )
35
+ end
36
+
37
+ raise BadKind if kind && by_kind(kind) != account.class
38
+
39
+ if overdraft != account.overdraft_enabled?
40
+ account.update_attributes! overdraft_enabled: overdraft
41
+ end
42
+
43
+ return account
20
44
  end
21
45
 
22
46
  def total_balance
@@ -0,0 +1,26 @@
1
+ module Debitcredit
2
+ module Extension
3
+ extend ActiveSupport::Concern
4
+ module ProxyMethods
5
+ [:asset, :liability, :expense].each do |kind|
6
+ define_method kind do |name, overdraft = false|
7
+ define_method name do
8
+ self[name, kind, overdraft]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ module ClassMethods
14
+ def has_accounts(&block)
15
+ has_many :accounts, as: :reference, class_name: 'Debitcredit::Account', inverse_of: :reference do
16
+ extend ProxyMethods
17
+ instance_eval &block
18
+ end
19
+ end
20
+
21
+ def has_transactions &block
22
+ has_many :transactions, as: :reference, class_name: 'Debitcredit::Transaction', &block
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Debitcredit
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debitcredit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitaly Kushner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-30 00:00:00.000000000 Z
11
+ date: 2014-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.2
19
+ version: 4.0.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 4.0.2
26
+ version: 4.0.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: docile
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -191,6 +191,7 @@ files:
191
191
  - app/models/debitcredit/debit_account.rb
192
192
  - app/models/debitcredit/equity_account.rb
193
193
  - app/models/debitcredit/expense_account.rb
194
+ - app/models/debitcredit/extension.rb
194
195
  - app/models/debitcredit/income_account.rb
195
196
  - app/models/debitcredit/item.rb
196
197
  - app/models/debitcredit/liability_account.rb