class AppStructure

Public Class Methods

source_root() click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 8
def self.source_root
  File.dirname(__FILE__)
end

Public Instance Methods

root_directory() click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 12
def root_directory
  app_name = name.to_s
  empty_directory(app_name)
  path = app_name

  app_directory(path)
  db_directory(path)
  lib_directory(path)
  proto_directory(path)
  config_directory(path)
  test_directory(path)

  generate_gemfile(path)
  generate_rake_file(path)
  generate_server_file(path)

  run_protoc_cmd(path)
  run_bundle_install(path)
end

Private Instance Methods

app_directory(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 33
def app_directory(path)
  path += "/app"
  empty_directory(path)

  models_directory(path)
end
config_directory(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 126
def config_directory(path)
  path += "/config"
  empty_directory(path)

  generate_db_config_file(path)
  generate_application_config_file(path)
end
db_directory(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 53
def db_directory(path)
  path += "/db"
  empty_directory(path)

  migration_directory(path)
end
generate_application_config_file(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 141
def generate_application_config_file(path)
  path += "/"
  generate_template(
    path: path, extenstion: 'rb', template_name: 'application'
  )
end
generate_application_record(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 47
def generate_application_record(path)
  path += "/"
  template_name = "application_record"
  generate_template(path: path, template_name: template_name, extenstion: 'rb')
end
generate_db_config_file(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 134
def generate_db_config_file(path)
  path += "/"
  generate_template(
    path: path, extenstion: 'rb', template_name: 'db_config'
  )
end
generate_db_rake_file(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 88
def generate_db_rake_file(path)
  path += "/"
  generate_template(
    path: path, extenstion: 'rake', template_name: 'db'
  )
end
generate_gemfile(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 162
def generate_gemfile(path)
  path += "/"
  generate_template(
    path: path, template_name: 'Gemfile'
  )
end
generate_proto_file(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 119
def generate_proto_file(path)
  path += "/"
  generate_template(
    path: path, extenstion: 'proto', template_name: 'proto', file_name: name
  )
end
generate_protofub_rake_file(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 95
def generate_protofub_rake_file(path)
  path += "/"
  generate_template(
    path: path, extenstion: 'rake', template_name: 'generate_protobuf_files'
  )
end
generate_rake_file(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 169
def generate_rake_file(path)
  path += "/"
  generate_template(
    path: path, template_name: 'Rakefile'
  )
end
generate_server_file(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 176
def generate_server_file(path)
  path += "/"
  generate_template(
    path: path, template_name: 'server',
    file_name: name + "_server", extenstion: 'rb'
  )
end
generate_service_file(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 102
def generate_service_file(path)
  path += "/"
  file_name = "#{name.underscore}_service"

  generate_template(
    path: path, file_name: file_name,
    extenstion: 'rb', template_name: "service"
  )
end
generate_template(path:, template_name:, extenstion: '', file_name: nil) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 200
def generate_template(path:, template_name:, extenstion: '', file_name: nil)
  template(
    path.sub(name, templates_directory) + template_name + ".tt",
    path + ( file_name ? file_name : template_name ) + ( extenstion.present? ? '.' + extenstion : extenstion )
  )
end
generate_test_client_file(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 155
def generate_test_client_file(path)
  path += "/"
  generate_template(
    path: path, extenstion: 'rb', template_name: 'test_client'
  )
end
lib_directory(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 65
def lib_directory(path)
  path += "/lib"
  empty_directory(path)

  protos_directory(path)
  tasks_directory(path)

  generate_service_file(path)
end
migration_directory(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 60
def migration_directory(path)
  path += "/migrate"
  empty_directory(path)
end
models_directory(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 40
def models_directory(path)
  path += "/models"
  empty_directory(path)

  generate_application_record(path)
end
proto_directory(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 112
def proto_directory(path)
  path += "/proto"
  empty_directory(path)

  generate_proto_file(path)
end
protos_directory(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 75
def protos_directory(path)
  path += "/protos"
  empty_directory(path)
end
run_bundle_install(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 190
def run_bundle_install(path)
  inside(path) do
    run ("bundle install")
  end
end
run_protoc_cmd(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 184
def run_protoc_cmd(path)
  inside(path) do
    run ("grpc_tools_ruby_protoc -I proto --ruby_out=lib/protos --grpc_out=lib/protos proto/#{name.underscore}.proto")
  end
end
tasks_directory(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 80
def tasks_directory(path)
  path += "/tasks"
  empty_directory(path)

  generate_db_rake_file(path)
  generate_protofub_rake_file(path)
end
templates_directory() click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 196
def templates_directory
  "templates"
end
test_directory(path) click to toggle source
# File lib/runways/generators/app_structure_generator.rb, line 148
def test_directory(path)
  path += "/test"
  empty_directory(path)

  generate_test_client_file(path)
end