bd_money 0.0.2 → 0.0.3
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.
- data/README.rdoc +2 -1
- data/VERSION +1 -1
- data/bd_money.gemspec +1 -1
- data/lib/bd_money/rails.rb +15 -10
- data/spec/rails_spec.rb +1 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -54,7 +54,8 @@ There is a rails extension that makes it easier to store money values in the dat
|
|
54
54
|
require 'bd_money/rails'
|
55
55
|
|
56
56
|
class Product < ActiveRecord::Base
|
57
|
-
money :price
|
57
|
+
money :cost, :price, :round_mode => :floor
|
58
|
+
validates_numericality_of :cost, :greater_than => 0
|
58
59
|
validates_numericality_of :price, :greater_than => 0
|
59
60
|
end
|
60
61
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/bd_money.gemspec
CHANGED
data/lib/bd_money/rails.rb
CHANGED
@@ -22,17 +22,22 @@ module ActiveRecord #:nodoc:
|
|
22
22
|
end
|
23
23
|
|
24
24
|
module ClassMethods
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
# Pass list of fields you want to use as Money. You can also pass a hash in the end to indicate your
|
26
|
+
# preferences for :precision and :round_mode.
|
27
|
+
def money(*names)
|
28
|
+
options = names.extract_options!
|
29
|
+
names.each do |name|
|
30
|
+
define_method "#{name}=" do |value|
|
31
|
+
if value.present?
|
32
|
+
self[name] = ::Money.new(value, options[:precision], options[:round_mode]).amount
|
33
|
+
else
|
34
|
+
self[name] = nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
define_method "#{name}" do
|
38
|
+
return nil unless self[name].present?
|
39
|
+
::Money.new self[name], options[:precision], options[:round_mode]
|
31
40
|
end
|
32
|
-
end
|
33
|
-
define_method "#{name}" do
|
34
|
-
return nil unless self[name].present?
|
35
|
-
::Money.new self[name], options[:precision], options[:round_mode]
|
36
41
|
end
|
37
42
|
end
|
38
43
|
end
|
data/spec/rails_spec.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bd_money
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adrian Madrid
|