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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e68e4778b29b3cf78670d0096790d55914beb14f
4
- data.tar.gz: 3d0694e12d2e317356e7eae95483eb07fea11003
3
+ metadata.gz: 11bbbefd55c61e98dbbc825bd62914cf8c5db61e
4
+ data.tar.gz: 7e8964b2729124602136631ee8c7e7ae05880632
5
5
  SHA512:
6
- metadata.gz: 1a20557bd58a6a26268c159986e775220f8864a601e97186fe10f9ac4b9e89672d22d27dfb3c9525a1db96740bedf5834edb62c21afc1149e1120dc6edc05cbe
7
- data.tar.gz: e32f05204cfc04690f6d1e657438fbc6e516ae4f9db5511a70c6e4b2c09338d720485d7b4e339cb0090cdb53d87af782e8e9464d60fdc5cf7c47fb14b94315e0
6
+ metadata.gz: 9766a2ecc37debfe6186f6ee7b5101458261391ea9b7ca0ceba6c4648bb0c2d51cae70db6d30752cf3506ed9ac6ca99c3d491b0085dccb048a1df44fb4d02e53
7
+ data.tar.gz: a106a37ad16a882536acad010229dfaa01e2b6c764173b90ca35458f742294d29ff98650693f8872f73562ec824a088c5c361283ccb259823704d549ceff564e
@@ -9,13 +9,25 @@ module Prezzo
9
9
  module ClassMethods
10
10
  def composed_by(options)
11
11
  options.each do |name, klass|
12
- options[name] = klass
12
+ components << name
13
13
 
14
14
  define_method(name) do
15
- options[name].new(context).calculate
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
@@ -7,14 +7,20 @@ module Prezzo
7
7
  end
8
8
 
9
9
  module ClassMethods
10
- def explain_with(*methods)
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 = methods.each_with_object({}) do |method, acc|
17
- acc[method] = send(method)
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?
@@ -1,3 +1,3 @@
1
1
  module Prezzo
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.4.1".freeze
3
3
  end
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.0
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-06-23 00:00:00.000000000 Z
11
+ date: 2017-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hanami-validations