prezzo 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/prezzo/composable.rb +14 -2
- data/lib/prezzo/explainable.rb +9 -3
- data/lib/prezzo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11bbbefd55c61e98dbbc825bd62914cf8c5db61e
|
4
|
+
data.tar.gz: 7e8964b2729124602136631ee8c7e7ae05880632
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9766a2ecc37debfe6186f6ee7b5101458261391ea9b7ca0ceba6c4648bb0c2d51cae70db6d30752cf3506ed9ac6ca99c3d491b0085dccb048a1df44fb4d02e53
|
7
|
+
data.tar.gz: a106a37ad16a882536acad010229dfaa01e2b6c764173b90ca35458f742294d29ff98650693f8872f73562ec824a088c5c361283ccb259823704d549ceff564e
|
data/lib/prezzo/composable.rb
CHANGED
@@ -9,13 +9,25 @@ module Prezzo
|
|
9
9
|
module ClassMethods
|
10
10
|
def composed_by(options)
|
11
11
|
options.each do |name, klass|
|
12
|
-
|
12
|
+
components << name
|
13
13
|
|
14
14
|
define_method(name) do
|
15
|
-
|
15
|
+
cached_components[name] ||= klass.new(context)
|
16
|
+
|
17
|
+
cached_components[name].calculate
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
21
|
+
|
22
|
+
def components
|
23
|
+
@components ||= []
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def cached_components
|
30
|
+
@cached_components ||= {}
|
19
31
|
end
|
20
32
|
end
|
21
33
|
end
|
data/lib/prezzo/explainable.rb
CHANGED
@@ -7,14 +7,20 @@ module Prezzo
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module ClassMethods
|
10
|
-
def explain_with(*
|
10
|
+
def explain_with(*component_names)
|
11
11
|
define_method(:explain) do
|
12
12
|
explanation = {
|
13
13
|
total: calculate,
|
14
14
|
}
|
15
15
|
|
16
|
-
components =
|
17
|
-
|
16
|
+
components = component_names.each_with_object({}) do |component, acc|
|
17
|
+
value = send(component)
|
18
|
+
if self.class.respond_to?(:components) && self.class.components.include?(component)
|
19
|
+
value = cached_components[component]
|
20
|
+
end
|
21
|
+
value = value.explain if value.respond_to?(:explain)
|
22
|
+
value = value.calculate if value.respond_to?(:calculate)
|
23
|
+
acc[component] = value
|
18
24
|
end
|
19
25
|
|
20
26
|
explanation[:components] = components unless components.empty?
|
data/lib/prezzo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prezzo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Boeira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hanami-validations
|