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 +4 -4
- data/amountable.gemspec +3 -3
- data/lib/amountable.rb +1 -0
- data/lib/amountable/jsonb_methods.rb +1 -1
- data/lib/amountable/version.rb +1 -1
- data/lib/amountable/virtual_amount.rb +35 -0
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 150e7fb0a09dce9fd26118253413dda2602a5a87
|
4
|
+
data.tar.gz: 6472352d7d6211f86a6caf508bd80b73c1480e98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2dfd396391a8ca03a1d6eadeb40ae7fe3fc094eac21c61de98aee23540a5ed0f8d825b0f07c0776a6e87f736636fa0c14b20a6a7d22df424b3d9f269ed6e1c2
|
7
|
+
data.tar.gz: 257038679b3f1b47804388a382eec7235afc7b0da9478c1dc1f83b704229af035d92c4d3752a05001a873302a8399b15acb784c491436d7caa03e46ec15467ce
|
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', '< 5.
|
21
|
-
gem.add_dependency 'activesupport', '>= 4.1', '< 5.
|
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'
|
data/lib/amountable.rb
CHANGED
@@ -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
|
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.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-
|
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.
|
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.
|
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.
|
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.
|
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:
|
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:
|
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
|