forked from RubyMoney/money-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
289 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## MAC OS | ||
.DS_Store | ||
|
||
## TEXTMATE | ||
*.tmproj | ||
tmtags | ||
|
||
## EMACS | ||
*~ | ||
\#* | ||
.\#* | ||
|
||
## VIM | ||
*.swp | ||
|
||
## Rubymine | ||
.idea | ||
|
||
## PROJECT::GENERAL | ||
coverage | ||
rdoc | ||
pkg | ||
*.rbc | ||
.rvmrc | ||
|
||
## PROJECT::SPECIFIC | ||
.yardoc | ||
doc | ||
.rbenv-version | ||
.rbx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rake' | ||
|
||
group :test do | ||
gem 'rspec' | ||
end | ||
|
||
group :test, :development do | ||
gem 'rails', '>= 3.0.0' | ||
end | ||
|
||
# dependencies in money-rails.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
money-rails (0.0.1) | ||
activesupport (>= 3.0) | ||
money (~> 4.0.2) | ||
railties (>= 3.0) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
actionmailer (3.2.2) | ||
actionpack (= 3.2.2) | ||
mail (~> 2.4.0) | ||
actionpack (3.2.2) | ||
activemodel (= 3.2.2) | ||
activesupport (= 3.2.2) | ||
builder (~> 3.0.0) | ||
erubis (~> 2.7.0) | ||
journey (~> 1.0.1) | ||
rack (~> 1.4.0) | ||
rack-cache (~> 1.1) | ||
rack-test (~> 0.6.1) | ||
sprockets (~> 2.1.2) | ||
activemodel (3.2.2) | ||
activesupport (= 3.2.2) | ||
builder (~> 3.0.0) | ||
activerecord (3.2.2) | ||
activemodel (= 3.2.2) | ||
activesupport (= 3.2.2) | ||
arel (~> 3.0.2) | ||
tzinfo (~> 0.3.29) | ||
activeresource (3.2.2) | ||
activemodel (= 3.2.2) | ||
activesupport (= 3.2.2) | ||
activesupport (3.2.2) | ||
i18n (~> 0.6) | ||
multi_json (~> 1.0) | ||
arel (3.0.2) | ||
builder (3.0.0) | ||
diff-lcs (1.1.3) | ||
erubis (2.7.0) | ||
hike (1.2.1) | ||
i18n (0.6.0) | ||
journey (1.0.3) | ||
json (1.6.6) | ||
mail (2.4.4) | ||
i18n (>= 0.4.0) | ||
mime-types (~> 1.16) | ||
treetop (~> 1.4.8) | ||
mime-types (1.18) | ||
money (4.0.2) | ||
i18n (~> 0.4) | ||
json | ||
multi_json (1.2.0) | ||
polyglot (0.3.3) | ||
rack (1.4.1) | ||
rack-cache (1.2) | ||
rack (>= 0.4) | ||
rack-ssl (1.3.2) | ||
rack | ||
rack-test (0.6.1) | ||
rack (>= 1.0) | ||
rails (3.2.2) | ||
actionmailer (= 3.2.2) | ||
actionpack (= 3.2.2) | ||
activerecord (= 3.2.2) | ||
activeresource (= 3.2.2) | ||
activesupport (= 3.2.2) | ||
bundler (~> 1.0) | ||
railties (= 3.2.2) | ||
railties (3.2.2) | ||
actionpack (= 3.2.2) | ||
activesupport (= 3.2.2) | ||
rack-ssl (~> 1.3.2) | ||
rake (>= 0.8.7) | ||
rdoc (~> 3.4) | ||
thor (~> 0.14.6) | ||
rake (0.9.2.2) | ||
rdoc (3.12) | ||
json (~> 1.4) | ||
rspec (2.9.0) | ||
rspec-core (~> 2.9.0) | ||
rspec-expectations (~> 2.9.0) | ||
rspec-mocks (~> 2.9.0) | ||
rspec-core (2.9.0) | ||
rspec-expectations (2.9.0) | ||
diff-lcs (~> 1.1.3) | ||
rspec-mocks (2.9.0) | ||
sprockets (2.1.2) | ||
hike (~> 1.2) | ||
rack (~> 1.0) | ||
tilt (~> 1.1, != 1.3.0) | ||
thor (0.14.6) | ||
tilt (1.3.3) | ||
treetop (1.4.10) | ||
polyglot | ||
polyglot (>= 0.3.1) | ||
tzinfo (0.3.32) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
money-rails! | ||
rails (>= 3.0.0) | ||
rake | ||
rspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2012 Andreas Loupasakis | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require "money" | ||
|
||
require "money-rails/version" | ||
require "money-rails/monetize" | ||
require "money-rails/railtie" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'active_support/concern' | ||
require 'active_support/core_ext/array/extract_options' | ||
|
||
module MoneyRails | ||
module Monetizable | ||
extend ActiveSupport::Concern | ||
|
||
module ClassMethods | ||
def monetize(field, *args) | ||
options = args.extract_options! | ||
|
||
# Stringify model field name | ||
subunit_name = field.to_s | ||
|
||
# Model currency field name | ||
model_currency_name = options[:model_currency] || "currency" | ||
|
||
# Override Model and default currency | ||
field_currency_name = options[:field_currency] || nil | ||
|
||
# Form target name for the money backed ActiveModel field: | ||
# if a target name is provided then use it | ||
# if there is a "_cents" suffix then just remove it to create the target name | ||
# if none of the previous is the case then use a default suffix | ||
if options[:target_name] | ||
name = options[:target_name].to_s | ||
elsif subunit_name =~ /_cents$/ | ||
name = subunit_name.sub(/_cents$/, "") | ||
else | ||
# FIXME: provide a better default | ||
name = subunit_name << "_money" | ||
end | ||
|
||
class_eval do | ||
composed_of name.to_sym, | ||
:class_name => "Money", | ||
:mapping => [[subunit_name, "cents"], [model_currency_name, "currency_as_string"]], | ||
:constructor => Proc.new { |cents, currency| | ||
Money.new(cents || 0, field_currency_name || currency || | ||
Money.default_currency) | ||
}, | ||
:converter => Proc.new { |value| | ||
if value.respond_to?(:to_money) | ||
if field_currency_name | ||
value.to_money(field_currency_name) | ||
else | ||
value.to_money | ||
end | ||
else | ||
raise(ArgumentError, "Can't convert #{value.class} to Money") | ||
end | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module MoneyRails | ||
module Monetizable | ||
class Railtie < ::Rails::Railtie | ||
ActiveRecord::Base.send :include, Monetizable | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module MoneyRails | ||
VERSION = "0.0.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- encoding: utf-8 -*- | ||
require File.expand_path('../lib/money-rails/version', __FILE__) | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "money-rails" | ||
s.version = MoneyRails::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.license = "MIT" | ||
s.authors = ["Andreas Loupasakis", "Shane Emmons", "Simone Carletti"] | ||
s.email = ["[email protected]"] | ||
s.description = %q{This library provides integration of RubyMoney - Money gem with Rails} | ||
s.summary = %q{Money gem integration with Rails} | ||
s.homepage = "https://github.com/RubyMoney/money" | ||
|
||
# s.files = `git ls-files`.split($\) | ||
s.files = Dir.glob("{lib,spec}/**/*") | ||
s.files += %w(LICENSE README.md) | ||
s.files += %w(money-rails.gemspec) | ||
|
||
|
||
s.test_files = s.files.grep(%r{^(test|spec|features)/}) | ||
|
||
s.require_path = "lib" | ||
|
||
s.add_dependency(%q<money>, [">= 4.0.2"]) | ||
s.add_dependency(%q<activesupport>, [">= 3.0"]) | ||
s.add_dependency(%q<railties>, [">= 3.0"]) | ||
end |