amountable 0.3.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/CI.yml +58 -0
- data/.github/workflows/gem-publish-public.yml +34 -0
- data/.gitignore +2 -0
- data/.rspec +1 -1
- data/LICENSE +1 -1
- data/amountable.gemspec +3 -4
- data/db/migrate/0_create_amounts.rb +1 -1
- data/gemfiles/activerecord_5.2.gemfile +5 -0
- data/gemfiles/activerecord_6.0.gemfile +5 -0
- data/gemfiles/activerecord_6.1.gemfile +5 -0
- data/gemfiles/activerecord_7.0.gemfile +5 -0
- data/lib/amountable/amount.rb +2 -17
- data/lib/amountable/jsonb_methods.rb +1 -1
- data/lib/amountable/nil_amount.rb +1 -1
- data/lib/amountable/operations.rb +1 -1
- data/lib/amountable/table_methods.rb +5 -5
- data/lib/amountable/version.rb +2 -2
- data/lib/amountable/virtual_amount.rb +1 -1
- data/lib/amountable.rb +3 -1
- data/spec/amountable/amount_spec.rb +1 -1
- data/spec/amountable/amountable_spec.rb +3 -3
- data/spec/amountable/nil_amount_spec.rb +1 -1
- data/spec/internal/app/models/order.rb +1 -1
- data/spec/internal/app/models/subscription.rb +1 -1
- data/spec/internal/db/schema.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/database.rb +11 -10
- metadata +17 -32
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65db41fdb8408b564c411d3ccd1af1e472283c5c3d3f315eafc32b5a9f027315
|
4
|
+
data.tar.gz: 5741d0ea7a24844389f7f522fca71f180b4271d0572647d0ccbb110ad1506d03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee011dcc7d65f146f331243798ce8c2198994215f9b6a565b1e859270eb38a852bd137bcb45dcdb0cd60eae7b43ba90d57d70dffc2669213b42e21123f954d65
|
7
|
+
data.tar.gz: 0a509e297d204a95326072236cc036b493b95e90204bc5170410b07163b9760135797e3928fedd97668c242565addd26eb76845523cacd2a72b9e3089a0cdfcf
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
3
|
+
# Please see the documentation for all configuration options:
|
4
|
+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
5
|
+
|
6
|
+
version: 2
|
7
|
+
updates:
|
8
|
+
- package-ecosystem: "bundler" # See documentation for possible values
|
9
|
+
directory: "/" # Location of package manifests
|
10
|
+
schedule:
|
11
|
+
interval: "daily"
|
@@ -0,0 +1,58 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
pull_request:
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby:
|
15
|
+
- '3.1'
|
16
|
+
- '3.0'
|
17
|
+
- '2.7'
|
18
|
+
activerecord:
|
19
|
+
- '7.0'
|
20
|
+
- '6.1'
|
21
|
+
- '6.0'
|
22
|
+
- '5.2'
|
23
|
+
exclude:
|
24
|
+
- activerecord: '5.2'
|
25
|
+
ruby: '3.0'
|
26
|
+
- activerecord: '5.2'
|
27
|
+
ruby: '3.1'
|
28
|
+
services:
|
29
|
+
postgres:
|
30
|
+
image: postgres:12
|
31
|
+
ports:
|
32
|
+
- 5432:5432
|
33
|
+
env:
|
34
|
+
POSTGRES_HOST_AUTH_METHOD: trust
|
35
|
+
POSTGRES_DB: amountable_test
|
36
|
+
options: >-
|
37
|
+
--health-cmd pg_isready
|
38
|
+
--health-interval 10s
|
39
|
+
--health-timeout 5s
|
40
|
+
--health-retries 5
|
41
|
+
|
42
|
+
name: Ruby ${{ matrix.ruby }} / ActiveRecord ${{ matrix.activerecord }}
|
43
|
+
env:
|
44
|
+
BUNDLE_GEMFILE: gemfiles/activerecord_${{ matrix.activerecord }}.gemfile
|
45
|
+
steps:
|
46
|
+
- uses: actions/checkout@v2
|
47
|
+
- run: |
|
48
|
+
sudo apt-get -yqq install libpq-dev
|
49
|
+
- uses: ruby/setup-ruby@v1
|
50
|
+
with:
|
51
|
+
ruby-version: ${{ matrix.ruby }}
|
52
|
+
bundler-cache: true
|
53
|
+
- run: |
|
54
|
+
bundle exec rake
|
55
|
+
env:
|
56
|
+
PGHOST: 127.0.0.1
|
57
|
+
PGUSER: postgres
|
58
|
+
RAILS_ENV: test
|
@@ -0,0 +1,34 @@
|
|
1
|
+
name: Publish Public Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
release:
|
5
|
+
types:
|
6
|
+
- published
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
name: Build + Publish
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
- uses: actions/setup-ruby@v1
|
16
|
+
- name: Build
|
17
|
+
run: |
|
18
|
+
gem build *.gemspec
|
19
|
+
- name: Publish to Github
|
20
|
+
run: |
|
21
|
+
mkdir -p $HOME/.gem
|
22
|
+
touch $HOME/.gem/credentials
|
23
|
+
chmod 0600 $HOME/.gem/credentials
|
24
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
25
|
+
gem push --verbose --key github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
26
|
+
env:
|
27
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
28
|
+
OWNER: ${{ github.repository_owner }}
|
29
|
+
continue-on-error: true
|
30
|
+
- name: Publish to RubyGems
|
31
|
+
run: |
|
32
|
+
gem push --verbose *.gem
|
33
|
+
env:
|
34
|
+
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_TOKEN}}
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--
|
1
|
+
--force-color
|
data/LICENSE
CHANGED
data/amountable.gemspec
CHANGED
@@ -15,11 +15,10 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.test_files = gem.files.grep(%r{^spec/})
|
17
17
|
gem.require_paths = ['lib']
|
18
|
-
gem.required_ruby_version = '>= 2.
|
18
|
+
gem.required_ruby_version = '>= 2.7'
|
19
19
|
|
20
|
-
gem.add_dependency 'activerecord', '>=
|
21
|
-
gem.add_dependency '
|
22
|
-
gem.add_dependency 'activerecord-import', '~> 0.19.1'
|
20
|
+
gem.add_dependency 'activerecord', '>= 5.2', '< 8'
|
21
|
+
gem.add_dependency 'activerecord-import', '>= 0.19.1'
|
23
22
|
gem.add_dependency 'money-rails', '>=1.7.0'
|
24
23
|
gem.add_dependency 'monetize'
|
25
24
|
|
data/lib/amountable/amount.rb
CHANGED
@@ -1,21 +1,7 @@
|
|
1
|
-
# Copyright 2015-
|
1
|
+
# Copyright 2015-2021, Instacart
|
2
2
|
|
3
3
|
module Amountable
|
4
4
|
class Amount < ActiveRecord::Base
|
5
|
-
class_attribute :columns
|
6
|
-
self.columns = []
|
7
|
-
|
8
|
-
def self.column(name, sql_type = nil, default = nil, null = true)
|
9
|
-
type = "ActiveRecord::Type::#{sql_type.to_s.camelize}".constantize.new
|
10
|
-
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, type, null)
|
11
|
-
end
|
12
|
-
|
13
|
-
column :amountable_type, :string, nil, false
|
14
|
-
column :amountable_id, :integer, nil, false
|
15
|
-
column :value_currency, :string, nil, true
|
16
|
-
column :value_cents, :integer, 0, false
|
17
|
-
column :name, :string, nil, false
|
18
|
-
|
19
5
|
include Amountable::Operations
|
20
6
|
|
21
7
|
belongs_to :amountable, polymorphic: true
|
@@ -31,6 +17,5 @@ module Amountable
|
|
31
17
|
raise StandardError.new("Can't persist amount to database") if persistable == false
|
32
18
|
super
|
33
19
|
end
|
34
|
-
|
35
20
|
end
|
36
|
-
end
|
21
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2015-
|
1
|
+
# Copyright 2015-2021, Instacart
|
2
2
|
|
3
3
|
module Amountable
|
4
4
|
module TableMethods
|
@@ -19,15 +19,15 @@ module Amountable
|
|
19
19
|
amount.value
|
20
20
|
end
|
21
21
|
|
22
|
-
def save(args
|
22
|
+
def save(**args)
|
23
23
|
ActiveRecord::Base.transaction do
|
24
|
-
save_amounts if super
|
24
|
+
save_amounts if super
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def save!(args
|
28
|
+
def save!(**args)
|
29
29
|
ActiveRecord::Base.transaction do
|
30
|
-
save_amounts! if super
|
30
|
+
save_amounts! if super
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
data/lib/amountable/version.rb
CHANGED
data/lib/amountable.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2015-
|
1
|
+
# Copyright 2015-2021, Instacart
|
2
2
|
|
3
3
|
module Amountable
|
4
4
|
extend ActiveSupport::Autoload
|
@@ -119,6 +119,7 @@ module Amountable
|
|
119
119
|
super
|
120
120
|
end
|
121
121
|
end
|
122
|
+
ruby2_keywords :where if Module.private_method_defined?(:ruby2_keywords)
|
122
123
|
|
123
124
|
def where_json(opts, *rest)
|
124
125
|
values = []
|
@@ -136,6 +137,7 @@ module Amountable
|
|
136
137
|
query = [query.join(' AND ')] + values
|
137
138
|
where(query, *rest).where(opts, *rest)
|
138
139
|
end
|
140
|
+
ruby2_keywords :where_json if Module.private_method_defined?(:ruby2_keywords)
|
139
141
|
|
140
142
|
def pg_json_field_access(name, field = :cents)
|
141
143
|
name = name.to_sym
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2015-
|
1
|
+
# Copyright 2015-2021, Instacart
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
@@ -23,7 +23,7 @@ describe Amountable do
|
|
23
23
|
expect(amount.persisted?).to be true
|
24
24
|
end
|
25
25
|
expect do
|
26
|
-
expect(order.
|
26
|
+
expect(order.update(sub_total: Money.new(200)))
|
27
27
|
end.not_to change { Amountable::Amount.count }
|
28
28
|
end
|
29
29
|
|
@@ -80,7 +80,7 @@ describe Amountable do
|
|
80
80
|
expect { subscription.save }.not_to change { Amountable::Amount.count }
|
81
81
|
expect(amount.persisted?).to be false
|
82
82
|
end
|
83
|
-
subscription.
|
83
|
+
subscription.update(sub_total: Money.new(200))
|
84
84
|
expect(subscription.sub_total).to eq(Money.new(200))
|
85
85
|
expect(subscription.total).to eq(Money.new(200))
|
86
86
|
subscription.sub_total = Money.zero
|
data/spec/internal/db/schema.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/support/database.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
# Copyright 2015-
|
1
|
+
# Copyright 2015-2021, Instacart
|
2
|
+
|
3
|
+
require "activerecord-import/base"
|
2
4
|
|
3
5
|
db_name = ENV['DB'] || 'postgresql'
|
4
6
|
spec_dir = Pathname.new(File.dirname(__FILE__)) / '..'
|
@@ -6,12 +8,17 @@ database_yml = spec_dir.join('internal/config/database.yml')
|
|
6
8
|
|
7
9
|
fail "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample" unless File.exist?(database_yml)
|
8
10
|
|
11
|
+
module ActiveRecord::Import::Connection
|
12
|
+
ruby2_keywords :establish_connection if Module.private_method_defined?(:ruby2_keywords)
|
13
|
+
end
|
14
|
+
|
9
15
|
ActiveRecord::Migration.verbose = false
|
10
16
|
ActiveRecord::Base.default_timezone = :utc
|
11
17
|
ActiveRecord::Base.configurations = YAML.load_file(database_yml)
|
12
18
|
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), '../debug.log'))
|
13
|
-
ActiveRecord::Base.logger.level = ENV['
|
14
|
-
|
19
|
+
ActiveRecord::Base.logger.level = ENV['CI'] ? ::Logger::ERROR : ::Logger::DEBUG
|
20
|
+
configs = ActiveRecord::Base.configurations
|
21
|
+
config = configs.try(:find_db_config, db_name) || configs[db_name]
|
15
22
|
|
16
23
|
begin
|
17
24
|
ActiveRecord::Base.establish_connection(db_name.to_sym)
|
@@ -30,13 +37,7 @@ rescue
|
|
30
37
|
end
|
31
38
|
|
32
39
|
def jsonb_available?
|
33
|
-
|
34
|
-
@@jsonb_available = if ActiveRecord::Base.connection.class.ancestors.include?(ActiveRecord::Import::PostgreSQLAdapter)
|
35
|
-
version = /PostgreSQL\s(\d+.\d+.\d+)\s/.match(ActiveRecord::Base.connection.execute("select version();")[0]['version'])[1].split('.').map(&:to_i)
|
36
|
-
version[0] >= 9 && version[1] >= 3
|
37
|
-
else
|
38
|
-
false
|
39
|
-
end
|
40
|
+
true
|
40
41
|
end
|
41
42
|
|
42
43
|
require_relative '../internal/db/schema'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amountable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emmanuel Turlay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,52 +16,32 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '8'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '5.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: activesupport
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - ">="
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '4.1'
|
40
|
-
- - "<"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '5.3'
|
43
|
-
type: :runtime
|
44
|
-
prerelease: false
|
45
|
-
version_requirements: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '4.1'
|
50
|
-
- - "<"
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '5.3'
|
32
|
+
version: '8'
|
53
33
|
- !ruby/object:Gem::Dependency
|
54
34
|
name: activerecord-import
|
55
35
|
requirement: !ruby/object:Gem::Requirement
|
56
36
|
requirements:
|
57
|
-
- - "
|
37
|
+
- - ">="
|
58
38
|
- !ruby/object:Gem::Version
|
59
39
|
version: 0.19.1
|
60
40
|
type: :runtime
|
61
41
|
prerelease: false
|
62
42
|
version_requirements: !ruby/object:Gem::Requirement
|
63
43
|
requirements:
|
64
|
-
- - "
|
44
|
+
- - ">="
|
65
45
|
- !ruby/object:Gem::Version
|
66
46
|
version: 0.19.1
|
67
47
|
- !ruby/object:Gem::Dependency
|
@@ -198,15 +178,21 @@ executables: []
|
|
198
178
|
extensions: []
|
199
179
|
extra_rdoc_files: []
|
200
180
|
files:
|
181
|
+
- ".github/dependabot.yml"
|
182
|
+
- ".github/workflows/CI.yml"
|
183
|
+
- ".github/workflows/gem-publish-public.yml"
|
201
184
|
- ".gitignore"
|
202
185
|
- ".rspec"
|
203
|
-
- ".travis.yml"
|
204
186
|
- Gemfile
|
205
187
|
- LICENSE
|
206
188
|
- README.md
|
207
189
|
- Rakefile
|
208
190
|
- amountable.gemspec
|
209
191
|
- db/migrate/0_create_amounts.rb
|
192
|
+
- gemfiles/activerecord_5.2.gemfile
|
193
|
+
- gemfiles/activerecord_6.0.gemfile
|
194
|
+
- gemfiles/activerecord_6.1.gemfile
|
195
|
+
- gemfiles/activerecord_7.0.gemfile
|
210
196
|
- lib/amountable.rb
|
211
197
|
- lib/amountable/amount.rb
|
212
198
|
- lib/amountable/jsonb_methods.rb
|
@@ -237,15 +223,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
237
223
|
requirements:
|
238
224
|
- - ">="
|
239
225
|
- !ruby/object:Gem::Version
|
240
|
-
version: 2.
|
226
|
+
version: '2.7'
|
241
227
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
242
228
|
requirements:
|
243
229
|
- - ">="
|
244
230
|
- !ruby/object:Gem::Version
|
245
231
|
version: '0'
|
246
232
|
requirements: []
|
247
|
-
|
248
|
-
rubygems_version: 2.7.6
|
233
|
+
rubygems_version: 3.2.32
|
249
234
|
signing_key:
|
250
235
|
specification_version: 4
|
251
236
|
summary: Easy Money fields for your Rails models.
|