bd_money 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.2
1
+ 0.0.3
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bd_money}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Adrian Madrid"]
@@ -22,17 +22,22 @@ module ActiveRecord #:nodoc:
22
22
  end
23
23
 
24
24
  module ClassMethods
25
- def money(name, options = { })
26
- define_method "#{name}=" do |value|
27
- if value.present?
28
- self[name] = ::Money.new(value, options[:precision], options[:round_mode]).amount
29
- else
30
- self[name] = nil
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
@@ -15,8 +15,7 @@ end
15
15
  class DefaultLoanExample < ActiveRecord::Base
16
16
  set_table_name "money_examples"
17
17
 
18
- money :amount
19
- money :apr
18
+ money :amount, :apr
20
19
  end
21
20
 
22
21
  class BetterLoanExample < ActiveRecord::Base
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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adrian Madrid