aws-lex-conversation 1.0.0 → 1.1.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
  SHA256:
3
- metadata.gz: 148e207d8dcce051f2fc01244390021ae5734037a3b856462cd76ccd9e4cde8a
4
- data.tar.gz: 7f019bdc51b68e037575a60784dbe76217aabccdf15e3394515d4a404dbdd85a
3
+ metadata.gz: 113a515e1c05389f5ab8d57fae23a54fc6cc212645d2bea1e091c5f750aabe08
4
+ data.tar.gz: b9233099ad5faae9ce4c530565be798703d5bfedccd981ab6835a8b6c01d5f82
5
5
  SHA512:
6
- metadata.gz: 856f7ab5e25ffc87f93f3ee6f2b834acdd47cbc28adf334a22af4b152b37de435f54d3715374f33acfdf4ceebca1e2945b3557b5f72c4c5873e4b8761af5758a
7
- data.tar.gz: e6dff0de003696ef87460e6dfdb54b94e470d4ff5b6470f43642dd259fa13b645b276d5d88413369dcacc7368004f4c93d92f38c1c50a5a18487c6cb2210e62d
6
+ metadata.gz: b712aef8787b4b0754b420027abddcee9ea51fe030c590c0caea229629099542d44979d1b8bf6b5a1e29a5bbf37c6ec10c33ac9493fbffbeeb6b84deb9daaaf3
7
+ data.tar.gz: 0cf7de36b758c798068ac23b4d1e73b07252b9ed39ed36bebdd648d0aa060088bfd5c77ea21fed00c8338ca9a434c540f0c5fd08f695011705672c24c7bfb926
@@ -19,7 +19,8 @@ module Aws
19
19
 
20
20
  module InstanceMethods
21
21
  def assign_attributes!(opts = {})
22
- self.class.attributes.each do |attribute|
22
+ attributes = self.class.attributes | self.class.virtual_attributes
23
+ attributes.each do |attribute|
23
24
  instance_variable_set("@#{attribute}", opts[attribute])
24
25
  end
25
26
  end
@@ -60,6 +61,17 @@ module Aws
60
61
  ->(v) { v.transform_keys(&:to_sym) }
61
62
  end
62
63
 
64
+ def computed_property(attribute, callable)
65
+ mapping[attribute] = attribute
66
+ attr_writer(attribute)
67
+
68
+ # dynamically memoize the result
69
+ define_method(attribute) do
70
+ instance_variable_get("@#{attribute}") ||
71
+ instance_variable_set("@#{attribute}", callable.call(self))
72
+ end
73
+ end
74
+
63
75
  def required(attribute, opts = {})
64
76
  property(attribute, opts.merge(allow_nil: false))
65
77
  end
@@ -76,7 +88,12 @@ module Aws
76
88
 
77
89
  attr_accessor(attribute)
78
90
 
79
- mapping[attribute] = from
91
+ if opts.fetch(:virtual) { false }
92
+ virtual_attributes << attribute
93
+ else
94
+ mapping[attribute] = from
95
+ end
96
+
80
97
  translate(attribute => params)
81
98
  end
82
99
 
@@ -84,6 +101,10 @@ module Aws
84
101
  @attributes ||= mapping.keys
85
102
  end
86
103
 
104
+ def virtual_attributes
105
+ @virtual_attributes ||= []
106
+ end
107
+
87
108
  def mapping
88
109
  @mapping ||= {}
89
110
  end
@@ -8,22 +8,23 @@ module Aws
8
8
  include Base
9
9
 
10
10
  required :name
11
- required :slots
11
+ required :raw_slots, from: :slots, virtual: true
12
12
  required :slot_details
13
13
  required :confirmation_status
14
14
 
15
- class << self
16
- def slots!
17
- ->(v) do
18
- v.each_with_object({}) do |(key, value), hash|
19
- hash[key.to_sym] = Slot.shrink_wrap(
20
- name: key,
21
- value: value
22
- )
23
- end
24
- end
15
+ computed_property :slots, ->(instance) do
16
+ instance.raw_slots.each_with_object({}) do |(key, value), hash|
17
+ hash[key.to_sym] = Slot.shrink_wrap(
18
+ name: key,
19
+ value: value,
20
+ # pass a reference to the parent down to the slot so that each slot
21
+ # instance can view a broader scope such as slot_details/resolutions
22
+ current_intent: instance
23
+ )
25
24
  end
25
+ end
26
26
 
27
+ class << self
27
28
  def slot_details!
28
29
  ->(v) do
29
30
  v.each_with_object({}) do |(key, value), hash|
@@ -34,7 +35,6 @@ module Aws
34
35
  end
35
36
 
36
37
  coerce(
37
- slots: slots!,
38
38
  slot_details: slot_details!,
39
39
  confirmation_status: ConfirmationStatus
40
40
  )
@@ -7,6 +7,7 @@ module Aws
7
7
  class Slot
8
8
  include Base
9
9
 
10
+ required :current_intent, from: :current_intent, virtual: true
10
11
  required :name
11
12
  required :value
12
13
 
@@ -17,6 +18,28 @@ module Aws
17
18
  def filled?
18
19
  value.to_s != ''
19
20
  end
21
+
22
+ def resolve!(index: 0)
23
+ self.value = resolved(index: index)
24
+ end
25
+
26
+ def resolved(index: 0)
27
+ details.resolutions.fetch(index) { SlotResolution.new(value: value) }.value
28
+ end
29
+
30
+ def original_value
31
+ details.original_value
32
+ end
33
+
34
+ def resolvable?
35
+ details.resolutions.any?
36
+ end
37
+
38
+ def details
39
+ @details ||= current_intent.slot_details.fetch(name.to_sym) do
40
+ SlotDetail.new(name: name, resolutions: [], original_value: value)
41
+ end
42
+ end
20
43
  end
21
44
  end
22
45
  end
@@ -3,7 +3,7 @@
3
3
  module Aws
4
4
  module Lex
5
5
  class Conversation
6
- VERSION = '1.0.0'
6
+ VERSION = '1.1.0'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-lex-conversation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Doyle
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: exe
14
14
  cert_chain: []
15
- date: 2020-06-26 00:00:00.000000000 Z
15
+ date: 2020-06-29 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: shrink_wrap