Class: Foobara::RemoteGenerator::GenerateTypescript

Inherits:
Generators::Generate show all
Defined in:
foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/generate_typescript.rb

Defined Under Namespace

Classes: MissingManifestError

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary collapse

Attributes inherited from Generators::Generate

#element_to_generate

Attributes included from CommandPatternImplementation::Concerns::Subcommands

#is_subcommand

Attributes included from CommandPatternImplementation::Concerns::Runtime

#exception, #outcome

Attributes included from CommandPatternImplementation::Concerns::Errors

#error_collection

Attributes included from CommandPatternImplementation::Concerns::Inputs

#inputs, #raw_inputs

Instance Method Summary collapse

Methods inherited from Generators::Generate

#each_element_to_generate, #elements_to_generate, #generate_element, #generated, #generated_elements, #include_non_templated_files, #paths_to_source_code

Methods inherited from Command

install!, reset_all

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods included from CommandPatternImplementation::Concerns::Reflection

#initialize

Methods included from CommandPatternImplementation::Concerns::DomainMappers

#domain_map, #domain_map!, #run_mapped_subcommand!

Methods included from CommandPatternImplementation::Concerns::Subcommands

#run_subcommand!, #subcommand?

Methods included from CommandPatternImplementation::Concerns::Entities

#load_entities, #load_records

Methods included from CommandPatternImplementation::Concerns::Transactions

#auto_detect_current_transactions, #commit_transaction, #open_transaction, #opened_transactions, #relevant_entity_classes, #rollback_transaction, #transactions

Methods included from CommandPatternImplementation::Concerns::StateMachine

#state_machine

Methods included from CommandPatternImplementation::Concerns::Runtime

#halt!, #run, #run!, #run_execute, #succeed, #success?, #validate_records

Methods included from CommandPatternImplementation::Concerns::Errors

#initialize

Methods included from CommandPatternImplementation::Concerns::Inputs

#cast_and_validate_inputs, #initialize, #method_missing, #respond_to_missing?, #respond_to_missing_for_inputs?

Methods included from TruncatedInspect

#inspect, truncating

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Foobara::CommandPatternImplementation::Concerns::Inputs

Instance Attribute Details

#command_manifestObject

Returns the value of attribute command_manifest.



38
39
40
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/generate_typescript.rb', line 38

def command_manifest
  @command_manifest
end

#manifest_dataObject

Returns the value of attribute manifest_data.



38
39
40
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/generate_typescript.rb', line 38

def manifest_data
  @manifest_data
end

Instance Method Details

#add_all_commands_to_set_of_elements_to_generateObject



69
70
71
72
73
74
75
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/generate_typescript.rb', line 69

def add_all_commands_to_set_of_elements_to_generate
  manifest.commands.each do |command|
    elements_to_generate << command
    elements_to_generate << command.domain
    elements_to_generate << command.organization
  end
end

#add_root_manifest_to_set_of_elements_to_generateObject



77
78
79
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/generate_typescript.rb', line 77

def add_root_manifest_to_set_of_elements_to_generate
  elements_to_generate << manifest
end

#base_generatorObject



40
41
42
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/generate_typescript.rb', line 40

def base_generator
  Services::TypescriptFromManifestBaseGenerator
end

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/generate_typescript.rb', line 14

def execute
  load_manifest_if_needed

  include_non_templated_files

  add_root_manifest_to_set_of_elements_to_generate
  # TODO: allow specifying subset of commands
  add_all_commands_to_set_of_elements_to_generate

  each_element_to_generate do
    generate_element
  end

  paths_to_source_code
end

#load_manifest_if_neededObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/generate_typescript.rb', line 48

def load_manifest_if_needed
  self.manifest_data = if raw_manifest
                         raw_manifest
                         # TODO: introduce VCR to test the following elsif block
                         # :nocov:
                       elsif manifest_url
                         url = URI.parse(manifest_url)
                         response = Net::HTTP.get_response(url)

                         manifest_json = if response.is_a?(Net::HTTPSuccess)
                                           response.body
                                         else
                                           raise "Could not get manifest from #{url}: " \
                                                 "#{response.code} #{response.message}"
                                         end

                         JSON.parse(manifest_json)
                         # :nocov:
                       end
end

#manifestObject



81
82
83
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/generate_typescript.rb', line 81

def manifest
  @manifest ||= Manifest::RootManifest.new(manifest_data)
end

#templates_dirObject



44
45
46
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/generate_typescript.rb', line 44

def templates_dir
  "#{__dir__}/../../templates"
end

#validateObject



30
31
32
33
34
35
36
# File 'foobara-typescript-remote-command-generator-0.0.18/src/remote_generator/generate_typescript.rb', line 30

def validate
  if raw_manifest.nil? && manifest_url.nil?
    # :nocov:
    add_runtime_error(MissingManifestError.new(message: "Either raw_manifest or manifest_url must be given"))
    # :nocov:
  end
end