Class: ArSerializer::GraphQL::TypeClass
- Inherits:
-
Object
- Object
- ArSerializer::GraphQL::TypeClass
- Includes:
- Serializable
- Defined in:
- lib/ar_serializer/graphql/types.rb
Direct Known Subclasses
HashTypeClass, ListTypeClass, OptionalTypeClass, OrTypeClass, ScalarTypeClass, SerializableTypeClass, TSTypeClass
Defined Under Namespace
Classes: InvalidType
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #association_type ⇒ Object
- #collect_types(types) ⇒ Object
- #description ⇒ Object
- #fields ⇒ Object
-
#initialize(type) ⇒ TypeClass
constructor
A new instance of TypeClass.
- #name ⇒ Object
- #of_type ⇒ Object
- #ts_type ⇒ Object
Constructor Details
#initialize(type) ⇒ TypeClass
Returns a new instance of TypeClass.
100 101 102 |
# File 'lib/ar_serializer/graphql/types.rb', line 100 def initialize(type) @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
99 100 101 |
# File 'lib/ar_serializer/graphql/types.rb', line 99 def type @type end |
Class Method Details
.from(type, only = nil, except = nil) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ar_serializer/graphql/types.rb', line 127 def self.from(type, only = nil, except = nil) type = [type[0...-1].to_sym, nil] if type.is_a?(Symbol) && type.to_s.end_with?('?') type = [type[0...-1], nil] if type.is_a?(String) && type.end_with?('?') # ?? case type when Class raise InvalidType, "#{type} must include ArSerializer::Serializable" unless type.ancestors.include? ArSerializer::Serializable SerializableTypeClass.new type, only, except when :number, :int, :float, :string, :boolean, :any, :unknown ScalarTypeClass.new type when String, Numeric, true, false, nil ScalarTypeClass.new type when Array if type.size == 1 ListTypeClass.new from(type.first, only, except) elsif type.size == 2 && type.last.nil? OptionalTypeClass.new from(type.first, only, except) else OrTypeClass.new type.map {|v| from(v, only, except) } end when Hash HashTypeClass.new type.transform_values {|v| from(v, only, except) } when ArSerializer::TSType TSTypeClass.new type.type else raise InvalidType, "Invalid type: #{type}" end end |
Instance Method Details
#association_type ⇒ Object
118 |
# File 'lib/ar_serializer/graphql/types.rb', line 118 def association_type; end |
#collect_types(types) ⇒ Object
106 |
# File 'lib/ar_serializer/graphql/types.rb', line 106 def collect_types(types); end |
#description ⇒ Object
108 |
# File 'lib/ar_serializer/graphql/types.rb', line 108 def description = ts_type |
#fields ⇒ Object
114 |
# File 'lib/ar_serializer/graphql/types.rb', line 114 def fields; end |
#name ⇒ Object
110 |
# File 'lib/ar_serializer/graphql/types.rb', line 110 def name; end |
#of_type ⇒ Object
112 |
# File 'lib/ar_serializer/graphql/types.rb', line 112 def of_type; end |
#ts_type ⇒ Object
116 |
# File 'lib/ar_serializer/graphql/types.rb', line 116 def ts_type; end |