whittaker_tech-midas 0.1.0 → 0.1.1
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/README.md +2 -2
- data/app/models/concerns/whittaker_tech/midas/bankable.rb +14 -9
- data/lib/generators/whittaker_tech/midas/install/install_generator.rb +16 -0
- data/lib/tasks/whittaker_tech/midas_tasks.rake +27 -4
- data/lib/whittaker_tech/midas/engine.rb +5 -0
- data/lib/whittaker_tech/midas/version.rb +1 -1
- metadata +10 -24
- data/config/routes.rb +0 -2
- /data/db/migrate/{20251015160523_create_wt_midas_coins.rb → create_wt_midas_coins.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: 027c1179177e4e7a6c618a55e196fad98d2b617a91b7ef70a49fb8653bb983ae
|
|
4
|
+
data.tar.gz: 54a5943974b9b93be6dfed049b87566afd9c952c560f5b286e62dba46ee18d1c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e6bde8babeb983a210ebb849c01a407c620491be821260782b43977747d84b4c07b23e3878597d49e7e0a2421dd3aab10ffc5aa165403f35f56b152ecdcc8e4f
|
|
7
|
+
data.tar.gz: dec832c4c97ae6155a9b67ed0dade3254ea06509446855ace527b6d574018bcafa162ad9d0a5849bf68636365ef38e5627bd16639acae290c6eb58f3890f6eed
|
data/README.md
CHANGED
|
@@ -35,13 +35,13 @@ This design keeps your pricing, billing, and financial reporting consistent acro
|
|
|
35
35
|
|
|
36
36
|
Add to your `Gemfile`:
|
|
37
37
|
```ruby
|
|
38
|
-
gem 'whittaker_tech-midas'
|
|
38
|
+
gem 'whittaker_tech-midas'
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
Install and run migrations:
|
|
42
42
|
```bash
|
|
43
43
|
bundle install
|
|
44
|
-
bin/rails
|
|
44
|
+
bin/rails whittaker_tech:midas:install
|
|
45
45
|
bin/rails db:migrate
|
|
46
46
|
```
|
|
47
47
|
|
|
@@ -148,17 +148,9 @@ module WhittakerTech
|
|
|
148
148
|
# product.set_price(amount: 2999, currency_code: 'USD') # 2999 cents
|
|
149
149
|
define_method("set_#{name}") do |amount:, currency_code:|
|
|
150
150
|
iso = currency_code.to_s.upcase
|
|
151
|
-
cents =
|
|
152
|
-
case amount
|
|
153
|
-
when Money then amount.cents
|
|
154
|
-
when Integer then amount
|
|
155
|
-
when Numeric then (BigDecimal(amount.to_s) * (10**decimals_for(iso))).round.to_i
|
|
156
|
-
else raise ArgumentError, "Invalid value for #{name}: #{amount.inspect}"
|
|
157
|
-
end
|
|
158
|
-
|
|
159
151
|
coin = public_send(name) || public_send("build_#{assoc_name}", resource_label: label)
|
|
160
152
|
coin.currency_code = iso
|
|
161
|
-
coin.currency_minor =
|
|
153
|
+
coin.currency_minor = to_cents(name, amount, iso)
|
|
162
154
|
coin.resource = self
|
|
163
155
|
coin.save!
|
|
164
156
|
|
|
@@ -169,6 +161,19 @@ module WhittakerTech
|
|
|
169
161
|
|
|
170
162
|
private
|
|
171
163
|
|
|
164
|
+
def to_cents(name, amount, iso)
|
|
165
|
+
raise ArgumentError, "Invalid value for #{name}: #{amount.inspect}" unless is_valid_type?(amount)
|
|
166
|
+
|
|
167
|
+
return amount.cents if amount.is_a? Money
|
|
168
|
+
return amount if amount.is_a? Integer
|
|
169
|
+
|
|
170
|
+
(BigDecimal(amount.to_s) * (10**decimals_for(iso))).round.to_i
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def is_valid_type?(amount)
|
|
174
|
+
[Money, Integer, Numeric].any? { |klass| amount.is_a?(klass) }
|
|
175
|
+
end
|
|
176
|
+
|
|
172
177
|
# Determines the number of decimal places for a given currency.
|
|
173
178
|
#
|
|
174
179
|
# @param iso [String] The ISO currency code
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module WhittakerTech
|
|
4
|
+
module Midas
|
|
5
|
+
module Generators
|
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
|
7
|
+
desc 'Installs Midas and copies migrations.'
|
|
8
|
+
|
|
9
|
+
def copy_migrations
|
|
10
|
+
say_status 'migrations', 'Copying migrations for Midas...', :green
|
|
11
|
+
rake 'midas:install:migrations'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -1,4 +1,27 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
namespace :midas do
|
|
4
|
+
namespace :install do
|
|
5
|
+
desc 'Copy Midas migrations to your application.'
|
|
6
|
+
task migrations: :environment do
|
|
7
|
+
engine = WhittakerTech::Midas::Engine
|
|
8
|
+
source = engine.root.join('db/migrate')
|
|
9
|
+
destination = Rails.root.join('db/migrate')
|
|
10
|
+
|
|
11
|
+
FileUtils.mkdir_p(destination)
|
|
12
|
+
|
|
13
|
+
Dir.glob(source.join('*.rb')).each_with_index do |migration, i|
|
|
14
|
+
filename = File.basename(migration)
|
|
15
|
+
timestamp = (Time.now.utc + i).strftime('%Y%m%d%H%M%S')
|
|
16
|
+
target = destination.join("#{timestamp}_#{filename}")
|
|
17
|
+
|
|
18
|
+
if File.exist?(target)
|
|
19
|
+
puts "Skipping #{filename} because it already exists."
|
|
20
|
+
else
|
|
21
|
+
FileUtils.cp migration, target
|
|
22
|
+
puts "Copied #{filename} to #{target}."
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: whittaker_tech-midas
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lee Whittaker
|
|
@@ -51,20 +51,6 @@ dependencies:
|
|
|
51
51
|
- - "~>"
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
53
|
version: '6.4'
|
|
54
|
-
- !ruby/object:Gem::Dependency
|
|
55
|
-
name: pg
|
|
56
|
-
requirement: !ruby/object:Gem::Requirement
|
|
57
|
-
requirements:
|
|
58
|
-
- - "~>"
|
|
59
|
-
- !ruby/object:Gem::Version
|
|
60
|
-
version: '1.5'
|
|
61
|
-
type: :development
|
|
62
|
-
prerelease: false
|
|
63
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
-
requirements:
|
|
65
|
-
- - "~>"
|
|
66
|
-
- !ruby/object:Gem::Version
|
|
67
|
-
version: '1.5'
|
|
68
54
|
- !ruby/object:Gem::Dependency
|
|
69
55
|
name: puma
|
|
70
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -149,10 +135,11 @@ dependencies:
|
|
|
149
135
|
- - "~>"
|
|
150
136
|
- !ruby/object:Gem::Version
|
|
151
137
|
version: '3.5'
|
|
152
|
-
description:
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
138
|
+
description: |
|
|
139
|
+
WhittakerTech Midas is a Rails engine that provides elegant multi-currency support
|
|
140
|
+
through a single polymorphic Coin model. Instead of adding price_cents/price_currency
|
|
141
|
+
columns to every model, Midas stores all monetary values in one place with a simple
|
|
142
|
+
has_coins DSL. Includes bank-style currency input fields powered by Stimulus.
|
|
156
143
|
email:
|
|
157
144
|
- lee@whittakertech.com
|
|
158
145
|
executables: []
|
|
@@ -176,8 +163,8 @@ files:
|
|
|
176
163
|
- app/views/layouts/whittaker_tech/midas/application.html.erb
|
|
177
164
|
- app/views/layouts/whittaker_tech/midas/shared/_currency_field.html.erb
|
|
178
165
|
- config/locales/midas.en.yml
|
|
179
|
-
-
|
|
180
|
-
-
|
|
166
|
+
- db/migrate/create_wt_midas_coins.rb
|
|
167
|
+
- lib/generators/whittaker_tech/midas/install/install_generator.rb
|
|
181
168
|
- lib/tasks/whittaker_tech/midas_tasks.rake
|
|
182
169
|
- lib/whittaker_tech/midas.rb
|
|
183
170
|
- lib/whittaker_tech/midas/engine.rb
|
|
@@ -188,10 +175,9 @@ licenses:
|
|
|
188
175
|
metadata:
|
|
189
176
|
homepage_uri: https://github.com/whittakertech/midas
|
|
190
177
|
source_code_uri: https://github.com/whittakertech/midas
|
|
191
|
-
changelog_uri: https://github.com/whittakertech/midas/blob/
|
|
178
|
+
changelog_uri: https://github.com/whittakertech/midas/blob/master/CHANGELOG.md
|
|
192
179
|
bug_tracker_uri: https://github.com/whittakertech/midas/issues
|
|
193
180
|
documentation_uri: https://midas.whittakertech.com/
|
|
194
|
-
rubygems_mfa_required: 'true'
|
|
195
181
|
rdoc_options: []
|
|
196
182
|
require_paths:
|
|
197
183
|
- lib
|
|
@@ -206,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
206
192
|
- !ruby/object:Gem::Version
|
|
207
193
|
version: '0'
|
|
208
194
|
requirements: []
|
|
209
|
-
rubygems_version: 3.
|
|
195
|
+
rubygems_version: 3.6.9
|
|
210
196
|
specification_version: 4
|
|
211
197
|
summary: Multi-currency money management for Rails with polymorphic coin storage
|
|
212
198
|
test_files: []
|
data/config/routes.rb
DELETED
|
File without changes
|