Skip to content

Commit

Permalink
trivial plugin to ease the use of the Money gem
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Sep 18, 2006
0 parents commit 7d6dd79
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README
@@ -0,0 +1,4 @@
Money
=====

Description goes here
22 changes: 22 additions & 0 deletions Rakefile
@@ -0,0 +1,22 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

desc 'Default: run unit tests.'
task :default => :test

desc 'Test the money plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Generate documentation for the money plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Money'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
3 changes: 3 additions & 0 deletions init.rb
@@ -0,0 +1,3 @@
require 'acts_as_money'

ActiveRecord::Base.send :include, CollectiveIdea::Acts::Money
1 change: 1 addition & 0 deletions install.rb
@@ -0,0 +1 @@
# Install hook code here
29 changes: 29 additions & 0 deletions lib/acts_as_money.rb
@@ -0,0 +1,29 @@
require 'money'

module CollectiveIdea #:nodoc:
module Acts
module Money #:nodoc:
def self.included(base) #:nodoc:
base.extend ClassMethods
end

module ClassMethods
def money(name, options = {})
options = {:cents => :cents, :currency => :currency}.merge(options)

module_eval <<-end_eval
composed_of :composed_of_#{name}, :class_name => 'Money',
:mapping => [%w(#{options[:cents]} cents), %w(#{options[:currency] || nil} currency)]
def #{name}=(part)
self.composed_of_#{name} = part.is_a?(Money) ? part : part.to_money
end
def #{name}(force_reload = false)
self.composed_of_#{name} unless #{options[:cents]}.blank?
end
end_eval
end
end
end
end
end
4 changes: 4 additions & 0 deletions tasks/money_tasks.rake
@@ -0,0 +1,4 @@
# desc "Explaining what the task does"
# task :money do
# # Task goes here
# end
8 changes: 8 additions & 0 deletions test/money_test.rb
@@ -0,0 +1,8 @@
require 'test/unit'

class MoneyTest < Test::Unit::TestCase
# Replace this with your real tests.
def test_this_plugin
flunk
end
end

0 comments on commit 7d6dd79

Please sign in to comment.