minting-rails 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -12
- data/lib/generators/templates/minting.rb +4 -6
- data/lib/minting/money_attribute/money_attribute.rb +16 -14
- data/lib/minting/money_attribute/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bd3a7589733a495cc181ffa6ab521e5c8090c03cbc3ab5e94b5cd2f75053a44
|
4
|
+
data.tar.gz: 3dcaaa12c7f389d07e29f4ffe7c6636c3370e78a11f366b4ffef9f92539ab026
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d14f5bf882de78babfc661320fa08a9a182addcd429bebcc1df1c604a09778d637dd34000cb386816e6c3e089018563696dbcedbfcd1bffc38cd8d9832d1914
|
7
|
+
data.tar.gz: cbef220622baba1a8fc0eedce69b6854c2786d347e0b7d487913654ab6221849dff57ce6e7ca8f25fb3ba3e1a433536fcc829afc68fd56227c9dadb6ed2e4ac7
|
data/README.md
CHANGED
@@ -1,17 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# Minting::Rails
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
## Usage
|
6
|
-
|
7
|
-
Currently in development. Please wait for 1.0 release.
|
3
|
+
Minting::Rails is a gem that provides money attributes to ActiveRecord models. It integrates the [Minting](https://github.com/gferraz/minting) library into your Rails application.
|
8
4
|
|
9
5
|
## Installation
|
10
6
|
|
11
7
|
Add this line to your application's Gemfile:
|
12
8
|
|
13
9
|
```ruby
|
14
|
-
gem
|
10
|
+
gem 'minting-rails'
|
15
11
|
```
|
16
12
|
|
17
13
|
And then execute:
|
@@ -20,11 +16,7 @@ And then execute:
|
|
20
16
|
bundle
|
21
17
|
```
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
```bash
|
26
|
-
gem install minting-rails
|
27
|
-
```
|
19
|
+
## Configuration
|
28
20
|
|
29
21
|
After intalling generate Minting configuration initializer:
|
30
22
|
|
@@ -32,6 +24,32 @@ After intalling generate Minting configuration initializer:
|
|
32
24
|
rails g mint:initializer
|
33
25
|
```
|
34
26
|
|
27
|
+
You can configure the default currency for your application by adding the following line to your config/initializers/minting.rb:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Minting.configure do |config|
|
31
|
+
config.default_currency = :usd
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
To use Minting::Rails, you add the money_attribute method to your ActiveRecord models. For example:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
class SimpleOffer < ApplicationRecord
|
41
|
+
money_attribute :price, currency: 'USD'
|
42
|
+
money_attribute :discount, currency: 'USD'
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
Now you can use the price attribute as a Money object:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
product = Product.ne(price: 100)
|
50
|
+
puts product.price # => "$100.00"
|
51
|
+
```
|
52
|
+
|
35
53
|
## To do
|
36
54
|
|
37
55
|
- API Documentation
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding : utf-8
|
2
2
|
# frozen_string_literal: true
|
3
|
-
Mint.configure do |config|
|
4
3
|
|
4
|
+
Mint.configure do |config|
|
5
5
|
# Register a custom currency
|
6
6
|
#
|
7
7
|
# Example:
|
@@ -10,8 +10,8 @@ Mint.configure do |config|
|
|
10
10
|
# {currency: 'NGN', subunit: 3, symbol: '₦'}
|
11
11
|
# ]
|
12
12
|
config.added_currencies = [
|
13
|
-
{currency: 'CRC', subunit: 2, symbol: '₡'},
|
14
|
-
{currency: 'NGN', subunit: 3, symbol: '₦'}
|
13
|
+
{ currency: 'CRC', subunit: 2, symbol: '₡' },
|
14
|
+
{ currency: 'NGN', subunit: 3, symbol: '₦' }
|
15
15
|
]
|
16
16
|
|
17
17
|
# Enable currencies
|
@@ -21,14 +21,12 @@ Mint.configure do |config|
|
|
21
21
|
|
22
22
|
config.enabled_currencies = :all
|
23
23
|
|
24
|
-
|
25
24
|
# To set the default currency
|
26
25
|
#
|
27
26
|
# It must be a registered currency
|
28
27
|
#
|
29
28
|
config.default_currency = 'BRL'
|
30
29
|
|
31
|
-
|
32
30
|
# Specify a rounding mode (not yet implemented)
|
33
31
|
# Any one of:
|
34
32
|
#
|
@@ -53,4 +51,4 @@ Mint.configure do |config|
|
|
53
51
|
# symbol: nil,
|
54
52
|
# sign_before_symbol: nil
|
55
53
|
# }
|
56
|
-
end
|
54
|
+
end
|
@@ -39,21 +39,23 @@ module Mint
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def self.parse(amount, currency)
|
42
|
-
case amount
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
42
|
+
money = case amount
|
43
|
+
when NilClass
|
44
|
+
nil
|
45
|
+
when Mint::Money
|
46
|
+
amount
|
47
|
+
when Numeric
|
48
|
+
Mint.money(amount, currency)
|
49
|
+
else
|
50
|
+
if amount.respond_to? :to_money
|
51
|
+
amount.to_money(currency)
|
52
|
+
else
|
53
|
+
Mint.money(amount.to_s.split[0].to_r, currency)
|
54
|
+
end
|
55
|
+
end
|
56
56
|
# puts "parse(#{amount}, #{currency.inspect}) => #{money.inspect}"
|
57
|
+
Mint.assert_valid_currency!(currency)
|
58
|
+
money
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minting-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gilson Ferraz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: minting
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 7.1.3.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 7.1.3.2
|
41
41
|
description: ''
|
42
42
|
email:
|
43
43
|
- gilson@cesar.etc.br
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
|
-
rubygems_version: 3.5.
|
86
|
+
rubygems_version: 3.5.14
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: Money attributes to ActiveRecord
|