event_sourced_accounting 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50060f8c9f1f6d7255e40b89573a8f8b57557b0a
4
- data.tar.gz: baf5ccaa16ad6488d6a94997692e780932bdd35e
3
+ metadata.gz: 1a83ae6907d7a2585115b51cbd1aaea238f15a3e
4
+ data.tar.gz: a3cfe1ed43083547c9416b652e99ffbc14de6ff3
5
5
  SHA512:
6
- metadata.gz: 6c6c898e8105dfa1bf731b6985108e0110413d6cad12d4dd2cfdb8b0710e4ce585a2f7a88a15d2c290b6f69d0118d9e20782035fb37168596a221d8ef2120f2f
7
- data.tar.gz: 6543bd307114e95356464413db9633a0de666576c19a14541a7eb3f84d4719052bc09b222a6431caca23406ac860e58a026e5a0b9dc921d7efda57c1d9808cd6
6
+ metadata.gz: 46bf5e9fe3c43bbf55125adef82617d589654abcfadb139fa85fc3f700f78756f1f2af5f1cb7d92cc15608e65e1b35444e6301615cfbd88d1f289b53f47213bd
7
+ data.tar.gz: 2ff9df539e8295630998372e49e468b90f9642f15d4fe12d95d767d4295da853b9eaa1149387054f3cd70063706672fdffd21ac8189cba0167766b65fadb6981
data/README.markdown CHANGED
@@ -1,3 +1,8 @@
1
+ [![Gem Version](https://badge.fury.io/rb/event_sourced_accounting.svg)](http://badge.fury.io/rb/event_sourced_accounting)
2
+ [![Dependency Status](https://gemnasium.com/lnagel/event-sourced-accounting.svg)](https://gemnasium.com/lnagel/event-sourced-accounting)
3
+ [![Build Status](https://api.travis-ci.org/lnagel/event-sourced-accounting.svg)](https://travis-ci.org/lnagel/event-sourced-accounting)
4
+ [![Code Climate](https://codeclimate.com/github/lnagel/event-sourced-accounting.png)](https://codeclimate.com/github/lnagel/event-sourced-accounting)
5
+
1
6
  Event-Sourced Accounting
2
7
  =================
3
8
 
@@ -1,3 +1,5 @@
1
+ require 'esa/associations/amounts_extension'
2
+
1
3
  module ESA
2
4
  # The Account class represents accounts in the system. Each account must be subclassed as one of the following types:
3
5
  #
@@ -24,7 +26,7 @@ module ESA
24
26
  attr_readonly :chart
25
27
 
26
28
  belongs_to :chart
27
- has_many :amounts, :extend => Associations::AmountsExtension
29
+ has_many :amounts, :extend => ESA::Associations::AmountsExtension
28
30
  has_many :transactions, :through => :amounts, :source => :transaction
29
31
 
30
32
  enumerize :normal_balance, in: [:none, :debit, :credit]
@@ -3,13 +3,13 @@ module ESA
3
3
  module FlagsExtension
4
4
  def most_recent(nature, time=Time.zone.now, exclude=nil)
5
5
  query = where(nature: nature).
6
- where('time <= ?', time)
6
+ where('esa_flags.time <= ?', time)
7
7
 
8
8
  if exclude.present?
9
9
  query = query.where('esa_flags.id not in (?)', exclude)
10
10
  end
11
11
 
12
- query.order('time DESC, created_at DESC').first
12
+ query.order('esa_flags.time DESC, esa_flags.created_at DESC').first
13
13
  end
14
14
 
15
15
  def is_set?(nature, time=Time.zone.now, exclude=nil)
@@ -1,9 +1,12 @@
1
+ require 'esa/associations/amounts_extension'
2
+ require 'esa/traits/extendable'
3
+
1
4
  module ESA
2
5
  # The Chart class represents an organized set of accounts in the system.
3
6
  #
4
7
  # @author Lenno Nagel
5
8
  class Chart < ActiveRecord::Base
6
- include Traits::Extendable
9
+ include ESA::Traits::Extendable
7
10
 
8
11
  attr_accessible :name
9
12
 
@@ -13,7 +16,7 @@ module ESA
13
16
  has_many :events, :through => :rulesets, :uniq => true
14
17
  has_many :flags, :through => :rulesets, :uniq => true
15
18
  has_many :transactions, :through => :accounts, :uniq => true
16
- has_many :amounts, :through => :accounts, :uniq => true, :extend => Associations::AmountsExtension
19
+ has_many :amounts, :through => :accounts, :uniq => true, :extend => ESA::Associations::AmountsExtension
17
20
 
18
21
  after_initialize :default_values
19
22
 
@@ -1,3 +1,5 @@
1
+ require 'esa/associations/amounts_extension'
2
+
1
3
  module ESA
2
4
  # The Context provides a persisted filtered view on the objects related to a Chart.
3
5
  #
@@ -14,7 +16,7 @@ module ESA
14
16
  has_many :unscoped_events, :through => :rulesets, :source => :events, :uniq => true
15
17
  has_many :unscoped_flags, :through => :rulesets, :source => :flags, :uniq => true
16
18
  has_many :unscoped_transactions, :through => :accounts, :source => :transactions, :uniq => true
17
- has_many :unscoped_amounts, :through => :accounts, :source => :amounts, :uniq => true, :extend => Associations::AmountsExtension
19
+ has_many :unscoped_amounts, :through => :accounts, :source => :amounts, :uniq => true, :extend => ESA::Associations::AmountsExtension
18
20
 
19
21
  belongs_to :parent, :class_name => "Context"
20
22
  has_many :subcontexts, :class_name => "Context", :foreign_key => "parent_id", :dependent => :destroy
@@ -1,10 +1,13 @@
1
+ require 'esa/associations/amounts_extension'
2
+ require 'esa/traits/extendable'
3
+
1
4
  module ESA
2
5
  # The Event class represents an event of significance to accounting,
3
6
  # which triggers the creation of Flags, which in turn create Transactions.
4
7
  #
5
8
  # @author Lenno Nagel
6
9
  class Event < ActiveRecord::Base
7
- include Traits::Extendable
10
+ include ESA::Traits::Extendable
8
11
  extend ::Enumerize
9
12
 
10
13
  attr_accessible :time, :nature, :accountable, :ruleset
@@ -14,7 +17,7 @@ module ESA
14
17
  belongs_to :ruleset
15
18
  has_many :flags
16
19
  has_many :transactions, :through => :flags
17
- has_many :amounts, :through => :transactions, :extend => Associations::AmountsExtension
20
+ has_many :amounts, :through => :transactions, :extend => ESA::Associations::AmountsExtension
18
21
 
19
22
  enumerize :nature, in: [:unknown, :adjustment]
20
23
 
@@ -1,3 +1,6 @@
1
+ require 'esa/associations/amounts_extension'
2
+ require 'esa/traits/extendable'
3
+
1
4
  module ESA
2
5
  # The Flag class represents a change of known state of an Accountable
3
6
  # and it is used record differences of state caused by Events.
@@ -8,7 +11,7 @@ module ESA
8
11
  #
9
12
  # @author Lenno Nagel
10
13
  class Flag < ActiveRecord::Base
11
- include Traits::Extendable
14
+ include ESA::Traits::Extendable
12
15
  extend ::Enumerize
13
16
 
14
17
  attr_accessible :nature, :state, :event, :time, :accountable, :type, :ruleset
@@ -18,7 +21,9 @@ module ESA
18
21
  belongs_to :event
19
22
  belongs_to :ruleset
20
23
  has_many :transactions
21
- has_many :amounts, :through => :transactions, :extend => Associations::AmountsExtension
24
+ has_many :amounts, :through => :transactions, :extend => ESA::Associations::AmountsExtension
25
+
26
+ scope :transitioning, lambda { joins(:event).where("esa_events.nature = 'adjustment' OR esa_flags.transition != 0").readonly(false) }
22
27
 
23
28
  enumerize :nature, in: [:unknown]
24
29
 
@@ -1,9 +1,11 @@
1
+ require 'esa/traits/extendable'
2
+
1
3
  module ESA
2
4
  # The Ruleset class contains the business logic and rules of accounting.
3
5
  #
4
6
  # @author Lenno Nagel
5
7
  class Ruleset < ActiveRecord::Base
6
- include Traits::Extendable
8
+ include ESA::Traits::Extendable
7
9
 
8
10
  attr_accessible :name, :type, :chart
9
11
  attr_readonly :name, :type, :chart
@@ -71,11 +73,7 @@ module ESA
71
73
  natures = accountable.esa_flags.pluck(:nature).uniq.map{|nature| nature.to_sym}
72
74
 
73
75
  most_recent_flags = natures.map do |nature|
74
- accountable.esa_flags.joins(:event).readonly(false).
75
- where("esa_events.nature = 'adjustment' OR esa_flags.transition != 0").
76
- where(nature: nature).
77
- order('time DESC, created_at DESC').
78
- first
76
+ accountable.esa_flags.transitioning.most_recent(nature)
79
77
  end.compact
80
78
 
81
79
  most_recent_flags.select(&:is_set?).reject do |flag|
@@ -1,3 +1,6 @@
1
+ require 'esa/associations/amounts_extension'
2
+ require 'esa/traits/extendable'
3
+
1
4
  module ESA
2
5
  # Transactions are the recording of debits and credits to various accounts.
3
6
  # This table can be thought of as a traditional accounting Journal.
@@ -6,14 +9,14 @@ module ESA
6
9
  #
7
10
  # @author Lenno Nagel, Michael Bulat
8
11
  class Transaction < ActiveRecord::Base
9
- include Traits::Extendable
12
+ include ESA::Traits::Extendable
10
13
 
11
14
  attr_accessible :description, :accountable, :flag, :time
12
15
  attr_readonly :description, :accountable, :flag, :time
13
16
 
14
17
  belongs_to :accountable, :polymorphic => true
15
18
  belongs_to :flag
16
- has_many :amounts, :extend => Associations::AmountsExtension
19
+ has_many :amounts, :extend => ESA::Associations::AmountsExtension
17
20
  has_many :accounts, :through => :amounts, :source => :account, :uniq => true
18
21
 
19
22
  after_initialize :default_values
@@ -29,14 +32,14 @@ module ESA
29
32
  def credits=(*attributes)
30
33
  attributes.flatten.each do |attrs|
31
34
  attrs[:transaction] = self
32
- self.amounts << Amounts::Credit.new(attrs)
35
+ self.amounts << ESA::Amounts::Credit.new(attrs)
33
36
  end
34
37
  end
35
38
 
36
39
  def debits=(*attributes)
37
40
  attributes.flatten.each do |attrs|
38
41
  attrs[:transaction] = self
39
- self.amounts << Amounts::Debit.new(attrs)
42
+ self.amounts << ESA::Amounts::Debit.new(attrs)
40
43
  end
41
44
  end
42
45
 
data/lib/esa.rb CHANGED
@@ -1,6 +1,58 @@
1
1
  # ESA
2
2
  require "rails"
3
3
  require "enumerize"
4
+
5
+ require 'esa/account'
6
+ require 'esa/accounts/asset'
7
+ require 'esa/accounts/equity'
8
+ require 'esa/accounts/expense'
9
+ require 'esa/accounts/liability'
10
+ require 'esa/accounts/revenue'
11
+ require 'esa/amount'
12
+ require 'esa/amounts/credit'
13
+ require 'esa/amounts/debit'
14
+ require 'esa/associations/amounts_extension'
15
+ require 'esa/associations/events_extension'
16
+ require 'esa/associations/flags_extension'
17
+ require 'esa/associations/transactions_extension'
18
+ require 'esa/chart'
19
+ require 'esa/context'
20
+ require 'esa/contexts/accountable_context'
21
+ require 'esa/contexts/accountable_type_context'
22
+ require 'esa/contexts/account_context'
23
+ require 'esa/contexts/created_at_context'
24
+ require 'esa/contexts/date_context'
25
+ require 'esa/contexts/empty_context'
26
+ require 'esa/contexts/filter_context'
27
+ require 'esa/contexts/open_close_context'
28
+ require 'esa/event'
29
+ require 'esa/flag'
30
+ require 'esa/ruleset'
31
+ require 'esa/traits/accountable'
32
+ require 'esa/traits/extendable'
33
+ require 'esa/traits/or_scope'
34
+ require 'esa/traits/union_scope'
35
+ require 'esa/transaction'
36
+
37
+ require 'esa/blocking_processor'
38
+ require 'esa/balance_checker'
39
+ require 'esa/subcontext_checker'
40
+
41
+ require 'esa/context_provider'
42
+ require 'esa/context_providers/accountable_context_provider'
43
+ require 'esa/context_providers/accountable_type_context_provider'
44
+ require 'esa/context_providers/account_context_provider'
45
+ require 'esa/context_providers/date_context_provider'
46
+
47
+ require 'esa/filters/account_filter'
48
+ require 'esa/filters/accountable_filter'
49
+ require 'esa/filters/accountable_type_filter'
50
+ require 'esa/filters/chart_filter'
51
+ require 'esa/filters/context_filter'
52
+ require 'esa/filters/date_time_filter'
53
+
54
+ require 'esa/config'
55
+
4
56
  module ESA
5
57
  class Engine < Rails::Engine
6
58
  isolate_namespace ESA
data/lib/esa/config.rb CHANGED
@@ -1,7 +1,3 @@
1
- require 'esa/blocking_processor'
2
- require 'esa/balance_checker'
3
- require 'esa/subcontext_checker'
4
-
5
1
  module ESA
6
2
  module Config
7
3
  mattr_accessor :processor
File without changes
File without changes
File without changes
File without changes
File without changes
data/lib/esa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ESA
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -2,7 +2,7 @@ FactoryGirl.define do
2
2
  factory :transaction, :class => ESA::Transaction do |transaction|
3
3
  transaction.description 'factory description'
4
4
  factory :transaction_with_credit_and_debit, :class => ESA::Transaction do |transaction_cd|
5
- transaction_cd.after_build do |t|
5
+ transaction_cd.after(:build) do |t|
6
6
  t.amounts << FactoryGirl.build(:credit_amount, :transaction => t)
7
7
  t.amounts << FactoryGirl.build(:debit_amount, :transaction => t)
8
8
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
1
4
  require 'factory_girl'
2
5
 
3
6
  ENV["RAILS_ENV"] ||= 'test'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_sourced_accounting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lenno Nagel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-04 00:00:00.000000000 Z
11
+ date: 2014-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -70,46 +70,46 @@ dependencies:
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
- version: '2.6'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
- version: '2.6'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec-rails
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
- version: '2.6'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
- version: '2.6'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rspec-rails
98
+ name: factory_girl
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
- version: '2.6'
103
+ version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
- version: '2.6'
110
+ version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: factory_girl
112
+ name: factory_girl_rails
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '>='
@@ -123,21 +123,21 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: factory_girl_rails
126
+ name: yard
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ~>
129
+ - - '>='
130
130
  - !ruby/object:Gem::Version
131
- version: '1.1'
131
+ version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ~>
136
+ - - '>='
137
137
  - !ruby/object:Gem::Version
138
- version: '1.1'
138
+ version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: yard
140
+ name: redcarpet
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - '>='
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: redcarpet
154
+ name: codeclimate-test-reporter
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - '>='
@@ -187,25 +187,14 @@ files:
187
187
  - app/models/esa/accounts/liability.rb
188
188
  - app/models/esa/accounts/revenue.rb
189
189
  - app/models/esa/accounts/equity.rb
190
- - app/models/esa/context_providers/account_context_provider.rb
191
- - app/models/esa/context_providers/date_context_provider.rb
192
- - app/models/esa/context_providers/accountable_context_provider.rb
193
- - app/models/esa/context_providers/accountable_type_context_provider.rb
194
190
  - app/models/esa/traits/extendable.rb
195
191
  - app/models/esa/traits/or_scope.rb
196
192
  - app/models/esa/traits/union_scope.rb
197
193
  - app/models/esa/traits/accountable.rb
198
194
  - app/models/esa/event.rb
199
- - app/models/esa/context_provider.rb
200
195
  - app/models/esa/flag.rb
201
196
  - app/models/esa/transaction.rb
202
197
  - app/models/esa/ruleset.rb
203
- - app/models/esa/filters/chart_filter.rb
204
- - app/models/esa/filters/accountable_type_filter.rb
205
- - app/models/esa/filters/context_filter.rb
206
- - app/models/esa/filters/date_time_filter.rb
207
- - app/models/esa/filters/accountable_filter.rb
208
- - app/models/esa/filters/account_filter.rb
209
198
  - app/models/esa/contexts/account_context.rb
210
199
  - app/models/esa/contexts/accountable_type_context.rb
211
200
  - app/models/esa/contexts/created_at_context.rb
@@ -227,9 +216,20 @@ files:
227
216
  - config/inflections.rb
228
217
  - lib/esa/subcontext_checker.rb
229
218
  - lib/esa/version.rb
219
+ - lib/esa/context_providers/account_context_provider.rb
220
+ - lib/esa/context_providers/date_context_provider.rb
221
+ - lib/esa/context_providers/accountable_context_provider.rb
222
+ - lib/esa/context_providers/accountable_type_context_provider.rb
230
223
  - lib/esa/config.rb
224
+ - lib/esa/context_provider.rb
231
225
  - lib/esa/balance_checker.rb
232
226
  - lib/esa/blocking_processor.rb
227
+ - lib/esa/filters/chart_filter.rb
228
+ - lib/esa/filters/accountable_type_filter.rb
229
+ - lib/esa/filters/context_filter.rb
230
+ - lib/esa/filters/date_time_filter.rb
231
+ - lib/esa/filters/accountable_filter.rb
232
+ - lib/esa/filters/account_filter.rb
233
233
  - lib/generators/esa/esa_generator.rb
234
234
  - lib/generators/esa/templates/migration.rb
235
235
  - lib/generators/esa/USAGE
@@ -265,6 +265,7 @@ post_install_message:
265
265
  rdoc_options: []
266
266
  require_paths:
267
267
  - lib
268
+ - app/models
268
269
  required_ruby_version: !ruby/object:Gem::Requirement
269
270
  requirements:
270
271
  - - '>='