Class: Anchor::TypeScript::Resource
- Inherits:
-
Object
- Object
- Anchor::TypeScript::Resource
- Defined in:
- lib/anchor/type_script/resource.rb
Defined Under Namespace
Classes: Definition
Instance Method Summary collapse
- #definition ⇒ Object
- #express ⇒ Object
-
#initialize(klass) ⇒ Resource
constructor
A new instance of Resource.
- #object(context: {}, include_all_fields:) ⇒ Object
Constructor Details
#initialize(klass) ⇒ Resource
Returns a new instance of Resource.
7 8 9 |
# File 'lib/anchor/type_script/resource.rb', line 7 def initialize(klass) @klass = klass end |
Instance Method Details
#definition ⇒ Object
17 18 19 20 |
# File 'lib/anchor/type_script/resource.rb', line 17 def definition(...) @object = object(...) Definition.new(name: anchor_schema_name, object: @object) end |
#express ⇒ Object
11 12 13 14 15 |
# File 'lib/anchor/type_script/resource.rb', line 11 def express(...) @object = object(...) expression = Anchor::TypeScript::Serializer.type_string(@object) "export type #{anchor_schema_name} = " + expression + ";" end |
#object(context: {}, include_all_fields:) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/anchor/type_script/resource.rb', line 22 def object(context: {}, include_all_fields:) t = Anchor::Inference::JSONAPI::ReadType.infer(@klass, context:, include_all_fields:) return t if t["relationships"].type.properties.count > 0 return t.omit(["relationships"]) unless Anchor.config.empty_relationship_type t.overwrite(Anchor::Types::Object.new([empty_relationships_property])) end |