spatten-bookkeeper 0.2.0

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.
Files changed (62) hide show
  1. data/init.rb +1 -0
  2. data/lib/bookkeeper.rb +8 -0
  3. data/lib/bookkeeper/account.rb +95 -0
  4. data/lib/bookkeeper/account/asset.rb +3 -0
  5. data/lib/bookkeeper/account/expense.rb +3 -0
  6. data/lib/bookkeeper/account/liability.rb +3 -0
  7. data/lib/bookkeeper/account/revenue.rb +3 -0
  8. data/lib/bookkeeper/asset_type.rb +3 -0
  9. data/lib/bookkeeper/asset_type/cad.rb +2 -0
  10. data/lib/bookkeeper/asset_type/usd.rb +2 -0
  11. data/lib/bookkeeper/batch.rb +62 -0
  12. data/lib/bookkeeper/journal.rb +29 -0
  13. data/lib/bookkeeper/journal/bill.rb +32 -0
  14. data/lib/bookkeeper/journal/deposit.rb +7 -0
  15. data/lib/bookkeeper/journal/disbursement.rb +7 -0
  16. data/lib/bookkeeper/journal/invoice.rb +4 -0
  17. data/lib/bookkeeper/journal/transfer.rb +7 -0
  18. data/lib/bookkeeper/paypal_transaction.rb +12 -0
  19. data/lib/bookkeeper/paypal_transaction/masspay_subpayment.rb +17 -0
  20. data/lib/bookkeeper/paypal_transaction/single.rb +14 -0
  21. data/lib/bookkeeper/posting.rb +32 -0
  22. data/lib/immutable-attribute-plugin/MIT-LICENSE +20 -0
  23. data/lib/immutable-attribute-plugin/README +35 -0
  24. data/lib/immutable-attribute-plugin/Rakefile +22 -0
  25. data/lib/immutable-attribute-plugin/init.rb +4 -0
  26. data/lib/immutable-attribute-plugin/install.rb +1 -0
  27. data/lib/immutable-attribute-plugin/lib/ensures_immutability_of.rb +43 -0
  28. data/lib/immutable-attribute-plugin/tasks/ensures_immutability_of_tasks.rake +4 -0
  29. data/lib/immutable-attribute-plugin/test/fixtures/accounts.yml +6 -0
  30. data/lib/immutable-attribute-plugin/test/fixtures/infos.yml +6 -0
  31. data/lib/immutable-attribute-plugin/test/rails_root/README +211 -0
  32. data/lib/immutable-attribute-plugin/test/rails_root/Rakefile +10 -0
  33. data/lib/immutable-attribute-plugin/test/rails_root/app/controllers/application.rb +7 -0
  34. data/lib/immutable-attribute-plugin/test/rails_root/app/helpers/application_helper.rb +3 -0
  35. data/lib/immutable-attribute-plugin/test/rails_root/app/models/account.rb +6 -0
  36. data/lib/immutable-attribute-plugin/test/rails_root/app/models/info.rb +3 -0
  37. data/lib/immutable-attribute-plugin/test/rails_root/config/boot.rb +39 -0
  38. data/lib/immutable-attribute-plugin/test/rails_root/config/database.yml +18 -0
  39. data/lib/immutable-attribute-plugin/test/rails_root/config/environment.rb +11 -0
  40. data/lib/immutable-attribute-plugin/test/rails_root/config/environments/development.rb +21 -0
  41. data/lib/immutable-attribute-plugin/test/rails_root/config/environments/mysql.rb +0 -0
  42. data/lib/immutable-attribute-plugin/test/rails_root/config/environments/postgresql.rb +0 -0
  43. data/lib/immutable-attribute-plugin/test/rails_root/config/environments/production.rb +18 -0
  44. data/lib/immutable-attribute-plugin/test/rails_root/config/environments/sqlite.rb +0 -0
  45. data/lib/immutable-attribute-plugin/test/rails_root/config/environments/sqlite3.rb +0 -0
  46. data/lib/immutable-attribute-plugin/test/rails_root/config/environments/test.rb +19 -0
  47. data/lib/immutable-attribute-plugin/test/rails_root/config/routes.rb +23 -0
  48. data/lib/immutable-attribute-plugin/test/rails_root/db/migrate/001_create_accounts.rb +12 -0
  49. data/lib/immutable-attribute-plugin/test/rails_root/db/migrate/002_create_infos.rb +13 -0
  50. data/lib/immutable-attribute-plugin/test/rails_root/script/console +3 -0
  51. data/lib/immutable-attribute-plugin/test/rails_root/script/runner +3 -0
  52. data/lib/immutable-attribute-plugin/test/rails_root/test/test_helper.rb +28 -0
  53. data/lib/immutable-attribute-plugin/test/rails_root/vendor/plugins/phone_validation/init.rb +2 -0
  54. data/lib/immutable-attribute-plugin/test/test_helper.rb +26 -0
  55. data/lib/immutable-attribute-plugin/test/unit/plugin_test.rb +137 -0
  56. data/lib/immutable-attribute-plugin/uninstall.rb +1 -0
  57. data/rails/init.rb +1 -0
  58. data/rails_generators/USAGE +3 -0
  59. data/rails_generators/bookkeeper_generator.rb +17 -0
  60. data/rails_generators/templates/fixtures.yml +1 -0
  61. data/rails_generators/templates/migration.rb +66 -0
  62. metadata +140 -0
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the ensures_immutability_of plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the ensures_immutability_of plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'EnsuresImmutabilityOf'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,4 @@
1
+ require File.join(File.dirname(__FILE__), 'lib', 'ensures_immutability_of')
2
+ require 'acts_as_tree'
3
+
4
+ ActiveRecord::Base.send(:include, EnsuresImmutabilityOf)
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,43 @@
1
+ module ActiveRecord
2
+ class ImmutableAttributeError < ActiveRecordError
3
+ def initialize(message=nil)
4
+ super(message || 'Cannot modify immutable attribute')
5
+ end
6
+ end
7
+ end
8
+
9
+ module EnsuresImmutabilityOf
10
+ def self.included(base)
11
+ base.extend ClassMethods
12
+ end
13
+
14
+ module ClassMethods
15
+ def ensures_immutability_of(*attr_names)
16
+ configuration = { :message => "Attribute cannot be changed" }
17
+ configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
18
+
19
+ if(attr_names.include? :all)
20
+ model_instance = self.new
21
+ attr_names = []
22
+ attr_names |= self.column_names.reject { |name| !model_instance.respond_to?(name) }
23
+ attr_names |= self.reflect_on_all_associations.collect { |a| a.name.to_s }
24
+ attr_names |= self.reflect_on_all_aggregations.collect { |a| a.name.to_s }
25
+ end
26
+
27
+ attr_names.each do |attr_name|
28
+ setter_name = "#{attr_name}="
29
+ ub_overwritten_setter = (method_defined?(setter_name) ? instance_method(setter_name) : nil)
30
+ ub_attr_getter = (method_defined?(attr_name) ? instance_method(attr_name) : nil)
31
+ define_method setter_name do |new_value|
32
+ getter = Proc.new { ub_attr_getter ? ub_attr_getter.bind(self).call : read_attribute(attr_name) }
33
+ return if getter.call == new_value
34
+ if getter.call.nil? || (getter.call.is_a?(Array) && getter.call.empty?)
35
+ ub_overwritten_setter ? ub_overwritten_setter.bind(self).call(new_value) : write_attribute(attr_name, new_value)
36
+ else
37
+ raise(ActiveRecord::ImmutableAttributeError, configuration[:message])
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :ensures_immutability_of do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,6 @@
1
+ nil_account:
2
+ id: 1
3
+ username:
4
+ wmoxam:
5
+ id: 2
6
+ username: wmoxam
@@ -0,0 +1,6 @@
1
+ foo:
2
+ id: 1
3
+ text: this is some text
4
+ bar:
5
+ id: 2
6
+ text: this is more text!
@@ -0,0 +1,211 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application and persistence framework that includes everything
4
+ needed to create database-backed web-applications according to the
5
+ Model-View-Control pattern of separation. This pattern splits the view (also
6
+ called the presentation) into "dumb" templates that are primarily responsible
7
+ for inserting pre-built data in between HTML tags. The model contains the
8
+ "smart" domain objects (such as Account, Product, Person, Post) that holds all
9
+ the business logic and knows how to persist themselves to a database. The
10
+ controller handles the incoming requests (such as Save New Account, Update
11
+ Product, Show Post) by manipulating the model and directing data to the view.
12
+
13
+ In Rails, the model is handled by what's called an object-relational mapping
14
+ layer entitled Active Record. This layer allows you to present the data from
15
+ database rows as objects and embellish these data objects with business logic
16
+ methods. You can read more about Active Record in
17
+ link:files/vendor/rails/activerecord/README.html.
18
+
19
+ The controller and view are handled by the Action Pack, which handles both
20
+ layers by its two parts: Action View and Action Controller. These two layers
21
+ are bundled in a single package due to their heavy interdependence. This is
22
+ unlike the relationship between the Active Record and Action Pack that is much
23
+ more separate. Each of these packages can be used independently outside of
24
+ Rails. You can read more about Action Pack in
25
+ link:files/vendor/rails/actionpack/README.html.
26
+
27
+
28
+ == Getting started
29
+
30
+ 1. At the command prompt, start a new rails application using the rails command
31
+ and your application name. Ex: rails myapp
32
+ (If you've downloaded rails in a complete tgz or zip, this step is already done)
33
+ 2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
34
+ 3. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!"
35
+ 4. Follow the guidelines to start developing your application
36
+
37
+
38
+ == Web Servers
39
+
40
+ By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
41
+ Rails will use the WEBrick, the webserver that ships with Ruby. When you run script/server,
42
+ Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
43
+ that you can always get up and running quickly.
44
+
45
+ Mongrel is a Ruby-based webserver with a C-component (which requires compilation) that is
46
+ suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
47
+ getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
48
+ More info at: http://mongrel.rubyforge.org
49
+
50
+ If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
51
+ Mongrel and WEBrick and also suited for production use, but requires additional
52
+ installation and currently only works well on OS X/Unix (Windows users are encouraged
53
+ to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
54
+ http://www.lighttpd.net.
55
+
56
+ And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
57
+ web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
58
+ for production.
59
+
60
+ But of course its also possible to run Rails on any platform that supports FCGI.
61
+ Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
62
+ please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
63
+
64
+
65
+ == Debugging Rails
66
+
67
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
68
+ will help you debug it and get it back on the rails.
69
+
70
+ First area to check is the application log files. Have "tail -f" commands running
71
+ on the server.log and development.log. Rails will automatically display debugging
72
+ and runtime information to these files. Debugging info will also be shown in the
73
+ browser on requests from 127.0.0.1.
74
+
75
+ You can also log your own messages directly into the log file from your code using
76
+ the Ruby logger class from inside your controllers. Example:
77
+
78
+ class WeblogController < ActionController::Base
79
+ def destroy
80
+ @weblog = Weblog.find(params[:id])
81
+ @weblog.destroy
82
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
83
+ end
84
+ end
85
+
86
+ The result will be a message in your log file along the lines of:
87
+
88
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
89
+
90
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
91
+
92
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
93
+
94
+ * The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
95
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
96
+
97
+ These two online (and free) books will bring you up to speed on the Ruby language
98
+ and also on programming in general.
99
+
100
+
101
+ == Breakpoints
102
+
103
+ Breakpoint support is available through the script/breakpointer client. This
104
+ means that you can break out of execution at any point in the code, investigate
105
+ and change the model, AND then resume execution! Example:
106
+
107
+ class WeblogController < ActionController::Base
108
+ def index
109
+ @posts = Post.find(:all)
110
+ breakpoint "Breaking out from the list"
111
+ end
112
+ end
113
+
114
+ So the controller will accept the action, run the first line, then present you
115
+ with a IRB prompt in the breakpointer window. Here you can do things like:
116
+
117
+ Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
118
+
119
+ >> @posts.inspect
120
+ => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
121
+ #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
122
+ >> @posts.first.title = "hello from a breakpoint"
123
+ => "hello from a breakpoint"
124
+
125
+ ...and even better is that you can examine how your runtime objects actually work:
126
+
127
+ >> f = @posts.first
128
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
129
+ >> f.
130
+ Display all 152 possibilities? (y or n)
131
+
132
+ Finally, when you're ready to resume execution, you press CTRL-D
133
+
134
+
135
+ == Console
136
+
137
+ You can interact with the domain model by starting the console through <tt>script/console</tt>.
138
+ Here you'll have all parts of the application configured, just like it is when the
139
+ application is running. You can inspect domain models, change values, and save to the
140
+ database. Starting the script without arguments will launch it in the development environment.
141
+ Passing an argument will specify a different environment, like <tt>script/console production</tt>.
142
+
143
+ To reload your controllers and models after launching the console run <tt>reload!</tt>
144
+
145
+ To reload your controllers and models after launching the console run <tt>reload!</tt>
146
+
147
+
148
+
149
+ == Description of contents
150
+
151
+ app
152
+ Holds all the code that's specific to this particular application.
153
+
154
+ app/controllers
155
+ Holds controllers that should be named like weblogs_controller.rb for
156
+ automated URL mapping. All controllers should descend from ApplicationController
157
+ which itself descends from ActionController::Base.
158
+
159
+ app/models
160
+ Holds models that should be named like post.rb.
161
+ Most models will descend from ActiveRecord::Base.
162
+
163
+ app/views
164
+ Holds the template files for the view that should be named like
165
+ weblogs/index.rhtml for the WeblogsController#index action. All views use eRuby
166
+ syntax.
167
+
168
+ app/views/layouts
169
+ Holds the template files for layouts to be used with views. This models the common
170
+ header/footer method of wrapping views. In your views, define a layout using the
171
+ <tt>layout :default</tt> and create a file named default.rhtml. Inside default.rhtml,
172
+ call <% yield %> to render the view using this layout.
173
+
174
+ app/helpers
175
+ Holds view helpers that should be named like weblogs_helper.rb. These are generated
176
+ for you automatically when using script/generate for controllers. Helpers can be used to
177
+ wrap functionality for your views into methods.
178
+
179
+ config
180
+ Configuration files for the Rails environment, the routing map, the database, and other dependencies.
181
+
182
+ components
183
+ Self-contained mini-applications that can bundle together controllers, models, and views.
184
+
185
+ db
186
+ Contains the database schema in schema.rb. db/migrate contains all
187
+ the sequence of Migrations for your schema.
188
+
189
+ doc
190
+ This directory is where your application documentation will be stored when generated
191
+ using <tt>rake doc:app</tt>
192
+
193
+ lib
194
+ Application specific libraries. Basically, any kind of custom code that doesn't
195
+ belong under controllers, models, or helpers. This directory is in the load path.
196
+
197
+ public
198
+ The directory available for the web server. Contains subdirectories for images, stylesheets,
199
+ and javascripts. Also contains the dispatchers and the default HTML files. This should be
200
+ set as the DOCUMENT_ROOT of your web server.
201
+
202
+ script
203
+ Helper scripts for automation and generation.
204
+
205
+ test
206
+ Unit and functional tests along with fixtures. When using the script/generate scripts, template
207
+ test files will be generated for you and placed in this directory.
208
+
209
+ vendor
210
+ External libraries that the application depends on. Also includes the plugins subdirectory.
211
+ This directory is in the load path.
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/rails'
@@ -0,0 +1,7 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ # Pick a unique cookie name to distinguish our session data from others'
6
+ session :session_key => '_rail_root_session_id'
7
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,6 @@
1
+ class Account < ActiveRecord::Base
2
+ has_many :infos
3
+ has_one :info
4
+
5
+ ensures_immutability_of :username, :infos, :info
6
+ end
@@ -0,0 +1,3 @@
1
+ class Info < ActiveRecord::Base
2
+ belongs_to :account
3
+ end
@@ -0,0 +1,39 @@
1
+ # Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb
2
+
3
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
4
+
5
+ unless defined?(Rails::Initializer)
6
+ if File.directory?("#{RAILS_ROOT}/vendor/rails")
7
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
8
+ else
9
+ require 'rubygems'
10
+
11
+ rails_gem_version =
12
+ if defined? RAILS_GEM_VERSION
13
+ RAILS_GEM_VERSION
14
+ else
15
+ File.read("#{File.dirname(__FILE__)}/environment.rb") =~ /^[^#]*RAILS_GEM_VERSION\s+=\s+'([\d.]+)'/
16
+ $1
17
+ end
18
+
19
+ if rails_gem_version
20
+ rails_gem = Gem.cache.search('rails', "=#{rails_gem_version}.0").sort_by { |g| g.version.version }.last
21
+
22
+ if rails_gem
23
+ gem "rails", "=#{rails_gem.version.version}"
24
+ require rails_gem.full_gem_path + '/lib/initializer'
25
+ else
26
+ STDERR.puts %(Cannot find gem for Rails =#{rails_gem_version}.0:
27
+ Install the missing gem with 'gem install -v=#{rails_gem_version} rails', or
28
+ change environment.rb to define RAILS_GEM_VERSION with your desired version.
29
+ )
30
+ exit 1
31
+ end
32
+ else
33
+ gem "rails"
34
+ require 'initializer'
35
+ end
36
+ end
37
+
38
+ Rails::Initializer.run(:set_load_path)
39
+ end
@@ -0,0 +1,18 @@
1
+ sqlite:
2
+ :adapter: sqlite
3
+ :dbfile: ensures_immunibility_of_test.sqlite.db
4
+ sqlite3:
5
+ :adapter: sqlite3
6
+ :dbfile: ensures_immunibility_of_test.sqlite3.db
7
+ postgresql:
8
+ :adapter: postgresql
9
+ :username: postgres
10
+ :password: postgres
11
+ :database: ensures_immunibility_of_test
12
+ :min_messages: ERROR
13
+ mysql:
14
+ :adapter: mysql
15
+ :host: localhost
16
+ :username: root
17
+ :password:
18
+ :database: ensures_immunibility_of_test
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), 'boot')
2
+
3
+ Rails::Initializer.run do |config|
4
+ config.log_level = :debug
5
+ config.cache_classes = false
6
+ config.whiny_nils = true
7
+ config.breakpoint_server = true
8
+ config.load_paths << "#{File.dirname(__FILE__)}/../../../lib/"
9
+ end
10
+
11
+ Dependencies.log_activity = true
@@ -0,0 +1,21 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # In the development environment your application's code is reloaded on
4
+ # every request. This slows down response time but is perfect for development
5
+ # since you don't have to restart the webserver when you make code changes.
6
+ config.cache_classes = false
7
+
8
+ # Log error messages when you accidentally call methods on nil.
9
+ config.whiny_nils = true
10
+
11
+ # Enable the breakpoint server that script/breakpointer connects to
12
+ config.breakpoint_server = true
13
+
14
+ # Show full error reports and disable caching
15
+ config.action_controller.consider_all_requests_local = true
16
+ config.action_controller.perform_caching = false
17
+ config.action_view.cache_template_extensions = false
18
+ config.action_view.debug_rjs = true
19
+
20
+ # Don't care if the mailer can't send
21
+ config.action_mailer.raise_delivery_errors = false