amountable 0.2.6 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/CI.yml +43 -0
- data/.github/workflows/gem-push.yml +34 -0
- data/amountable.gemspec +4 -4
- data/lib/amountable.rb +1 -1
- data/lib/amountable/jsonb_methods.rb +1 -1
- data/lib/amountable/version.rb +1 -1
- data/lib/amountable/virtual_amount.rb +35 -0
- data/spec/support/database.rb +1 -7
- metadata +13 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aee387d2d2d88c2fc8086dd0cc4b09293e775bd3c9a4f5e6bc507d18ca06976b
|
4
|
+
data.tar.gz: 93b2fef942db13a396dae78c9fe533d74290f7ffd47b0df6d581fe8e5fdcbf72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c090c0efc1c00740a594f805fa49c967adce57369b19d5d509be9c1d708e454a9ce778d7d262aee3ae387d050e6f5b70692fc9a4b4f06ad520732388e78bf5e
|
7
|
+
data.tar.gz: 4119055f5f5e0631abf38758e638e2fa5619b5136c09a740a799bbe1b9743d36a662b37f7a091a0129090b397cf800b91c15e5fd7d3429d1b56d91a9ec451666
|
@@ -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,43 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
ruby:
|
13
|
+
- 2.6
|
14
|
+
- 2.7
|
15
|
+
services:
|
16
|
+
postgres:
|
17
|
+
image: postgres:12
|
18
|
+
ports:
|
19
|
+
- 5432:5432
|
20
|
+
env:
|
21
|
+
POSTGRES_HOST_AUTH_METHOD: trust
|
22
|
+
POSTGRES_DB: amountable_test
|
23
|
+
options: >-
|
24
|
+
--health-cmd pg_isready
|
25
|
+
--health-interval 10s
|
26
|
+
--health-timeout 5s
|
27
|
+
--health-retries 5
|
28
|
+
|
29
|
+
name: Ruby ${{ matrix.ruby }}
|
30
|
+
steps:
|
31
|
+
- uses: actions/checkout@v2
|
32
|
+
- run: |
|
33
|
+
sudo apt-get -yqq install libpq-dev
|
34
|
+
- uses: ruby/setup-ruby@v1
|
35
|
+
with:
|
36
|
+
ruby-version: ${{ matrix.ruby }}
|
37
|
+
bundler-cache: true
|
38
|
+
- run: |
|
39
|
+
bundle exec rake
|
40
|
+
env:
|
41
|
+
PGHOST: 127.0.0.1
|
42
|
+
PGUSER: postgres
|
43
|
+
RAILS_ENV: test
|
@@ -0,0 +1,34 @@
|
|
1
|
+
name: Ruby 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/amountable.gemspec
CHANGED
@@ -17,10 +17,10 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.require_paths = ['lib']
|
18
18
|
gem.required_ruby_version = '>= 2.1.1'
|
19
19
|
|
20
|
-
gem.add_dependency 'activerecord', '>= 4.1', '<
|
21
|
-
gem.add_dependency 'activesupport', '>= 4.1'
|
22
|
-
gem.add_dependency 'activerecord-import', '
|
23
|
-
gem.add_dependency 'money-rails'
|
20
|
+
gem.add_dependency 'activerecord', '>= 4.1', '< 6.1'
|
21
|
+
gem.add_dependency 'activesupport', '>= 4.1'
|
22
|
+
gem.add_dependency 'activerecord-import', '>= 0.19.1'
|
23
|
+
gem.add_dependency 'money-rails', '>=1.7.0'
|
24
24
|
gem.add_dependency 'monetize'
|
25
25
|
|
26
26
|
gem.add_development_dependency 'sqlite3'
|
data/lib/amountable.rb
CHANGED
@@ -4,6 +4,7 @@ module Amountable
|
|
4
4
|
extend ActiveSupport::Autoload
|
5
5
|
autoload :Operations
|
6
6
|
autoload :Amount
|
7
|
+
autoload :VirtualAmount
|
7
8
|
autoload :NilAmount
|
8
9
|
autoload :VERSION
|
9
10
|
autoload :TableMethods
|
@@ -71,7 +72,6 @@ module Amountable
|
|
71
72
|
include Amountable::TableMethods
|
72
73
|
when :jsonb
|
73
74
|
self.amounts_column_name = options[:column].to_s if options[:column]
|
74
|
-
raise MissingColumn.new("You need an amounts jsonb field on the #{self.table_name} table.") unless column_names.include?(self.amounts_column_name)
|
75
75
|
include Amountable::JsonbMethods
|
76
76
|
else
|
77
77
|
raise ArgumentError.new("Please specify a storage: #{ALLOWED_STORAGE}")
|
@@ -6,7 +6,7 @@ module Amountable
|
|
6
6
|
|
7
7
|
def amounts
|
8
8
|
@_amounts ||= attribute(amounts_column_name).to_h['amounts'].to_h.map do |name, amount|
|
9
|
-
|
9
|
+
Amountable::VirtualAmount.new(name: name, value_cents: amount['cents'], value_currency: amount['currency'], persistable: false, amountable: self)
|
10
10
|
end.to_set
|
11
11
|
end
|
12
12
|
|
data/lib/amountable/version.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Copyright 2015-2017, Instacart
|
2
|
+
|
3
|
+
module Amountable
|
4
|
+
class VirtualAmount
|
5
|
+
include ActiveModel::Model
|
6
|
+
|
7
|
+
attr_accessor :amountable, :value_cents, :value_currency, :name, :persistable
|
8
|
+
|
9
|
+
include Amountable::Operations
|
10
|
+
|
11
|
+
validates :name, presence: true
|
12
|
+
|
13
|
+
def value
|
14
|
+
Money.new(value_cents, value_currency)
|
15
|
+
end
|
16
|
+
|
17
|
+
def value=(val)
|
18
|
+
self.value_cents = value.fractional
|
19
|
+
self.value_currency = value.currency.iso_code
|
20
|
+
end
|
21
|
+
|
22
|
+
def new_record?
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def persisted?
|
27
|
+
false
|
28
|
+
end
|
29
|
+
|
30
|
+
def save
|
31
|
+
raise StandardError.new("Can't persist amount to database") if persistable == false
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/support/database.rb
CHANGED
@@ -30,13 +30,7 @@ rescue
|
|
30
30
|
end
|
31
31
|
|
32
32
|
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
|
33
|
+
true
|
40
34
|
end
|
41
35
|
|
42
36
|
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.2
|
4
|
+
version: 0.3.2
|
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: 2021-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '4.1'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '6.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '4.1'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '6.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activesupport
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -37,9 +37,6 @@ dependencies:
|
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '4.1'
|
40
|
-
- - "<"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '5.1'
|
43
40
|
type: :runtime
|
44
41
|
prerelease: false
|
45
42
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -47,21 +44,18 @@ dependencies:
|
|
47
44
|
- - ">="
|
48
45
|
- !ruby/object:Gem::Version
|
49
46
|
version: '4.1'
|
50
|
-
- - "<"
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '5.1'
|
53
47
|
- !ruby/object:Gem::Dependency
|
54
48
|
name: activerecord-import
|
55
49
|
requirement: !ruby/object:Gem::Requirement
|
56
50
|
requirements:
|
57
|
-
- - "
|
51
|
+
- - ">="
|
58
52
|
- !ruby/object:Gem::Version
|
59
53
|
version: 0.19.1
|
60
54
|
type: :runtime
|
61
55
|
prerelease: false
|
62
56
|
version_requirements: !ruby/object:Gem::Requirement
|
63
57
|
requirements:
|
64
|
-
- - "
|
58
|
+
- - ">="
|
65
59
|
- !ruby/object:Gem::Version
|
66
60
|
version: 0.19.1
|
67
61
|
- !ruby/object:Gem::Dependency
|
@@ -70,14 +64,14 @@ dependencies:
|
|
70
64
|
requirements:
|
71
65
|
- - ">="
|
72
66
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
67
|
+
version: 1.7.0
|
74
68
|
type: :runtime
|
75
69
|
prerelease: false
|
76
70
|
version_requirements: !ruby/object:Gem::Requirement
|
77
71
|
requirements:
|
78
72
|
- - ">="
|
79
73
|
- !ruby/object:Gem::Version
|
80
|
-
version:
|
74
|
+
version: 1.7.0
|
81
75
|
- !ruby/object:Gem::Dependency
|
82
76
|
name: monetize
|
83
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,6 +192,9 @@ executables: []
|
|
198
192
|
extensions: []
|
199
193
|
extra_rdoc_files: []
|
200
194
|
files:
|
195
|
+
- ".github/dependabot.yml"
|
196
|
+
- ".github/workflows/CI.yml"
|
197
|
+
- ".github/workflows/gem-push.yml"
|
201
198
|
- ".gitignore"
|
202
199
|
- ".rspec"
|
203
200
|
- ".travis.yml"
|
@@ -214,6 +211,7 @@ files:
|
|
214
211
|
- lib/amountable/operations.rb
|
215
212
|
- lib/amountable/table_methods.rb
|
216
213
|
- lib/amountable/version.rb
|
214
|
+
- lib/amountable/virtual_amount.rb
|
217
215
|
- spec/amountable/amount_spec.rb
|
218
216
|
- spec/amountable/amountable_spec.rb
|
219
217
|
- spec/amountable/nil_amount_spec.rb
|
@@ -243,8 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
243
241
|
- !ruby/object:Gem::Version
|
244
242
|
version: '0'
|
245
243
|
requirements: []
|
246
|
-
|
247
|
-
rubygems_version: 2.5.2
|
244
|
+
rubygems_version: 3.1.4
|
248
245
|
signing_key:
|
249
246
|
specification_version: 4
|
250
247
|
summary: Easy Money fields for your Rails models.
|