Class: ServiceContract::Avro::Type
- Inherits:
-
ServiceContract::AbstractType
- Object
- Struct
- ServiceContract::AbstractType
- ServiceContract::Avro::Type
- Defined in:
- lib/service_contract/avro/type.rb
Instance Attribute Summary
Attributes inherited from ServiceContract::AbstractType
Class Method Summary collapse
Instance Method Summary collapse
- #array? ⇒ Boolean
- #complex? ⇒ Boolean
- #fields ⇒ Object
- #name ⇒ Object
- #subtype ⇒ Object
- #to_s ⇒ Object
- #union? ⇒ Boolean
- #valid_ruby_types ⇒ Object
Class Method Details
.build(definition) ⇒ Object
33 34 35 |
# File 'lib/service_contract/avro/type.rb', line 33 def self.build(definition) Type.new(definition) end |
Instance Method Details
#array? ⇒ Boolean
29 30 31 |
# File 'lib/service_contract/avro/type.rb', line 29 def array? type_string == "array" end |
#complex? ⇒ Boolean
37 38 39 |
# File 'lib/service_contract/avro/type.rb', line 37 def complex? type_string == "record" end |
#fields ⇒ Object
12 13 14 15 16 |
# File 'lib/service_contract/avro/type.rb', line 12 def fields definition.fields.map do |field| Parameter.new(field) end end |
#name ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/service_contract/avro/type.rb', line 4 def name array? ? "Array(#{subtype.name})" : complex? ? definition.name : definition.type.to_s end |
#subtype ⇒ Object
24 25 26 27 |
# File 'lib/service_contract/avro/type.rb', line 24 def subtype return nil unless definition.respond_to?(:items) Type.build(definition.items) end |
#to_s ⇒ Object
18 19 20 21 22 |
# File 'lib/service_contract/avro/type.rb', line 18 def to_s return name unless union? union_types.map(&:name).join(", ") end |
#union? ⇒ Boolean
41 42 43 |
# File 'lib/service_contract/avro/type.rb', line 41 def union? type_string == "union" end |
#valid_ruby_types ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/service_contract/avro/type.rb', line 45 def valid_ruby_types case type_string when "array" [Array] when "int" [Fixnum] when "string" [String] when "float" [Float] when "boolean" [TrueClass, FalseClass] when "null" [NilClass] when "union" union_types.map(&:valid_ruby_types).flatten else # a complex type [Hash] end end |