money-rails 2.0.0 → 3.0.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +79 -68
- data/lib/money-rails/active_job/money_serializer.rb +4 -0
- data/lib/money-rails/active_record/monetizable.rb +24 -14
- data/lib/money-rails/hooks.rb +5 -27
- data/lib/money-rails/mongoid/money.rb +4 -14
- data/lib/money-rails/test_helpers.rb +4 -4
- data/lib/money-rails/version.rb +1 -1
- data/lib/money-rails.rb +2 -0
- data/money-rails.gemspec +2 -2
- metadata +9 -10
- data/lib/money-rails/mongoid/two.rb +0 -35
- /data/lib/money-rails/active_record/migration_extensions/{schema_statements_pg_rails4.rb → schema_statements_pg.rb} +0 -0
- /data/lib/money-rails/active_record/migration_extensions/{table_pg_rails4.rb → table_pg.rb} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cb63337354249ecd15c15695c269080edb51883d30b78f833256dbc1222a86b9
|
|
4
|
+
data.tar.gz: 809dcf758b84ae3a66edf286691f031dfc5fb68706cc604742fc5230e7a27c3b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f52ce4f9d92e1352a962147882337fb17c04961b0b935760e0011d3d1d3a433250fe0d0cc3d9837943c912b48dda94b0dcdb82919f9fd98334ef894601e4f82b
|
|
7
|
+
data.tar.gz: 0d0fb9c5ef2adb1db3d1de67b7799059cedb5fb52610dc5eb44f605a31e398e37852f51bb583b039fec7ffd05b17a89abf1f9cb8889969078fdcf3c9d34b745a
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 3.0.0
|
|
6
|
+
|
|
7
|
+
- **Breaking change**: Drop support for Rails < 7.0
|
|
8
|
+
- Allow `super` when overriding methods
|
|
9
|
+
- Fix `MoneyRails::ActionViewExtension` not available during eager loading (#614)
|
|
10
|
+
- Fix deprecation warning on the ActiveJob serializer to support future Rails 8.2 (#729)
|
|
11
|
+
- Support Mongoid 8.x and 9.x
|
|
12
|
+
- `MoneyRails::TestHelpers` can be used in Minitest
|
|
13
|
+
|
|
5
14
|
## 2.0.0
|
|
6
15
|
|
|
7
16
|
- **Breaking change**: Requires `money` gem version ~> 7.0.
|
data/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# RubyMoney - Money-Rails
|
|
2
2
|
|
|
3
|
-
[](
|
|
3
|
+
[](https://rubygems.org/gems/money-rails)
|
|
4
4
|
[](https://github.com/RubyMoney/money-rails/actions/workflows/ruby.yml)
|
|
5
|
-
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
|
|
7
7
|
## Introduction
|
|
8
8
|
|
|
9
|
-
This library provides integration of the [money](
|
|
9
|
+
This library provides integration of the [money](https://github.com/Rubymoney/money) gem with Rails.
|
|
10
10
|
|
|
11
11
|
Use `monetize` to specify which fields you want to be backed by
|
|
12
|
-
Money objects and helpers provided by the [money](
|
|
12
|
+
Money objects and helpers provided by the [money](https://github.com/Rubymoney/money)
|
|
13
13
|
gem.
|
|
14
14
|
|
|
15
15
|
Currently, this library is in active development mode, so if you would
|
|
@@ -130,9 +130,9 @@ monetize :optional_price_cents, allow_nil: true
|
|
|
130
130
|
# in Migration
|
|
131
131
|
def change
|
|
132
132
|
add_monetize :products,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
:optional_price,
|
|
134
|
+
amount: { null: true, default: nil },
|
|
135
|
+
currency: { null: true, default: nil }
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
# now blank assignments are permitted
|
|
@@ -156,7 +156,7 @@ end
|
|
|
156
156
|
#### Numericality validation options
|
|
157
157
|
|
|
158
158
|
You can also pass along
|
|
159
|
-
[numericality validation options](
|
|
159
|
+
[numericality validation options](https://guides.rubyonrails.org/active_record_validations.html#numericality)
|
|
160
160
|
such as this:
|
|
161
161
|
|
|
162
162
|
```ruby
|
|
@@ -187,14 +187,14 @@ And you can also use `subunit_numericality` for subunit:
|
|
|
187
187
|
|
|
188
188
|
```ruby
|
|
189
189
|
monetize :price_in_a_range_cents,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
190
|
+
allow_nil: true,
|
|
191
|
+
subunit_numericality: {
|
|
192
|
+
greater_than_or_equal_to: 0,
|
|
193
|
+
less_than_or_equal_to: 100_00
|
|
194
|
+
}
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
-
### Mongoid
|
|
197
|
+
### Mongoid
|
|
198
198
|
|
|
199
199
|
`Money` is available as a field type to supply during a field definition:
|
|
200
200
|
|
|
@@ -274,18 +274,14 @@ from a field in a configuration model called `Tenant` in this example:
|
|
|
274
274
|
|
|
275
275
|
```ruby
|
|
276
276
|
# config/initializers/money.rb
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
277
|
+
ActiveSupport::Reloader.to_prepare do
|
|
278
|
+
MoneyRails.configure do |config|
|
|
279
|
+
# set the default currency based on client configuration
|
|
280
|
+
config.default_currency = -> { Tenant.current.default_currency }
|
|
281
|
+
end
|
|
280
282
|
end
|
|
281
283
|
```
|
|
282
284
|
|
|
283
|
-
Be aware that this **does not work in Rails 7+**, as the lambda is evaluated
|
|
284
|
-
immediately, and therefore requires your model to be already loaded.
|
|
285
|
-
Workarounds include wrapping the initialization in
|
|
286
|
-
`ActiveSupport::Reloader.to_prepare`, or creating a function that rescues
|
|
287
|
-
unloaded constants with an initialization-time default, and running that in your lambda.
|
|
288
|
-
|
|
289
285
|
In many cases this is not enough, so there are some other options to
|
|
290
286
|
meet your needs.
|
|
291
287
|
|
|
@@ -308,7 +304,7 @@ end
|
|
|
308
304
|
Now `product.discount` and `product.bonus` will return a `Money` object using
|
|
309
305
|
EUR as their currency, instead of the default USD.
|
|
310
306
|
|
|
311
|
-
(This is not available in
|
|
307
|
+
(This is not available in Mongoid).
|
|
312
308
|
|
|
313
309
|
#### Attribute Currency (`:with_currency`)
|
|
314
310
|
|
|
@@ -377,9 +373,6 @@ currency values, so they have the highest precedence.
|
|
|
377
373
|
|
|
378
374
|
```ruby
|
|
379
375
|
class Transaction < ActiveRecord::Base
|
|
380
|
-
# This model has a separate currency column
|
|
381
|
-
attr_accessible :amount_cents, :currency, :tax_cents
|
|
382
|
-
|
|
383
376
|
# Use model level currency
|
|
384
377
|
register_currency :gbp
|
|
385
378
|
|
|
@@ -422,37 +415,39 @@ MoneyRails.configure do |config|
|
|
|
422
415
|
|
|
423
416
|
# Default ActiveRecord migration configuration values for columns:
|
|
424
417
|
#
|
|
425
|
-
# config.amount_column = {
|
|
426
|
-
#
|
|
427
|
-
#
|
|
428
|
-
#
|
|
429
|
-
#
|
|
430
|
-
#
|
|
431
|
-
#
|
|
432
|
-
#
|
|
418
|
+
# config.amount_column = {
|
|
419
|
+
# prefix: '', # column name prefix
|
|
420
|
+
# postfix: '_cents', # column name postfix
|
|
421
|
+
# column_name: nil, # full column name (overrides prefix, postfix and accessor name)
|
|
422
|
+
# type: :integer, # column type
|
|
423
|
+
# present: true, # column will be created
|
|
424
|
+
# null: false, # other options will be treated as column options
|
|
425
|
+
# default: 0
|
|
426
|
+
# }
|
|
433
427
|
#
|
|
434
|
-
# config.currency_column = {
|
|
435
|
-
#
|
|
436
|
-
#
|
|
437
|
-
#
|
|
438
|
-
#
|
|
439
|
-
#
|
|
440
|
-
#
|
|
441
|
-
#
|
|
428
|
+
# config.currency_column = {
|
|
429
|
+
# prefix: '',
|
|
430
|
+
# postfix: '_currency',
|
|
431
|
+
# column_name: nil,
|
|
432
|
+
# type: :string,
|
|
433
|
+
# present: true,
|
|
434
|
+
# null: false,
|
|
435
|
+
# default: 'USD'
|
|
436
|
+
# }
|
|
442
437
|
|
|
443
438
|
# Register a custom currency
|
|
444
439
|
#
|
|
445
440
|
# Example:
|
|
446
441
|
# config.register_currency = {
|
|
447
|
-
# priority:
|
|
448
|
-
# iso_code:
|
|
449
|
-
# name:
|
|
450
|
-
# symbol:
|
|
451
|
-
# symbol_first:
|
|
452
|
-
# subunit:
|
|
453
|
-
# subunit_to_unit:
|
|
442
|
+
# priority: 1,
|
|
443
|
+
# iso_code: "EU4",
|
|
444
|
+
# name: "Euro with subunit of 4 digits",
|
|
445
|
+
# symbol: "€",
|
|
446
|
+
# symbol_first: true,
|
|
447
|
+
# subunit: "Subcent",
|
|
448
|
+
# subunit_to_unit: 10000,
|
|
454
449
|
# thousands_separator: ".",
|
|
455
|
-
# decimal_mark:
|
|
450
|
+
# decimal_mark: ","
|
|
456
451
|
# }
|
|
457
452
|
|
|
458
453
|
# Specify a rounding mode
|
|
@@ -527,8 +522,34 @@ So `humanized_money` will ignore `config.default_format = { no_cents_if_whole: f
|
|
|
527
522
|
|
|
528
523
|
### Testing
|
|
529
524
|
|
|
530
|
-
|
|
531
|
-
|
|
525
|
+
The test helpers work with both RSpec and Minitest.
|
|
526
|
+
|
|
527
|
+
#### RSpec
|
|
528
|
+
|
|
529
|
+
If you use RSpec, just require the test helpers in `spec_helper.rb`:
|
|
530
|
+
|
|
531
|
+
```ruby
|
|
532
|
+
require "money-rails/test_helpers"
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
The helpers will automatically be included in your RSpec tests.
|
|
536
|
+
|
|
537
|
+
#### Minitest
|
|
538
|
+
|
|
539
|
+
If you use Minitest, require the test helpers and include them in your test class:
|
|
540
|
+
|
|
541
|
+
```ruby
|
|
542
|
+
require "money-rails/test_helpers"
|
|
543
|
+
|
|
544
|
+
class ProductTest < Minitest::Test
|
|
545
|
+
include MoneyRails::TestHelpers
|
|
546
|
+
|
|
547
|
+
def test_monetizes_price
|
|
548
|
+
matcher = monetize(:price_cents)
|
|
549
|
+
assert matcher.matches?(Product)
|
|
550
|
+
end
|
|
551
|
+
end
|
|
552
|
+
```
|
|
532
553
|
|
|
533
554
|
#### The `monetize` matcher
|
|
534
555
|
|
|
@@ -570,12 +591,12 @@ For examples on using the test_helpers look at
|
|
|
570
591
|
|
|
571
592
|
## Supported ORMs/ODMs
|
|
572
593
|
|
|
573
|
-
* ActiveRecord (>=
|
|
574
|
-
* Mongoid (>=
|
|
594
|
+
* ActiveRecord (>= 7.0)
|
|
595
|
+
* Mongoid (>= 7.x)
|
|
575
596
|
|
|
576
597
|
## Supported Ruby interpreters
|
|
577
598
|
|
|
578
|
-
* MRI Ruby >= 3.
|
|
599
|
+
* MRI Ruby >= 3.1
|
|
579
600
|
|
|
580
601
|
You can see a full list of the currently supported interpreters in
|
|
581
602
|
[ruby.yml](https://github.com/RubyMoney/money-rails/blob/main/.github/workflows/ruby.yml)
|
|
@@ -592,18 +613,8 @@ You can see a full list of the currently supported interpreters in
|
|
|
592
613
|
|
|
593
614
|
### How to run the tests
|
|
594
615
|
|
|
595
|
-
Our tests are executed with several ORMs - see `Rakefile` for details. To install all required gems run `rake spec:all
|
|
616
|
+
Our tests are executed with several ORMs - see `Rakefile` for details. To install all required gems run `rake spec:all`. That command will take care of installing all required gems for all the different Gemfiles and then running the test suite with the installed bundle.
|
|
596
617
|
|
|
597
618
|
You can also run the test suite against a specific ORM or Rails version, `rake -T` will give you an idea of the possible task (take a look at the tasks under the spec: namespace).
|
|
598
619
|
|
|
599
|
-
If you are testing against mongoid, make sure to have the mongod process running before executing the suite
|
|
600
|
-
|
|
601
|
-
## Maintainers
|
|
602
|
-
|
|
603
|
-
* Andreas Loupasakis (https://github.com/alup)
|
|
604
|
-
* Shane Emmons (https://github.com/semmons99)
|
|
605
|
-
* Simone Carletti (https://github.com/weppos)
|
|
606
|
-
|
|
607
|
-
## License
|
|
608
|
-
|
|
609
|
-
[MIT License](https://github.com/RubyMoney/money-rails/blob/main/LICENSE). Copyright 2023 RubyMoney.
|
|
620
|
+
If you are testing against mongoid, make sure to have the mongod process running before executing the suite. (E.g. `sudo mongod --quiet`)
|
|
@@ -9,6 +9,8 @@ module MoneyRails
|
|
|
9
9
|
extend ActiveSupport::Concern
|
|
10
10
|
|
|
11
11
|
module ClassMethods
|
|
12
|
+
MODULE_NAME = :DynamicMoneyAttributes
|
|
13
|
+
|
|
12
14
|
def monetized_attributes
|
|
13
15
|
monetized_attributes = @monetized_attributes || {}.with_indifferent_access
|
|
14
16
|
|
|
@@ -116,23 +118,31 @@ module MoneyRails
|
|
|
116
118
|
end
|
|
117
119
|
end
|
|
118
120
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
if const_defined?(MODULE_NAME, false)
|
|
122
|
+
mod = const_get(MODULE_NAME)
|
|
123
|
+
else
|
|
124
|
+
mod = const_set(MODULE_NAME, Module.new)
|
|
125
|
+
include mod
|
|
123
126
|
end
|
|
124
127
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
mod.module_eval do
|
|
129
|
+
# Getter for monetized attribute
|
|
130
|
+
define_method name do |*args, **kwargs|
|
|
131
|
+
read_monetized name, subunit_name, options, *args, **kwargs
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Setter for monetized attribute
|
|
135
|
+
define_method "#{name}=" do |value|
|
|
136
|
+
write_monetized name, subunit_name, value, validation_enabled, instance_currency_name, options
|
|
137
|
+
end
|
|
129
138
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
if validation_enabled
|
|
140
|
+
# Ensure that the before_type_cast value is cleared when setting
|
|
141
|
+
# the subunit value directly
|
|
142
|
+
define_method "#{subunit_name}=" do |value|
|
|
143
|
+
instance_variable_set "@#{name}_money_before_type_cast", nil
|
|
144
|
+
write_attribute(subunit_name, value)
|
|
145
|
+
end
|
|
136
146
|
end
|
|
137
147
|
end
|
|
138
148
|
|
data/lib/money-rails/hooks.rb
CHANGED
|
@@ -8,30 +8,13 @@ module MoneyRails
|
|
|
8
8
|
require 'money-rails/active_model/validator'
|
|
9
9
|
require 'money-rails/active_record/monetizable'
|
|
10
10
|
::ActiveRecord::Base.send :include, MoneyRails::ActiveRecord::Monetizable
|
|
11
|
-
if defined?(::ActiveRecord) && defined?(::ActiveRecord::VERSION)
|
|
12
|
-
if ::ActiveRecord::VERSION::MAJOR >= 4
|
|
13
|
-
rails42 = case
|
|
14
|
-
when ::ActiveRecord::VERSION::MAJOR < 5 && ::ActiveRecord::VERSION::MINOR >= 2
|
|
15
|
-
true
|
|
16
|
-
when ::ActiveRecord::VERSION::MAJOR >= 5
|
|
17
|
-
true
|
|
18
|
-
else
|
|
19
|
-
false
|
|
20
|
-
end
|
|
21
11
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
else
|
|
25
|
-
::ActiveRecord::Base.connection_config[:adapter]
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
postgresql_with_money = rails42 && PG_ADAPTERS.include?(current_adapter)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
12
|
+
current_adapter = ::ActiveRecord::Base.connection_db_config.configuration_hash[:adapter]
|
|
13
|
+
postgresql_with_money = PG_ADAPTERS.include?(current_adapter)
|
|
31
14
|
|
|
32
15
|
require "money-rails/active_record/migration_extensions/options_extractor"
|
|
33
16
|
%w{schema_statements table}.each do |file|
|
|
34
|
-
require "money-rails/active_record/migration_extensions/#{file}
|
|
17
|
+
require "money-rails/active_record/migration_extensions/#{file}_pg"
|
|
35
18
|
if !postgresql_with_money
|
|
36
19
|
require "money-rails/active_record/migration_extensions/#{file}"
|
|
37
20
|
end
|
|
@@ -44,17 +27,12 @@ module MoneyRails
|
|
|
44
27
|
# For Mongoid
|
|
45
28
|
begin; require 'mongoid'; require 'mongoid/version'; rescue LoadError; end
|
|
46
29
|
if defined? ::Mongoid
|
|
47
|
-
|
|
48
|
-
require 'money-rails/mongoid/two' # Loading the file is enough
|
|
49
|
-
else
|
|
50
|
-
require 'money-rails/mongoid/money'
|
|
51
|
-
end
|
|
30
|
+
require 'money-rails/mongoid/money'
|
|
52
31
|
end
|
|
53
32
|
|
|
54
33
|
# For ActionView
|
|
55
34
|
ActiveSupport.on_load(:action_view) do
|
|
56
|
-
|
|
57
|
-
::ActionView::Base.send :include, MoneyRails::ActionViewExtension
|
|
35
|
+
::ActionView::Base.include MoneyRails::ActionViewExtension
|
|
58
36
|
end
|
|
59
37
|
|
|
60
38
|
# For ActiveSupport
|
|
@@ -3,8 +3,8 @@ class Money
|
|
|
3
3
|
# Converts an object of this instance into a database friendly value.
|
|
4
4
|
def mongoize
|
|
5
5
|
{
|
|
6
|
-
cents: cents.
|
|
7
|
-
currency_iso: currency.iso_code
|
|
6
|
+
cents: cents.to_f,
|
|
7
|
+
currency_iso: currency.iso_code
|
|
8
8
|
}
|
|
9
9
|
end
|
|
10
10
|
|
|
@@ -14,14 +14,8 @@ class Money
|
|
|
14
14
|
# this custom class from it.
|
|
15
15
|
def demongoize(object)
|
|
16
16
|
if object.is_a?(Hash)
|
|
17
|
-
|
|
18
|
-
object = object.deep_symbolize_keys
|
|
19
|
-
else
|
|
20
|
-
object = object.symbolize_keys
|
|
21
|
-
end
|
|
17
|
+
object = object.symbolize_keys
|
|
22
18
|
object.has_key?(:cents) ? ::Money.new(object[:cents], object[:currency_iso]) : nil
|
|
23
|
-
else
|
|
24
|
-
nil
|
|
25
19
|
end
|
|
26
20
|
end
|
|
27
21
|
|
|
@@ -48,11 +42,7 @@ class Money
|
|
|
48
42
|
private
|
|
49
43
|
|
|
50
44
|
def mongoize_hash(hash)
|
|
51
|
-
|
|
52
|
-
hash.deep_symbolize_keys!
|
|
53
|
-
elsif hash.respond_to?(:symbolize_keys!)
|
|
54
|
-
hash.symbolize_keys!
|
|
55
|
-
end
|
|
45
|
+
hash = hash.symbolize_keys
|
|
56
46
|
|
|
57
47
|
# Guard for a blank form
|
|
58
48
|
return nil if hash[:cents] == '' && hash[:currency_iso] == ''
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require 'rspec/expectations'
|
|
2
|
-
|
|
3
1
|
module MoneyRails
|
|
4
2
|
module TestHelpers
|
|
5
3
|
def monetize(attribute)
|
|
@@ -113,6 +111,8 @@ module MoneyRails
|
|
|
113
111
|
end
|
|
114
112
|
end
|
|
115
113
|
|
|
116
|
-
RSpec
|
|
117
|
-
|
|
114
|
+
if defined?(RSpec)
|
|
115
|
+
RSpec.configure do |config|
|
|
116
|
+
config.include MoneyRails::TestHelpers
|
|
117
|
+
end
|
|
118
118
|
end
|
data/lib/money-rails/version.rb
CHANGED
data/lib/money-rails.rb
CHANGED
data/money-rails.gemspec
CHANGED
|
@@ -21,8 +21,8 @@ Gem::Specification.new do |s|
|
|
|
21
21
|
|
|
22
22
|
s.add_dependency "money", "~> 7.0"
|
|
23
23
|
s.add_dependency "monetize", "~> 2.0"
|
|
24
|
-
s.add_dependency "activesupport", ">=
|
|
25
|
-
s.add_dependency "railties", ">=
|
|
24
|
+
s.add_dependency "activesupport", ">= 7.0"
|
|
25
|
+
s.add_dependency "railties", ">= 7.0"
|
|
26
26
|
|
|
27
27
|
if s.respond_to?(:metadata)
|
|
28
28
|
s.metadata["changelog_uri"] = "https://github.com/RubyMoney/money-rails/blob/master/CHANGELOG.md"
|
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:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andreas Loupasakis
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
- Simone Carletti
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: money
|
|
@@ -45,28 +45,28 @@ dependencies:
|
|
|
45
45
|
requirements:
|
|
46
46
|
- - ">="
|
|
47
47
|
- !ruby/object:Gem::Version
|
|
48
|
-
version: '
|
|
48
|
+
version: '7.0'
|
|
49
49
|
type: :runtime
|
|
50
50
|
prerelease: false
|
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements:
|
|
53
53
|
- - ">="
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
|
-
version: '
|
|
55
|
+
version: '7.0'
|
|
56
56
|
- !ruby/object:Gem::Dependency
|
|
57
57
|
name: railties
|
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
|
59
59
|
requirements:
|
|
60
60
|
- - ">="
|
|
61
61
|
- !ruby/object:Gem::Version
|
|
62
|
-
version: '
|
|
62
|
+
version: '7.0'
|
|
63
63
|
type: :runtime
|
|
64
64
|
prerelease: false
|
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
|
66
66
|
requirements:
|
|
67
67
|
- - ">="
|
|
68
68
|
- !ruby/object:Gem::Version
|
|
69
|
-
version: '
|
|
69
|
+
version: '7.0'
|
|
70
70
|
description: This library provides integration of RubyMoney - Money gem with Rails
|
|
71
71
|
email:
|
|
72
72
|
- alup.rubymoney@gmail.com
|
|
@@ -88,9 +88,9 @@ files:
|
|
|
88
88
|
- lib/money-rails/active_model/validator.rb
|
|
89
89
|
- lib/money-rails/active_record/migration_extensions/options_extractor.rb
|
|
90
90
|
- lib/money-rails/active_record/migration_extensions/schema_statements.rb
|
|
91
|
-
- lib/money-rails/active_record/migration_extensions/
|
|
91
|
+
- lib/money-rails/active_record/migration_extensions/schema_statements_pg.rb
|
|
92
92
|
- lib/money-rails/active_record/migration_extensions/table.rb
|
|
93
|
-
- lib/money-rails/active_record/migration_extensions/
|
|
93
|
+
- lib/money-rails/active_record/migration_extensions/table_pg.rb
|
|
94
94
|
- lib/money-rails/active_record/monetizable.rb
|
|
95
95
|
- lib/money-rails/configuration.rb
|
|
96
96
|
- lib/money-rails/engine.rb
|
|
@@ -99,7 +99,6 @@ files:
|
|
|
99
99
|
- lib/money-rails/hooks.rb
|
|
100
100
|
- lib/money-rails/money.rb
|
|
101
101
|
- lib/money-rails/mongoid/money.rb
|
|
102
|
-
- lib/money-rails/mongoid/two.rb
|
|
103
102
|
- lib/money-rails/rails_admin.rb
|
|
104
103
|
- lib/money-rails/railtie.rb
|
|
105
104
|
- lib/money-rails/test_helpers.rb
|
|
@@ -127,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
127
126
|
- !ruby/object:Gem::Version
|
|
128
127
|
version: '0'
|
|
129
128
|
requirements: []
|
|
130
|
-
rubygems_version:
|
|
129
|
+
rubygems_version: 4.0.3
|
|
131
130
|
specification_version: 4
|
|
132
131
|
summary: Money gem integration with Rails
|
|
133
132
|
test_files: []
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# Class name does not really matches the folder hierarchy, because
|
|
2
|
-
# in order for (de)serialization to work, the class must be re-opened.
|
|
3
|
-
# But this file brings mongoid 2.X compat., so...
|
|
4
|
-
|
|
5
|
-
class Money
|
|
6
|
-
include ::Mongoid::Fields::Serializable
|
|
7
|
-
|
|
8
|
-
# Mongo friendly -> Money
|
|
9
|
-
def deserialize(object)
|
|
10
|
-
return nil if object.nil?
|
|
11
|
-
|
|
12
|
-
object = object.with_indifferent_access
|
|
13
|
-
::Money.new object[:cents], object[:currency_iso]
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# Money -> Mongo friendly
|
|
17
|
-
def serialize(object)
|
|
18
|
-
case
|
|
19
|
-
when object.is_a?(Money)
|
|
20
|
-
{
|
|
21
|
-
cents: object.cents.is_a?(BigDecimal) ? object.cents.to_s : object.cents,
|
|
22
|
-
currency_iso: object.currency.iso_code
|
|
23
|
-
}
|
|
24
|
-
when object.nil? then nil
|
|
25
|
-
when object.respond_to?(:to_money)
|
|
26
|
-
begin
|
|
27
|
-
serialize(object.to_money)
|
|
28
|
-
rescue Monetize::ParseError => e
|
|
29
|
-
raise MoneyRails::Error, e.message if MoneyRails.raise_error_on_money_parsing
|
|
30
|
-
nil
|
|
31
|
-
end
|
|
32
|
-
else nil
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
File without changes
|
|
File without changes
|