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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37b04a7be15864c3d863599f9459d060fb4438ee
4
- data.tar.gz: 60663ea37c3f404e17af412b7243d7dfc1844c72
3
+ metadata.gz: 06fe320d8e4a586f4c77666ad7b84724dda8131d
4
+ data.tar.gz: 78fa897739471e33e09f80a25ae127284434041f
5
5
  SHA512:
6
- metadata.gz: c0c1209bf5dbbae3363bd3ef19bd5dd0e4685357a874f8074e0a1948b40ebe55da05248aa90c335cdea61b5af0ab1a125239b1a275cbccff0ea0876a7d880de6
7
- data.tar.gz: 110bd949e2b5077755d4f736e91e46167d6fc7e89ffadfd2f78cd6777b0730def9c9c2c811697a4eac059678a6ca73fe7c2220c0b058aeed250ac5aa8cdc75f0
6
+ metadata.gz: 770d0661ee7e420da951020b5b63ad584d3e6d211e129855d0994f95f8a4a45f31df1ca0f4724855f757d5ab8afc417ab354f2bf8c4e3e8f8c7c065e6deebb6f
7
+ data.tar.gz: 2d78aec95f0f07fbf2bfbf7d12d08ff8f7d938fb4337536de8377dba0305d7c53315d9053fb1eca66940fceec3a82a5a708edde784d1ce6cf5563e5cf3114dde
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.12.0
4
+
5
+ - Bump money version to ~> 6.12.0
6
+ - Bump monetize version to ~> 1.9.0
7
+
3
8
  ## 1.11.0
4
9
 
5
10
  - Bump money version to ~> 6.11.0
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 and record_does_not_have_error?
36
+ if stringy && record_does_not_have_error?
37
37
  add_error if
38
- value_has_too_many_decimal_points or
39
- thousand_separator_after_decimal_mark or
38
+ value_has_too_many_decimal_points ||
39
+ thousand_separator_after_decimal_mark ||
40
40
  invalid_thousands_separation
41
41
  end
42
42
  end
@@ -1,3 +1,3 @@
1
1
  module MoneyRails
2
- VERSION = '1.11.0'
2
+ VERSION = '1.12.0'
3
3
  end
@@ -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.11.0"
30
- s.add_dependency "monetize", "~> 1.7.0"
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.11.0
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-04-10 00:00:00.000000000 Z
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.11.0
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.11.0
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.7.0
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.7.0
42
+ version: 1.9.0
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: activesupport
45
45
  requirement: !ruby/object:Gem::Requirement