economy 0.0.1 → 4.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea083151226d83d5359adb1745e8407d27b00461
4
- data.tar.gz: a8c38d7e246dc84fed0a34f6f4e6387539cc74d2
3
+ metadata.gz: abfda4805b987b0209c210090c47546f9516ac62
4
+ data.tar.gz: ebf38ddd7fa00e8bd6ef642fa05dedd65509b2f2
5
5
  SHA512:
6
- metadata.gz: d13e3f648a339a0ee0998fe7bfa929682c0e0faa21b7d56935867c3674b283edaa5445d4d84e49ce385f3ee51d38f5b6d89f46614a0ee18f9c0899b11298b4be
7
- data.tar.gz: 7701b8a3bdbd7a64dd51a8f544b5af9fee23e27a5e2443f8302b1acd43d66189e6002ada1a9065fd0a67a08978e0897e6a38dc15b6c64cfd12ad48dcf7463e49
6
+ metadata.gz: 69541c4bc20b5d70a424783b1dedca6de07cc6bd9a5cd6f695d5f79214d4fc2cc5eeda9ddaa0090166854848a62d509b84b704a5d45f0c83ae4a000d8bd66d8b
7
+ data.tar.gz: e04787510e5df9885afd1638cbe273fde30679c90dde3089849fcf7dc9b6ac70935b45df2334461aac83efe654bb621e1e8f1d6111fa2e83c863aedb04053828
data/README.md CHANGED
@@ -9,13 +9,13 @@ High performance multicurrency money for rails.
9
9
 
10
10
  ## Why
11
11
 
12
- I did this gem to add some enhancements to my projects:
12
+ I did this gem to:
13
13
 
14
14
  - Keep rates cached in redis for optimal performance and sync between instances.
15
- - Out of the box working rates service.
16
- - Be able to make sql queries without the need to convert integers to decimals.
15
+ - Have an out of the box working rates service.
16
+ - Be able to make sql queries without the need to convert integers into decimals.
17
17
  - Share a common currency column for multiple money fields if a need it.
18
- - Avoid the need to format manually the string representation in views.
18
+ - Avoid the need to manually format the string representation in views.
19
19
 
20
20
  ## Install
21
21
 
@@ -31,34 +31,49 @@ $ bundle
31
31
 
32
32
  To install Redis you can use homebrew:
33
33
  ```
34
- brew install redis
34
+ $ brew install redis
35
35
  ```
36
36
 
37
37
  ## Configuration
38
38
 
39
39
  Generate the configuration file:
40
40
  ```
41
- rails g economy:install
41
+ $ bundle exec rails g economy:install
42
42
  ```
43
43
 
44
- The defaults are:
44
+ Set the global settings:
45
45
  ```ruby
46
46
  Economy.configure do |config|
47
47
 
48
48
  config.rates = :yahoo
49
49
  config.default_currency = 'USD'
50
50
 
51
- config.add_currency(
51
+ config.register_currency(
52
52
  iso_code: 'USD',
53
53
  iso_number: 840,
54
54
  symbol: 'U$S',
55
55
  decimals: 2
56
56
  )
57
+ config.register_currency(
58
+ iso_code: 'UYU',
59
+ iso_number: 858,
60
+ symbol: '$U',
61
+ decimals: 2
62
+ )
57
63
 
58
64
  end
59
65
  ```
60
66
 
61
- ## Definition
67
+ Add a redis_url to your environment configuration:
68
+ ```ruby
69
+ Rails.application.configure do
70
+ config.redis_url = 'redis://localhost:6379/0'
71
+ end
72
+ ```
73
+
74
+ ## Usage
75
+
76
+ ### Definitions
62
77
 
63
78
  Add the money columns to your tables:
64
79
  ```ruby
@@ -73,13 +88,11 @@ end
73
88
  Define the money field in your models:
74
89
  ```ruby
75
90
  class Product < ActiveRecord::Base
76
-
77
91
  monetize :price
78
-
79
92
  end
80
93
  ```
81
94
 
82
- ## Usage
95
+ ### Attributes
83
96
 
84
97
  If you want to assign values, everything continuos working the same:
85
98
  ```ruby
@@ -106,11 +119,11 @@ The formatting method is to_s, it uses active support, so there is no need to ca
106
119
  <%= product.price %>
107
120
  ```
108
121
 
109
- ## Rates
122
+ ### Rates
110
123
 
111
124
  You can use rake task:
112
125
  ```
