amountable 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b550023b833cb60747b7b9fa15e3d10b6ebbada
4
- data.tar.gz: 0a6f0a5deaa1ca23545626debdbea1cbf5b0df6f
3
+ metadata.gz: 150e7fb0a09dce9fd26118253413dda2602a5a87
4
+ data.tar.gz: 6472352d7d6211f86a6caf508bd80b73c1480e98
5
5
  SHA512:
6
- metadata.gz: 2854582ba8a38cae2e22c6efce04e433771226fe8c38c130060ab88daaf17903cc4629b26a3a234f478f3b6880cca91f3517b0b08cd71616e859beaa78cba866
7
- data.tar.gz: c9be64517ccc33672379e0ae9829e24bca3197ec7fe7f0fcf9a0dd48d2062f39ae5586a8bc7dcb78be65665606091665cb83dc12e745e98a68a4671cda8d7a90
6
+ metadata.gz: b2dfd396391a8ca03a1d6eadeb40ae7fe3fc094eac21c61de98aee23540a5ed0f8d825b0f07c0776a6e87f736636fa0c14b20a6a7d22df424b3d9f269ed6e1c2
7
+ data.tar.gz: 257038679b3f1b47804388a382eec7235afc7b0da9478c1dc1f83b704229af035d92c4d3752a05001a873302a8399b15acb784c491436d7caa03e46ec15467ce
@@ -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', '< 5.1'
21
- gem.add_dependency 'activesupport', '>= 4.1', '< 5.1'
20
+ gem.add_dependency 'activerecord', '>= 4.1', '< 5.2'
21
+ gem.add_dependency 'activesupport', '>= 4.1', '< 5.2'
22
22
  gem.add_dependency 'activerecord-import', '~> 0.19.1'
23
- gem.add_dependency 'money-rails'
23
+ gem.add_dependency 'money-rails', '>=1.7.0'
24
24
  gem.add_dependency 'monetize'
25
25
 
26
26
  gem.add_development_dependency 'sqlite3'
@@ -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
@@ -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,5 +1,5 @@
1
1
  # Copyright 2015-2017, Instacart
2
2
 
3
3
  module Amountable
4
- VERSION = '0.2.8'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -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
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.3.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: 2018-03-28 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: '5.1'
22
+ version: '5.2'
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: '5.1'
32
+ version: '5.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activesupport
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '4.1'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '5.1'
42
+ version: '5.2'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: '4.1'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '5.1'
52
+ version: '5.2'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: activerecord-import
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -70,14 +70,14 @@ dependencies:
70
70
  requirements:
71
71
  - - ">="
72
72
  - !ruby/object:Gem::Version
73
- version: '0'
73
+ version: 1.7.0
74
74
  type: :runtime
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
- version: '0'
80
+ version: 1.7.0
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: monetize
83
83
  requirement: !ruby/object:Gem::Requirement
@@ -214,6 +214,7 @@ files:
214
214
  - lib/amountable/operations.rb
215
215
  - lib/amountable/table_methods.rb
216
216
  - lib/amountable/version.rb
217
+ - lib/amountable/virtual_amount.rb
217
218
  - spec/amountable/amount_spec.rb
218
219
  - spec/amountable/amountable_spec.rb
219
220
  - spec/amountable/nil_amount_spec.rb