Class: Swgr2rb::RubyFileGenerator

Inherits:
Object
  • Object
show all
Includes:
RubyFileGeneratorConstants
Defined in:
lib/endpoint_class_generator/ruby_file_generator.rb

Overview

RubyFileGenerator is meant to be used as an abstract class to be inherited from. It contains methods that create a Ruby file and write to it the return value of generate_lines method. The method is implemented in its child classes, EndpointClassGenerator and SchemaModuleGenerator.

Constant Summary

Constants included from RubyFileGeneratorConstants

Swgr2rb::RubyFileGeneratorConstants::CAMEL_CASE_TO_SNAKE_CASE, Swgr2rb::RubyFileGeneratorConstants::CLASS_NAME, Swgr2rb::RubyFileGeneratorConstants::COMMENT_ADD_SUB_RESULTS, Swgr2rb::RubyFileGeneratorConstants::COMMENT_SET_VALID_VALUES, Swgr2rb::RubyFileGeneratorConstants::END_POINT_PATH, Swgr2rb::RubyFileGeneratorConstants::EXPECTED_CODE, Swgr2rb::RubyFileGeneratorConstants::EXPECTED_SCHEMA, Swgr2rb::RubyFileGeneratorConstants::GENERATE_BODY, Swgr2rb::RubyFileGeneratorConstants::GENERATE_HEADERS, Swgr2rb::RubyFileGeneratorConstants::GET_PARAM_FROM_REQUEST_OPTIONS, Swgr2rb::RubyFileGeneratorConstants::GET_PARAM_FROM_REQUEST_PARAMS, Swgr2rb::RubyFileGeneratorConstants::INCLUDES, Swgr2rb::RubyFileGeneratorConstants::INITIALIZE, Swgr2rb::RubyFileGeneratorConstants::JSON_VALIDATOR_VALIDATE_SCHEMA, Swgr2rb::RubyFileGeneratorConstants::MODULE_NAME, Swgr2rb::RubyFileGeneratorConstants::MULTIPART_REQUEST_BODY, Swgr2rb::RubyFileGeneratorConstants::RAISE_UNLESS_PARAMS_PASSED, Swgr2rb::RubyFileGeneratorConstants::REQUIRES, Swgr2rb::RubyFileGeneratorConstants::SNAKE_CASE_TO_CAMEL_CASE, Swgr2rb::RubyFileGeneratorConstants::VALIDATE_RESPONSE_SCHEMA

Instance Method Summary collapse

Constructor Details

#initialize(class_config, opts) ⇒ RubyFileGenerator

opts can include:

name: class/module name
rewrite: if set to true, rewrite the existing file if it already exists
target_dir: directory where the class/module will be created
update_only: if set to true, do not create new file,
             only update existing


21
22
23
24
# File 'lib/endpoint_class_generator/ruby_file_generator.rb', line 21

def initialize(class_config, opts)
  @config = class_config
  @opts = opts
end

Instance Method Details

#generate_fileObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/endpoint_class_generator/ruby_file_generator.rb', line 26

def generate_file
  if (File.exist?(filename) && !@opts[:rewrite]) ||
     (!File.exist?(filename) && @opts[:update_only])
    return
  end

  File.open(filename, 'w') do |file|
    file.write(generate_lines.join("\n"))
  end
end