113
- bundle exec rake economy:update_rates
126
+ $ bundle exec rake economy:update_rates
114
127
  ```
115
128
 
116
129
  Or the plain method:
@@ -3,7 +3,7 @@ module Economy
3
3
 
4
4
  attr_accessor :rates, :default_currency
5
5
 
6
- def add_currency(*args)
6
+ def register_currency(*args)
7
7
  Economy.currencies.add *args
8
8
  end
9
9
 
@@ -1,7 +1,7 @@
1
1
  module Economy
2
2
  class Railtie < Rails::Railtie
3
3
 
4
- initializer :sidejobs do
4
+ initializer 'economy.extensions' do
5
5
  # Prevent deprecation warning
6
6
  require 'economy/exchange'
7
7
 
@@ -1,5 +1,5 @@
1
1
  module Economy
2
2
 
3
- VERSION = '0.0.1'
3
+ VERSION = '4.0.0.0'
4
4
 
5
5
  end
data/lib/economy.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'generators/economy/install_generator'
2
1
  require 'economy/extensions/active_record/base'
3
2
  require 'economy/rates/base'
4
3
  require 'economy/rates/yahoo'
@@ -2,7 +2,7 @@ require 'rails/generators'
2
2
 
3
3
  module Economy
4
4
  module Generators
5
- class InstallGenerator < Rails::Generators::Base
5
+ class InstallGenerator < ::Rails::Generators::Base
6
6
  include Rails::Generators::Migration
7
7
 
8
8
  source_root File.expand_path('../templates', __FILE__)
@@ -3,7 +3,7 @@ Economy.configure do |config|
3
3
  config.rates = :yahoo
4
4
  config.default_currency = 'USD'
5
5
 
6
- config.add_currency(
6
+ config.register_currency(
7
7
  iso_code: 'USD',
8
8
  iso_number: 840,
9
9
  symbol: 'U$S',
@@ -1,4 +1,5 @@
1
1
  namespace :economy do
2
+ desc 'Updates all rates.'
2
3
  task update_rates: :environment do
3
4
  Economy.update_rates
4
5
  end
@@ -1,7 +1,7 @@
1
1
  development:
2
2
  adapter: postgresql
3
- database: makers_development
3
+ database: economy_development
4
4
 
5
5
  test:
6
6
  adapter: postgresql
7
- database: makers_test
7
+ database: economy_test
@@ -3,13 +3,13 @@ Economy.configure do |config|
3
3
  config.rates = :yahoo
4
4
  config.default_currency = 'USD'
5
5
 
6
- config.add_currency(
6
+ config.register_currency(
7
7
  iso_code: 'USD',
8
8
  iso_number: 840,
9
9
  symbol: 'U$S',
10
10
  decimals: 2
11
11
  )
12
- config.add_currency(
12
+ config.register_currency(
13
13
  iso_code: 'UYU',
14
14
  iso_number: 858,
15
15
  symbol: '$U',
@@ -1,67 +1,61 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>The page you were looking for doesn't exist (404)</title>
5
- <meta name="viewport" content="width=device-width,initial-scale=1">
6
- <style>
7
- body {
8
- background-color: #EFEFEF;
9
- color: #2E2F30;
10
- text-align: center;
11
- font-family: arial, sans-serif;
12
- margin: 0;
13
- }
14
-
15
- div.dialog {
16
- width: 95%;
17
- max-width: 33em;
18
- margin: 4em auto 0;
19
- }
20
-
21
- div.dialog > div {
22
- border: 1px solid #CCC;
23
- border-right-color: #999;
24
- border-left-color: #999;
25
- border-bottom-color: #BBB;
26
- border-top: #B00100 solid 4px;
27
- border-top-left-radius: 9px;
28
- border-top-right-radius: 9px;
29
- background-color: white;
30
- padding: 7px 12% 0;
31
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
- }
33
-
34
- h1 {
35
- font-size: 100%;
36
- color: #730E15;
37
- line-height: 1.5em;
38
- }
39
-
40
- div.dialog > p {
41
- margin: 0 0 1em;
42
- padding: 1em;
43
- background-color: #F7F7F7;
44
- border: 1px solid #CCC;
45
- border-right-color: #999;
46
- border-left-color: #999;
47
- border-bottom-color: #999;
48
- border-bottom-left-radius: 4px;
49
- border-bottom-right-radius: 4px;
50
- border-top-color: #DADADA;
51
- color: #666;
52
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
- }
54
- </style>
55
- </head>
56
-
57
- <body>
58
- <!-- This file lives in public/404.html -->
59
- <div class="dialog">
60
- <div>
61
- <h1>The page you were looking for doesn't exist.</h1>
62
- <p>You may have mistyped the address or the page may have moved.</p>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+ div.dialog {
15
+ width: 95%;
16
+ max-width: 33em;
17
+ margin: 4em auto 0;
18
+ }
19
+ div.dialog > div {
20
+ border: 1px solid #CCC;
21
+ border-right-color: #999;
22
+ border-left-color: #999;
23
+ border-bottom-color: #BBB;
24
+ border-top: #B00100 solid 4px;
25
+ border-top-left-radius: 9px;
26
+ border-top-right-radius: 9px;
27
+ background-color: white;
28
+ padding: 7px 12% 0;
29
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
30
+ }
31
+ h1 {
32
+ font-size: 100%;
33
+ color: #730E15;
34
+ line-height: 1.5em;
35
+ }
36
+ div.dialog > p {
37
+ margin: 0 0 1em;
38
+ padding: 1em;
39
+ background-color: #F7F7F7;
40
+ border: 1px solid #CCC;
41
+ border-right-color: #999;
42
+ border-left-color: #999;
43
+ border-bottom-color: #999;
44
+ border-bottom-left-radius: 4px;
45
+ border-bottom-right-radius: 4px;
46
+ border-top-color: #DADADA;
47
+ color: #666;
48
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <div class="dialog">
54
+ <div>
55
+ <h1>The page you were looking for doesn't exist.</h1>
56
+ <p>You may have mistyped the address or the page may have moved.</p>
57
+ </div>
58
+ <p>If you are the application owner check the logs for more information.</p>
63
59
  </div>
64
- <p>If you are the application owner check the logs for more information.</p>
65
- </div>
66
- </body>
60
+ </body>
67
61
  </html>
@@ -1,67 +1,61 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>The change you wanted was rejected (422)</title>
5
- <meta name="viewport" content="width=device-width,initial-scale=1">
6
- <style>
7
- body {
8
- background-color: #EFEFEF;
9
- color: #2E2F30;
10
- text-align: center;
11
- font-family: arial, sans-serif;
12
- margin: 0;
13
- }
14
-
15
- div.dialog {
16
- width: 95%;
17
- max-width: 33em;
18
- margin: 4em auto 0;
19
- }
20
-
21
- div.dialog > div {
22
- border: 1px solid #CCC;
23
- border-right-color: #999;
24
- border-left-color: #999;
25
- border-bottom-color: #BBB;
26
- border-top: #B00100 solid 4px;
27
- border-top-left-radius: 9px;
28
- border-top-right-radius: 9px;
29
- background-color: white;
30
- padding: 7px 12% 0;
31
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
- }
33
-
34
- h1 {
35
- font-size: 100%;
36
- color: #730E15;
37
- line-height: 1.5em;
38
- }
39
-
40
- div.dialog > p {
41
- margin: 0 0 1em;
42
- padding: 1em;
43
- background-color: #F7F7F7;
44
- border: 1px solid #CCC;
45
- border-right-color: #999;
46
- border-left-color: #999;
47
- border-bottom-color: #999;
48
- border-bottom-left-radius: 4px;
49
- border-bottom-right-radius: 4px;
50
- border-top-color: #DADADA;
51
- color: #666;
52
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
- }
54
- </style>
55
- </head>
56
-
57
- <body>
58
- <!-- This file lives in public/422.html -->
59
- <div class="dialog">
60
- <div>
61
- <h1>The change you wanted was rejected.</h1>
62
- <p>Maybe you tried to change something you didn't have access to.</p>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+ div.dialog {
15
+ width: 95%;
16
+ max-width: 33em;
17
+ margin: 4em auto 0;
18
+ }
19
+ div.dialog > div {
20
+ border: 1px solid #CCC;
21
+ border-right-color: #999;
22
+ border-left-color: #999;
23
+ border-bottom-color: #BBB;
24
+ border-top: #B00100 solid 4px;
25
+ border-top-left-radius: 9px;
26
+ border-top-right-radius: 9px;
27
+ background-color: white;
28
+ padding: 7px 12% 0;
29
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
30
+ }
31
+ h1 {
32
+ font-size: 100%;
33
+ color: #730E15;
34
+ line-height: 1.5em;
35
+ }
36
+ div.dialog > p {
37
+ margin: 0 0 1em;
38
+ padding: 1em;
39
+ background-color: #F7F7F7;
40
+ border: 1px solid #CCC;
41
+ border-right-color: #999;
42
+ border-left-color: #999;
43
+ border-bottom-color: #999;
44
+ border-bottom-left-radius: 4px;
45
+ border-bottom-right-radius: 4px;
46
+ border-top-color: #DADADA;
47
+ color: #666;
48
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <div class="dialog">
54
+ <div>
55
+ <h1>The change you wanted was rejected.</h1>
56
+ <p>Maybe you tried to change something you didn't have access to.</p>
57
+ </div>
58
+ <p>If you are the application owner check the logs for more information.</p>
63
59
  </div>
64
- <p>If you are the application owner check the logs for more information.</p>
65
- </div>
66
- </body>
60
+ </body>
67
61
  </html>
@@ -1,66 +1,60 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>We're sorry, but something went wrong (500)</title>
5
- <meta name="viewport" content="width=device-width,initial-scale=1">
6
- <style>
7
- body {
8
- background-color: #EFEFEF;
9
- color: #2E2F30;
10
- text-align: center;
11
- font-family: arial, sans-serif;
12
- margin: 0;
13
- }
14
-
15
- div.dialog {
16
- width: 95%;
17
- max-width: 33em;
18
- margin: 4em auto 0;
19
- }
20
-
21
- div.dialog > div {
22
- border: 1px solid #CCC;
23
- border-right-color: #999;
24
- border-left-color: #999;
25
- border-bottom-color: #BBB;
26
- border-top: #B00100 solid 4px;
27
- border-top-left-radius: 9px;
28
- border-top-right-radius: 9px;
29
- background-color: white;
30
- padding: 7px 12% 0;
31
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
- }
33
-
34
- h1 {
35
- font-size: 100%;
36
- color: #730E15;
37
- line-height: 1.5em;
38
- }
39
-
40
- div.dialog > p {
41
- margin: 0 0 1em;
42
- padding: 1em;
43
- background-color: #F7F7F7;
44
- border: 1px solid #CCC;
45
- border-right-color: #999;
46
- border-left-color: #999;
47
- border-bottom-color: #999;
48
- border-bottom-left-radius: 4px;
49
- border-bottom-right-radius: 4px;
50
- border-top-color: #DADADA;
51
- color: #666;
52
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
- }
54
- </style>
55
- </head>
56
-
57
- <body>
58
- <!-- This file lives in public/500.html -->
59
- <div class="dialog">
60
- <div>
61
- <h1>We're sorry, but something went wrong.</h1>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+ div.dialog {
15
+ width: 95%;
16
+ max-width: 33em;
17
+ margin: 4em auto 0;
18
+ }
19
+ div.dialog > div {
20
+ border: 1px solid #CCC;
21
+ border-right-color: #999;
22
+ border-left-color: #999;
23
+ border-bottom-color: #BBB;
24
+ border-top: #B00100 solid 4px;
25
+ border-top-left-radius: 9px;
26
+ border-top-right-radius: 9px;
27
+ background-color: white;
28
+ padding: 7px 12% 0;
29
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
30
+ }
31
+ h1 {
32
+ font-size: 100%;
33
+ color: #730E15;
34
+ line-height: 1.5em;
35
+ }
36
+ div.dialog > p {
37
+ margin: 0 0 1em;
38
+ padding: 1em;
39
+ background-color: #F7F7F7;
40
+ border: 1px solid #CCC;
41
+ border-right-color: #999;
42
+ border-left-color: #999;
43
+ border-bottom-color: #999;
44
+ border-bottom-left-radius: 4px;
45
+ border-bottom-right-radius: 4px;
46
+ border-top-color: #DADADA;
47
+ color: #666;
48
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <div class="dialog">
54
+ <div>
55
+ <h1>We're sorry, but something went wrong.</h1>
56
+ </div>
57
+ <p>If you are the application owner check the logs for more information.</p>
62
58
  </div>
63
- <p>If you are the application owner check the logs for more information.</p>
64
- </div>
65
- </body>
59
+ </body>
66
60
  </html>
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
  require 'rails/generators'
3
- require 'generators/economy/install_generator'
3
+ require 'generators/economy/install/install_generator'
4
4
 
5
5
  class GeneratorTest < Rails::Generators::TestCase
6
6
  destination Rails.root.join('tmp')
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class RatesTest < ActiveSupport::TestCase
3
+ class RateTest < ActiveSupport::TestCase
4
4
  include RatesHelper
5
5
 
6
6
  test 'retries' do