minting-rails 0.3.2 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5cbd850d0e142b296ffe9b02554317c3b240a2decea3ecd35177b83fcaab225
4
- data.tar.gz: e1f2a8b0fc4e9d573f00e8b230773bf7e883c75ecbe134c8c611c460f3203316
3
+ metadata.gz: 766443a16444b6968e71bd7a6413e354a694e5caa34372ccc75a5b0e8f2c3521
4
+ data.tar.gz: c8ddbbfdbf40da375086007a7c6483b6667a508254aab7dcd4e5cb3a4f34a4ee
5
5
  SHA512:
6
- metadata.gz: 88b6292f0807bb62a93d04a3dc7dbd5ef6139ae215f9659c66a67428f4248d9c32a73762b8837ee69bacc3959b0922393e6d3b4c0c7b7bd13526e0d466ade436
7
- data.tar.gz: dd0a1fcf55760156015e54a1fe86962af9271f1cb0ff9c8c134a15178e1cacef4fa5ebbd6c3d378f2dce1bdb9d650bc77fc3bffb5f4f2e81ec681f8e447c6149
6
+ metadata.gz: a3c077a74cbdc2a828d827aeaf9f19350d4eb78b3c413bdd5250e6e756f3b75e328de4a96bb7a25ef66427fb63bfb478c30d511e48dc6948fece318f719a7162
7
+ data.tar.gz: 3d04dd4a937c093ca1ae96516773077284226fa918b2cb633fa32fd64a35f8b75abbbb623d490bf5ace0cf8ec2755f03e9e83b576f4eae7915f8ae910cb8209a
data/README.md CHANGED
@@ -1,17 +1,13 @@
1
- # Mint::Rails
1
+ # Minting::Rails
2
2
 
3
- Add Money attributes to your Rails application.
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 "minting-rails"
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
- Or install it yourself as:
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
@@ -40,19 +40,19 @@ module Mint
40
40
 
41
41
  def self.parse(amount, currency)
42
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
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
57
  Mint.assert_valid_currency!(currency)
58
58
  money
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Mint
4
4
  module MoneyAttribute
5
- VERSION = '0.3.2'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,43 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minting-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilson Ferraz
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-05-25 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: rails
13
+ name: minting
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: 7.1.3.2
18
+ version: 1.0.0
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: 7.1.3.2
25
+ version: 1.0.0
27
26
  - !ruby/object:Gem::Dependency
28
- name: minting
27
+ name: rails
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: '0.3'
32
+ version: 7.1.3.2
34
33
  type: :runtime
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - ">="
39
38
  - !ruby/object:Gem::Version
40
- version: '0.3'
39
+ version: 7.1.3.2
41
40
  description: ''
42
41
  email:
43
42
  - gilson@cesar.etc.br
@@ -68,7 +67,6 @@ metadata:
68
67
  changelog_uri: https://github.com/gferraz/minting-rails/releases
69
68
  bug_tracker_uri: https://github.com/gferraz/minting-rails/issues
70
69
  rubygems_mfa_required: 'true'
71
- post_install_message:
72
70
  rdoc_options: []
73
71
  require_paths:
74
72
  - lib
@@ -83,8 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
81
  - !ruby/object:Gem::Version
84
82
  version: '0'
85
83
  requirements: []
86
- rubygems_version: 3.5.10
87
- signing_key:
84
+ rubygems_version: 4.0.9
88
85
  specification_version: 4
89
86
  summary: Money attributes to ActiveRecord
90
87
  test_files: []