amountable 0.2.8 → 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
- SHA1:
3
- metadata.gz: 6b550023b833cb60747b7b9fa15e3d10b6ebbada
4
- data.tar.gz: 0a6f0a5deaa1ca23545626debdbea1cbf5b0df6f
2
+ SHA256:
3
+ metadata.gz: 7f15a987389dd56fc45dcddf6145adddbfe47bfc8b3b7666180c1bd51d7638a1
4
+ data.tar.gz: 1a23700ce3d891c26c35e53fe2d2e3c2d07dea910b0e6057a71aa17740933b6b
5
5
  SHA512:
6
- metadata.gz: 2854582ba8a38cae2e22c6efce04e433771226fe8c38c130060ab88daaf17903cc4629b26a3a234f478f3b6880cca91f3517b0b08cd71616e859beaa78cba866
7
- data.tar.gz: c9be64517ccc33672379e0ae9829e24bca3197ec7fe7f0fcf9a0dd48d2062f39ae5586a8bc7dcb78be65665606091665cb83dc12e745e98a68a4671cda8d7a90
6
+ metadata.gz: 3642a8c7ad8a7eb8ff0e039cb77abadb6ee11b4d53521e53028d2b4c74ad71e8a3ed1ab3762e36e55067d8e31813dfde1c0a2fdf1ae15fdf7583bac6f4ba65b4
7
+ data.tar.gz: 68285488fe760b730d09fd54640e2529bd579dbb3227cd313842ae8c7f5d4aa6db6d46d0e7bc7dc7a03541c0cf8de78a6aadb731fb654252df217f2ffa4a7a38
@@ -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,51 @@
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
+ - '2.6'
16
+ - '2.7'
17
+ activerecord:
18
+ - '6.1'
19
+ - '6.0'
20
+ - '5.2'
21
+ services:
22
+ postgres:
23
+ image: postgres:12
24
+ ports:
25
+ - 5432:5432
26
+ env:
27
+ POSTGRES_HOST_AUTH_METHOD: trust
28
+ POSTGRES_DB: amountable_test
29
+ options: >-
30
+ --health-cmd pg_isready
31
+ --health-interval 10s
32
+ --health-timeout 5s
33
+ --health-retries 5
34
+
35
+ name: Ruby ${{ matrix.ruby }} / ActiveRecord ${{ matrix.activerecord }}
36
+ env:
37
+ BUNDLE_GEMFILE: gemfiles/activerecord_${{ matrix.activerecord }}.gemfile
38
+ steps:
39
+ - uses: actions/checkout@v2
40
+ - run: |
41
+ sudo apt-get -yqq install libpq-dev
42
+ - uses: ruby/setup-ruby@v1
43
+ with:
44
+ ruby-version: ${{ matrix.ruby }}
45
+ bundler-cache: true
46
+ - run: |
47
+ bundle exec rake
48
+ env:
49
+ PGHOST: 127.0.0.1
50
+ PGUSER: postgres
51
+ 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
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ gemfiles/*.lock
11
+ *.log
data/.rspec CHANGED
@@ -1 +1 @@
1
- --colour
1
+ --force-color
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright © 2015-2016, Instacart
1
+ Copyright © 2015-2021, Instacart
2
2
 
3
3
  Permission to use, copy, modify, and/or distribute this software for any
4
4
  purpose with or without fee is hereby granted, provided that the above
data/amountable.gemspec CHANGED
@@ -15,12 +15,11 @@ 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.1.1'
18
+ gem.required_ruby_version = '>= 2.6'
19
19
 
20
- gem.add_dependency 'activerecord', '>= 4.1', '< 5.1'
21
- gem.add_dependency 'activesupport', '>= 4.1', '< 5.1'
22
- gem.add_dependency 'activerecord-import', '~> 0.19.1'
23
- gem.add_dependency 'money-rails'
20
+ gem.add_dependency 'activerecord', '>= 5.2', '< 7'
21
+ gem.add_dependency 'activerecord-import', '>= 0.19.1'
22
+ gem.add_dependency 'money-rails', '>=1.7.0'
24
23
  gem.add_dependency 'monetize'
25
24
 
26
25
  gem.add_development_dependency 'sqlite3'
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  class CreateAmounts < ActiveRecord::Migration
4
4
  def change
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: "../"
4
+
5
+ gem "activerecord", "~> 5.2.0"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: "../"
4
+
5
+ gem "activerecord", "~> 6.0.0"
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec path: "../"
4
+
5
+ gem "activerecord", "~> 6.1.0"
@@ -1,21 +1,7 @@
1
- # Copyright 2015-2017, Instacart
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-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  module Amountable
4
4
  module JsonbMethods
@@ -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
- Amount.new(name: name, value_cents: amount['cents'], value_currency: amount['currency'], persistable: false, amountable: self)
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
 
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  module Amountable
4
4
  class NilAmount
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  module Amountable
4
4
  module Operations
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  module Amountable
4
4
  module TableMethods
@@ -1,5 +1,5 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  module Amountable
4
- VERSION = '0.2.8'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -0,0 +1,35 @@
1
+ # Copyright 2015-2021, 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/lib/amountable.rb CHANGED
@@ -1,9 +1,10 @@
1
- # Copyright 2015-2017, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  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
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
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.update_attributes(sub_total: Money.new(200)))
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.update_attributes(sub_total: Money.new(200))
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
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  require 'spec_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  class Order < ActiveRecord::Base
4
4
 
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  if jsonb_available?
4
4
  class Subscription < ActiveRecord::Base
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  ActiveRecord::Schema.define do
4
4
 
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  ENV['RAILS_ENV'] = 'test'
4
4
  require 'rails'
@@ -1,4 +1,4 @@
1
- # Copyright 2015-2016, Instacart
1
+ # Copyright 2015-2021, Instacart
2
2
 
3
3
  db_name = ENV['DB'] || 'postgresql'
4
4
  spec_dir = Pathname.new(File.dirname(__FILE__)) / '..'
@@ -10,7 +10,7 @@ ActiveRecord::Migration.verbose = false
10
10
  ActiveRecord::Base.default_timezone = :utc
11
11
  ActiveRecord::Base.configurations = YAML.load_file(database_yml)
12
12
  ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), '../debug.log'))
13
- ActiveRecord::Base.logger.level = ENV['TRAVIS'] ? ::Logger::ERROR : ::Logger::DEBUG
13
+ ActiveRecord::Base.logger.level = ENV['CI'] ? ::Logger::ERROR : ::Logger::DEBUG
14
14
  config = ActiveRecord::Base.configurations[db_name]
15
15
 
16
16
  begin
@@ -30,13 +30,7 @@ rescue
30
30
  end
31
31
 
32
32
  def jsonb_available?
33
- return @@jsonb_available if defined?(@@jsonb_available)
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.8
4
+ version: 0.4.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: 2018-03-27 00:00:00.000000000 Z
11
+ date: 2021-10-01 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: '4.1'
19
+ version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.1'
22
+ version: '7'
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: '4.1'
29
+ version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.1'
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.1'
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.1'
32
+ version: '7'
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
@@ -70,14 +50,14 @@ dependencies:
70
50
  requirements:
71
51
  - - ">="
72
52
  - !ruby/object:Gem::Version
73
- version: '0'
53
+ version: 1.7.0
74
54
  type: :runtime
75
55
  prerelease: false
76
56
  version_requirements: !ruby/object:Gem::Requirement
77
57
  requirements:
78
58
  - - ">="
79
59
  - !ruby/object:Gem::Version
80
- version: '0'
60
+ version: 1.7.0
81
61
  - !ruby/object:Gem::Dependency
82
62
  name: monetize
83
63
  requirement: !ruby/object:Gem::Requirement
@@ -198,15 +178,20 @@ 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
210
195
  - lib/amountable.rb
211
196
  - lib/amountable/amount.rb
212
197
  - lib/amountable/jsonb_methods.rb
@@ -214,6 +199,7 @@ files:
214
199
  - lib/amountable/operations.rb
215
200
  - lib/amountable/table_methods.rb
216
201
  - lib/amountable/version.rb
202
+ - lib/amountable/virtual_amount.rb
217
203
  - spec/amountable/amount_spec.rb
218
204
  - spec/amountable/amountable_spec.rb
219
205
  - spec/amountable/nil_amount_spec.rb
@@ -236,15 +222,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
236
222
  requirements:
237
223
  - - ">="
238
224
  - !ruby/object:Gem::Version
239
- version: 2.1.1
225
+ version: '2.6'
240
226
  required_rubygems_version: !ruby/object:Gem::Requirement
241
227
  requirements:
242
228
  - - ">="
243
229
  - !ruby/object:Gem::Version
244
230
  version: '0'
245
231
  requirements: []
246
- rubyforge_project:
247
- rubygems_version: 2.5.2.2
232
+ rubygems_version: 3.2.22
248
233
  signing_key:
249
234
  specification_version: 4
250
235
  summary: Easy Money fields for your Rails models.
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.2
4
- addons:
5
- postgresql: "9.4"