class Atum::Generation::GeneratorService

Public Class Methods

new(module_name, schema_file, url, options) click to toggle source
# File lib/atum/generation/generator_service.rb, line 6
def initialize(module_name, schema_file, url, options)
  @module_name = module_name
  @schema = schema_from_file(schema_file)
  @url = url
  @options = options
end

Public Instance Methods

generate_files() click to toggle source
# File lib/atum/generation/generator_service.rb, line 13
def generate_files
  generate_namespace_folder
  generated_files.each do |gf|
    File.open("#{gf.path}.rb", 'w') do |f|
      f.write(gf.generator.generate)
    end
  end
end

Private Instance Methods

generate_namespace_folder() click to toggle source
# File lib/atum/generation/generator_service.rb, line 28
def generate_namespace_folder
  FileUtils.mkdir_p namespace_path
  FileUtils.mkdir_p File.join(namespace_path, 'resources')
end
generated_files() click to toggle source
# File lib/atum/generation/generator_service.rb, line 37
def generated_files
  files = []

  files << GeneratedFile.new(namespace_path,
                             Generators::ModuleGenerator.new(*generator_args))

  files << GeneratedFile.new(File.join(namespace_path, 'client'),
                             Generators::ClientGenerator.new(*generator_args))

  resources.each do |resource|
    files << GeneratedFile.new(
      File.join(namespace_path, 'resources', resource.name.underscore),
      Generators::ResourceGenerator.new(resource, *generator_args))
  end

  files
end
generator_args() click to toggle source
# File lib/atum/generation/generator_service.rb, line 66
def generator_args
  [@module_name, @schema, @url, @options]
end
namespace() click to toggle source
# File lib/atum/generation/generator_service.rb, line 55
def namespace
  @module_name.downcase.underscore
end
namespace_path() click to toggle source
# File lib/atum/generation/generator_service.rb, line 59
def namespace_path
  s = []
  s << @options[:path] if @options.key?(:path)
  s << namespace
  File.join(*s)
end
resources() click to toggle source
# File lib/atum/generation/generator_service.rb, line 33
def resources
  @schema.resource_schemas.map { |r| GeneratorResource.new(r) }
end
schema_from_file(file) click to toggle source
# File lib/atum/generation/generator_service.rb, line 24
def schema_from_file(file)
  Atum::Core::Schema::ApiSchema.new(JSON.parse(File.read(file)))
end