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) ⇒ FileStructure



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

def initialize(definition)
  @definition = definition
  @name = definition.name
  @object = definition.object
end

Instance Method Details

#importsArray<Import>



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

def imports
  shared_imports + relationship_imports
end

#nameObject



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

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

#to_code(manually_editable: false) ⇒ Object



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

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