Class: Subledger::Domain::Account
- Inherits:
-
Object
- Object
- Subledger::Domain::Account
show all
- Includes:
- Subledger::Domain, Roles::Activatable, Roles::Archivable, Roles::Attributable, Roles::Collectable, Roles::Creatable, Roles::Describable, Roles::Identifiable, Roles::Readable, Roles::Restable, Roles::Storable, Roles::Updatable, Roles::Versionable
- Defined in:
- lib/subledger/domain/account.rb
Defined Under Namespace
Classes: Entity
Instance Attribute Summary collapse
#version
#client, #store
#id
#description, #reference
Class Method Summary
collapse
Instance Method Summary
collapse
#patch_hash, #post_hash, #serializable_hash, #to_json
#archive
#activate
included
included, #update
included, #read
#create, included
included
#attributes
#==, #collection_name, #entity_name, included, #to_s
Constructor Details
#initialize(args) ⇒ Account
Returns a new instance of Account.
68
69
70
71
72
73
74
75
76
|
# File 'lib/subledger/domain/account.rb', line 68
def initialize args
describable args
identifiable args
storable args
versionable args
@book = args[:book]
@normal_balance = args[:normal_balance]
end
|
Instance Attribute Details
#book ⇒ Object
Returns the value of attribute book.
26
27
28
|
# File 'lib/subledger/domain/account.rb', line 26
def book
@book
end
|
#normal_balance ⇒ Object
Returns the value of attribute normal_balance.
27
28
29
|
# File 'lib/subledger/domain/account.rb', line 27
def normal_balance
@normal_balance
end
|
Class Method Details
.active_klass ⇒ Object
45
46
47
|
# File 'lib/subledger/domain/account.rb', line 45
def self.active_klass
ActiveAccount
end
|
.archived_klass ⇒ Object
49
50
51
|
# File 'lib/subledger/domain/account.rb', line 49
def self.archived_klass
ArchivedAccount
end
|
.first_and_last_line(args) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/subledger/domain/account.rb', line 53
def self.first_and_last_line args
store = args[:store]
client = args[:client]
id = args[:id]
if id.nil?
raise AccountError, 'cannot get first and last lines without an :id'
end
args.merge! :account => client.accounts( :id => id )
store.first_and_last_line args
end
|
.patch_keys ⇒ Object
33
34
35
|
# File 'lib/subledger/domain/account.rb', line 33
def self.patch_keys
[ :id, :description, :reference, :normal_balance, :version ]
end
|
.post_keys ⇒ Object
29
30
31
|
# File 'lib/subledger/domain/account.rb', line 29
def self.post_keys
[ :description, :reference, :normal_balance ]
end
|
.root_klass ⇒ Object
37
38
39
|
# File 'lib/subledger/domain/account.rb', line 37
def self.root_klass
Account
end
|
.sub_klasses ⇒ Object
41
42
43
|
# File 'lib/subledger/domain/account.rb', line 41
def self.sub_klasses
[ active_klass, archived_klass ]
end
|
Instance Method Details
#balance(args) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/subledger/domain/account.rb', line 91
def balance args
at = args[:at]
unless at.kind_of? Time
raise AccountError, ':at must be a Time'
end
store.account_balance :store => store,
:client => client,
:account => self,
:at => at.utc
end
|
#first_and_last_line ⇒ Object
104
105
106
|
# File 'lib/subledger/domain/account.rb', line 104
def first_and_last_line
client.accounts.first_and_last_line :id => self.id
end
|
#line(args) ⇒ Object
78
79
80
|
# File 'lib/subledger/domain/account.rb', line 78
def line args
client.posted_lines( args.merge! :account => self )
end
|
#lines(args = { }, &block) ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/subledger/domain/account.rb', line 82
def lines args={ }, &block
args.merge! :action => args[:action] || :ending,
:state => args[:state] || :posted,
:effective_at => args[:effective_at] || Time.now.utc,
:account => self
client.account_lines.collect args, &block
end
|