Class: Anchor::TypeScript::FileStructure

Inherits:
Object
  • Object
show all
Defined in:
lib/anchor/type_script/file_structure.rb

Defined Under Namespace

Classes: FileUtils, Import

Instance Method Summary collapse

Constructor Details

#initialize(definition, extension: ".ts") ⇒ FileStructure

Returns a new instance of FileStructure.



27
28
29
30
31
32
# File 'lib/anchor/type_script/file_structure.rb', line 27

def initialize(definition, extension: ".ts")
  @definition = definition
  @name = definition.name
  @object = definition.object
  @extension = extension
end

Instance Method Details

#importsArray<Import>

Returns:



55
56
57
# File 'lib/anchor/type_script/file_structure.rb', line 55

def imports
  shared_imports + relationship_imports
end

#nameObject



34
35
36
# File 'lib/anchor/type_script/file_structure.rb', line 34

def name
  "#{@definition.name}#{@extension}"
end

#to_code(manually_editable: false) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/anchor/type_script/file_structure.rb', line 38

def to_code(manually_editable: false)
  imports_string = FileUtils.imports_to_code(imports)
  name = manually_editable ? "Model" : @name
  typedef = FileUtils.def_to_code(name, @object)
  export_string = FileUtils.export_code(@definition.name)

  if manually_editable
    start_autogen = "// START AUTOGEN\n"
    end_autogen = "// END AUTOGEN\n"
    unedited_export_def = "type #{@name} = Model;\n"
    [start_autogen, imports_string, typedef, end_autogen, unedited_export_def, export_string].join("\n")
  else
    [imports_string, typedef, export_string].join("\n")
  end
end