Class: EWorld::ControllerScanner
- Inherits:
-
Object
- Object
- EWorld::ControllerScanner
- Defined in:
- lib/scanners/controller_scanner.rb
Constant Summary collapse
- SCHEMA_FILE =
"#{App::Opt::get_base_path}#{App::Opt::OPT_PATH}/schema/controllers.yml"
Class Method Summary collapse
-
.scan(api_project) ⇒ Object
Responsible for scanning the .codegen/controllers/.yml file(s).
Class Method Details
.scan(api_project) ⇒ Object
Responsible for scanning the .codegen/controllers/.yml file(s).
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/scanners/controller_scanner.rb', line 9 def self.scan(api_project) # TODO - Need to inject permissions. # TODO - Need to inject entities. raise RuntimeError, "Expected project type to be: #{Blufin::Projects::TYPE_API_SIMPLE}, instead got: #{api_project[Blufin::Projects::TYPE]}" unless api_project[Blufin::Projects::TYPE] == Blufin::Projects::TYPE_API_SIMPLE @errors = [] @controllers = {} @classes_seen = [] @paths_seen = [] begin @project_path = Blufin::Projects::get_project_path(api_project[Blufin::Projects::PROJECT_ID]) @project_path_api = Blufin::Projects::get_project_path(api_project[Blufin::Projects::PROJECT_ID], true) @project_transient_api = api_project[Blufin::Projects::TRANSIENT_DATA] @controller_path = "#{EWorld::BaseWriter::get_java_path_for(@project_path, @project_transient_api['ControllerPath'])}/#{EWorld::ControllerWriter::PACKAGE_NAME}" @service_path = "#{EWorld::BaseWriter::get_java_path_for(@project_path, @project_transient_api['ServicePath'])}/#{EWorld::ServiceWriter::PACKAGE_NAME}" controller_yml_path = "#{@project_path}/.#{Blufin::Projects::CODEGEN}/controllers" # If path not found, bomb-out immediately. unless Blufin::Files::path_exists(controller_yml_path) @errors << Blufin::ScannerError::add_error(nil, "YML Controller path not found: #{controller_yml_path}") return @errors, {} end # If the parent path where controllers/services should live doesn't exists -- bomb-out! [@controller_path, @service_path].each do |path| unless Blufin::Files::path_exists(path) @errors << Blufin::ScannerError::add_error(nil, "Path not found: #{path}") return {}, @errors end end # Loop all the YML files. Each file = 1 controller. Blufin::Files::get_files_in_dir(controller_yml_path).each do |controller_file| @file = controller_file # Get extension + controller root path. fs = @file.split('.') @root_path = fs[fs.length - 2].split('/') @root_path = @root_path[@root_path.length - 1] @class_name = "#{Blufin::Strings::snake_case_to_camel_case(@root_path.gsub('-', '_'))}" ext = fs[fs.length - 1] # Make sure we don't have duplicate class names. @errors << Blufin::ScannerError::add_error(@file, "Duplicate class: #{@class_name}") if @classes_seen.include?(@class_name.upcase) @classes_seen << @class_name.upcase # Make sure we have validly named YML file(s). @errors << Blufin::ScannerError::add_error(@file, "Expected extension to be lowercase 'yml', instead got: #{ext}") if ext.downcase != 'yml' unless ext.downcase == 'yml' @errors << Blufin::ScannerError::add_error(@file, "Expected extension to be 'yml', instead got: #{ext}") next end controller_yml = Blufin::Yml::read_file(@file, SCHEMA_FILE) # Validate file. If errors, go to next file. next unless validate_file(controller_yml) controller_yml['RootPath'] = Blufin::Strings::remove_surrounding_slashes(@root_path) @controllers[@class_name] = controller_yml end rescue => e Blufin::Terminal::print_exception(e) end return @controllers, @errors end |