Module: Aws::Lex::Conversation::Type::Base::ClassMethods
- Defined in:
- lib/aws/lex/conversation/type/base.rb
Instance Method Summary collapse
- #attributes ⇒ Object
- #computed_property(attribute, opts = {}, &block) ⇒ Object
- #float!(nilable: false) ⇒ Object
- #integer!(nilable: false) ⇒ Object
- #mapping ⇒ Object
- #optional(attribute, opts = {}) ⇒ Object
- #property(attribute, opts = {}) ⇒ Object
- #required(attribute, opts = {}) ⇒ Object
- #symbolize_hash! ⇒ Object
- #virtual_attributes ⇒ Object
Instance Method Details
#attributes ⇒ Object
115 116 117 |
# File 'lib/aws/lex/conversation/type/base.rb', line 115 def attributes @attributes ||= mapping.keys end |
#computed_property(attribute, opts = {}, &block) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/aws/lex/conversation/type/base.rb', line 74 def computed_property(attribute, opts = {}, &block) attr_writer(attribute) if opts.fetch(:virtual) { false } virtual_attributes << attribute else mapping[attribute] = attribute end # dynamically memoize the result define_method(attribute) do instance_variable_get("@#{attribute}") || instance_variable_set("@#{attribute}", block.call(self)) end end |
#float!(nilable: false) ⇒ Object
66 67 68 |
# File 'lib/aws/lex/conversation/type/base.rb', line 66 def float!(nilable: false) nilable ? ->(v) { v&.to_f } : ->(v) { v.to_f } end |
#integer!(nilable: false) ⇒ Object
62 63 64 |
# File 'lib/aws/lex/conversation/type/base.rb', line 62 def integer!(nilable: false) nilable ? ->(v) { v&.to_i } : ->(v) { v.to_i } end |
#mapping ⇒ Object
123 124 125 |
# File 'lib/aws/lex/conversation/type/base.rb', line 123 def mapping @mapping ||= {} end |
#optional(attribute, opts = {}) ⇒ Object
94 95 96 |
# File 'lib/aws/lex/conversation/type/base.rb', line 94 def optional(attribute, opts = {}) property(attribute, opts.merge(allow_nil: true)) end |
#property(attribute, opts = {}) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/aws/lex/conversation/type/base.rb', line 98 def property(attribute, opts = {}) from = opts.fetch(:from) do Support::Inflector.new(attribute).to_camel_case.to_sym end params = { from: from }.merge(opts) attr_accessor(attribute) if opts.fetch(:virtual) { false } virtual_attributes << attribute else mapping[attribute] = from end translate(attribute => params) end |
#required(attribute, opts = {}) ⇒ Object
90 91 92 |
# File 'lib/aws/lex/conversation/type/base.rb', line 90 def required(attribute, opts = {}) property(attribute, opts.merge(allow_nil: false)) end |
#symbolize_hash! ⇒ Object
70 71 72 |
# File 'lib/aws/lex/conversation/type/base.rb', line 70 def symbolize_hash! ->(v) { v.transform_keys(&:to_sym) } end |
#virtual_attributes ⇒ Object
119 120 121 |
# File 'lib/aws/lex/conversation/type/base.rb', line 119 def virtual_attributes @virtual_attributes ||= [] end |