money-rails 1.11.0 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +25 -2
- data/lib/money-rails/active_model/validator.rb +3 -3
- data/lib/money-rails/version.rb +1 -1
- data/money-rails.gemspec +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06fe320d8e4a586f4c77666ad7b84724dda8131d
|
4
|
+
data.tar.gz: 78fa897739471e33e09f80a25ae127284434041f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 770d0661ee7e420da951020b5b63ad584d3e6d211e129855d0994f95f8a4a45f31df1ca0f4724855f757d5ab8afc417ab354f2bf8c4e3e8f8c7c065e6deebb6f
|
7
|
+
data.tar.gz: 2d78aec95f0f07fbf2bfbf7d12d08ff8f7d938fb4337536de8377dba0305d7c53315d9053fb1eca66940fceec3a82a5a708edde784d1ce6cf5563e5cf3114dde
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/money-rails.svg)](http://badge.fury.io/rb/money-rails)
|
4
4
|
[![Build Status](https://secure.travis-ci.org/RubyMoney/money-rails.svg?branch=master)](http://travis-ci.org/RubyMoney/money-rails)
|
5
|
-
[![Dependency Status](https://gemnasium.com/RubyMoney/money-rails.svg)](https://gemnasium.com/RubyMoney/money-rails)
|
6
5
|
[![Code Climate](https://codeclimate.com/github/RubyMoney/money-rails.svg)](https://codeclimate.com/github/RubyMoney/money-rails)
|
7
6
|
[![License](http://img.shields.io/:license-mit-green.svg?style=flat)](http://opensource.org/licenses/MIT)
|
8
7
|
|
@@ -306,7 +305,7 @@ object using EUR as their currency, instead of the default USD.
|
|
306
305
|
#### Attribute Currency (:with_currency)
|
307
306
|
|
308
307
|
By passing the option ```:with_currency``` to the ```monetize``` macro call,
|
309
|
-
with a currency code as its value, you can define a currency in a more granular
|
308
|
+
with a currency code (symbol or string) or a callable object (object that responds to the method ```call```) that returns a currency code, as its value, you can define a currency in a more granular
|
310
309
|
way. This will you attach the given currency only to the specified monetized model
|
311
310
|
attribute (allowing you to, for example, monetize different attributes of the same model with different currencies.).
|
312
311
|
|
@@ -329,6 +328,30 @@ end
|
|
329
328
|
In this case ```product.bonus``` will return a Money object with GBP as its
|
330
329
|
currency, whereas ```product.discount.currency_as_string # => EUR ```
|
331
330
|
|
331
|
+
As mentioned earlier you can use an object that responds to the method ```call``` and accepts the model instance as a parameter. That means you can use a ```Proc``` or ```lambda``` (we would recommend ```lambda``` over ```Proc``` because of their [different control flow characteristics](https://stackoverflow.com/questions/1740046/whats-the-difference-between-a-proc-and-a-lambda-in-ruby)) or even define a separate ```class``` with an instance or class method (maybe even a ```module```) to return the currency code:
|
332
|
+
|
333
|
+
```ruby
|
334
|
+
class DeliveryFee
|
335
|
+
def call(product)
|
336
|
+
# some logic here that will return a currency code
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
module OptionalPrice
|
341
|
+
def self.call(product)
|
342
|
+
# some logic here that will return a currency code
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
# app/models/product.rb
|
347
|
+
class Product < ActiveRecord::Base
|
348
|
+
|
349
|
+
monetize :price_cents, with_currency: ->(_product) { :gbp }
|
350
|
+
monetize :delivery_fee_cents, with_currency: DeliveryFee.new
|
351
|
+
monetize :optional_price_cents, with_currency: OptionalPrice
|
352
|
+
end
|
353
|
+
```
|
354
|
+
|
332
355
|
#### Instance Currencies
|
333
356
|
|
334
357
|
All the previous options do not require any extra model fields to hold
|
@@ -33,10 +33,10 @@ module MoneyRails
|
|
33
33
|
normalize_raw_value!
|
34
34
|
super(@record, @attr, @raw_value)
|
35
35
|
|
36
|
-
if stringy
|
36
|
+
if stringy && record_does_not_have_error?
|
37
37
|
add_error if
|
38
|
-
value_has_too_many_decimal_points
|
39
|
-
thousand_separator_after_decimal_mark
|
38
|
+
value_has_too_many_decimal_points ||
|
39
|
+
thousand_separator_after_decimal_mark ||
|
40
40
|
invalid_thousands_separation
|
41
41
|
end
|
42
42
|
end
|
data/lib/money-rails/version.rb
CHANGED
data/money-rails.gemspec
CHANGED
@@ -26,8 +26,8 @@ Gem::Specification.new do |s|
|
|
26
26
|
|
27
27
|
s.require_path = "lib"
|
28
28
|
|
29
|
-
s.add_dependency "money", "~> 6.
|
30
|
-
s.add_dependency "monetize", "~> 1.
|
29
|
+
s.add_dependency "money", "~> 6.12.0"
|
30
|
+
s.add_dependency "monetize", "~> 1.9.0"
|
31
31
|
s.add_dependency "activesupport", ">= 3.0"
|
32
32
|
s.add_dependency "railties", ">= 3.0"
|
33
33
|
s.add_dependency "mime-types", "< 3" if RUBY_VERSION < '2.0' # mime-types > 3 depends on mime-types-data, which doesn't support ruby 1.9
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Loupasakis
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-
|
13
|
+
date: 2018-09-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: money
|
@@ -18,28 +18,28 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 6.
|
21
|
+
version: 6.12.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 6.
|
28
|
+
version: 6.12.0
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: monetize
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 1.
|
35
|
+
version: 1.9.0
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 1.
|
42
|
+
version: 1.9.0
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: activesupport
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|