money-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Andreas Loupasakis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # RubyMoney - Money-Rails
2
+
3
+
4
+ ## Introduction
5
+
6
+ This library provides integration of [money](http://github.com/Rubymoney/money) gem with Rails.
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'money-rails'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install money-rails
@@ -0,0 +1,5 @@
1
+ require "money"
2
+
3
+ require "money-rails/version"
4
+ require "money-rails/monetize"
5
+ require "money-rails/railtie"
@@ -0,0 +1,57 @@
1
+ require 'active_support/concern'
2
+ require 'active_support/core_ext/array/extract_options'
3
+
4
+ module MoneyRails
5
+ module Monetizable
6
+ extend ActiveSupport::Concern
7
+
8
+ module ClassMethods
9
+ def monetize(field, *args)
10
+ options = args.extract_options!
11
+
12
+ # Stringify model field name
13
+ subunit_name = field.to_s
14
+
15
+ # Model currency field name
16
+ model_currency_name = options[:model_currency] || "currency"
17
+
18
+ # Override Model and default currency
19
+ field_currency_name = options[:field_currency] || nil
20
+
21
+ # Form target name for the money backed ActiveModel field:
22
+ # if a target name is provided then use it
23
+ # if there is a "_cents" suffix then just remove it to create the target name
24
+ # if none of the previous is the case then use a default suffix
25
+ if options[:target_name]
26
+ name = options[:target_name].to_s
27
+ elsif subunit_name =~ /_cents$/
28
+ name = subunit_name.sub(/_cents$/, "")
29
+ else
30
+ # FIXME: provide a better default
31
+ name = subunit_name << "_money"
32
+ end
33
+
34
+ class_eval do
35
+ composed_of name.to_sym,
36
+ :class_name => "Money",
37
+ :mapping => [[subunit_name, "cents"], [model_currency_name, "currency_as_string"]],
38
+ :constructor => Proc.new { |cents, currency|
39
+ Money.new(cents || 0, field_currency_name || currency ||
40
+ Money.default_currency)
41
+ },
42
+ :converter => Proc.new { |value|
43
+ if value.respond_to?(:to_money)
44
+ if field_currency_name
45
+ value.to_money(field_currency_name)
46
+ else
47
+ value.to_money
48
+ end
49
+ else
50
+ raise(ArgumentError, "Can't convert #{value.class} to Money")
51
+ end
52
+ }
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,7 @@
1
+ module MoneyRails
2
+ module Monetizable
3
+ class Railtie < ::Rails::Railtie
4
+ ActiveRecord::Base.send :include, Monetizable
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module MoneyRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/money-rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "money-rails"
6
+ s.version = MoneyRails::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.license = "MIT"
9
+ s.authors = ["Andreas Loupasakis", "Shane Emmons", "Simone Carletti"]
10
+ s.email = ["alup.rubymoney@gmail.com"]
11
+ s.description = %q{This library provides integration of RubyMoney - Money gem with Rails}
12
+ s.summary = %q{Money gem integration with Rails}
13
+ s.homepage = "https://github.com/RubyMoney/money"
14
+
15
+ # s.files = `git ls-files`.split($\)
16
+ s.files = Dir.glob("{lib,spec}/**/*")
17
+ s.files += %w(LICENSE README.md)
18
+ s.files += %w(money-rails.gemspec)
19
+
20
+
21
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
22
+
23
+ s.require_path = "lib"
24
+
25
+ s.add_dependency(%q<money>, [">= 4.0.2"])
26
+ s.add_dependency(%q<activesupport>, [">= 3.0"])
27
+ s.add_dependency(%q<railties>, [">= 3.0"])
28
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: money-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andreas Loupasakis
9
+ - Shane Emmons
10
+ - Simone Carletti
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-03-30 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: money
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: 4.0.2
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: 4.0.2
32
+ - !ruby/object:Gem::Dependency
33
+ name: activesupport
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: railties
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '3.0'
64
+ description: This library provides integration of RubyMoney - Money gem with Rails
65
+ email:
66
+ - alup.rubymoney@gmail.com
67
+ executables: []
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - lib/money-rails.rb
72
+ - lib/money-rails/railtie.rb
73
+ - lib/money-rails/version.rb
74
+ - lib/money-rails/monetize.rb
75
+ - LICENSE
76
+ - README.md
77
+ - money-rails.gemspec
78
+ homepage: https://github.com/RubyMoney/money
79
+ licenses:
80
+ - MIT
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 1.8.21
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Money gem integration with Rails
103
+ test_files: []
104
+ has_rdoc: