Class: Blufin::YmlVueServiceWriter
- Inherits:
-
YmlWriterBase
- Object
- YmlWriterBase
- Blufin::YmlVueServiceWriter
- Defined in:
- lib/core/yml_writers/yml_vue_service_writer.rb
Constant Summary collapse
- SERVICE =
Blufin::SiteServices::API
- PACKAGE =
'resources'
Constants inherited from YmlWriterBase
Blufin::YmlWriterBase::AUTO_TYPES, Blufin::YmlWriterBase::PLACEHOLDER_CLASS, Blufin::YmlWriterBase::PLACEHOLDER_IMPORT, Blufin::YmlWriterBase::PLACEHOLDER_PACKAGE, Blufin::YmlWriterBase::PLACEHOLDER_SCHEMA
Instance Method Summary collapse
-
#initialize(site, schema_resources) ⇒ Object
constructor
Initialize the class.
-
#write ⇒ Object
Void.
Methods inherited from YmlWriterBase
#get_base_path, #get_java_path, #get_package, #get_package_from_file, #write_file_java
Constructor Details
#initialize(site, schema_resources) ⇒ Object
Initialize the class.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/core/yml_writers/yml_vue_service_writer.rb', line 10 def initialize(site, schema_resources) @schema_resources = schema_resources raise RuntimeError, 'Could not find valid @schema_resources.' if @schema_resources.nil? || !@schema_resources.is_a?(Hash) @site = Blufin::SiteResolver::validate_site(site) @site_name = Blufin::SiteResolver::get_site_name(@site) @site_domain = Blufin::SiteResolver::get_site_domain(@site) @site_location = "#{Blufin::SiteResolver::get_site_location(@site)}/" # Wipe out all previous files. # Blufin::YmlSchemaValidator::VALID_SCHEMAS_GENERATE.each do |schema| # path_to_wipe_out = "#{get_java_path(@site, schema, SERVICE, PACKAGE)}" # if Blufin::Files::path_exists(path_to_wipe_out) # if Blufin::Files::get_files_in_dir(path_to_wipe_out).any? # Blufin::Terminal::command('rm *', path_to_wipe_out, false, false) # end # end # end end |
Instance Method Details
#write ⇒ Object
Returns void.
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/core/yml_writers/yml_vue_service_writer.rb', line 34 def write @schema_resources.each do |schema_table, resource_data| # Only write PARENT resources as they will contain the others as 'dependents'. next unless resource_data[:tree].length < 2 # Skip if this resource has no HTTP Methods. next unless Blufin::YmlCommon::has_at_least_one_http_method(resource_data, Blufin::YmlSchemaValidator::CONFIG_INTERNAL) @schema = schema_table.split('.')[0] @table = schema_table.split('.')[1] @type = resource_data[:type] @import_statements = [] table_name = Blufin::Strings::snake_case_to_camel_case(@table) table_name_lower = Blufin::Strings::snake_case_to_camel_case_lower(@table) class_name = "#{table_name}Resource" auth_level = Blufin::SiteAuth::get_auth_level_for_table(@schema, @table) # TODO - THIS CANNOT BE HARD-CODED TO FALSE/TRUE. is_public = false is_secured = true is_account_aware = (auth_level == Blufin::SiteAuth::LEVEL_ACCOUNT || auth_level == Blufin::SiteAuth::LEVEL_ACCOUNT_USER) is_user_aware = (auth_level == Blufin::SiteAuth::LEVEL_ACCOUNT_USER) # TODO - THIS CANNOT BE HARD-CODED TO FALSE. is_oauth = false # TODO - REMOVE (AFTER OAUTH IS FIXED -- HANDY DEBUG STRING) # puts "\x1B[38;5;154m#{@schema}.#{@table}\x1B[0m \xe2\x86\x92 \x1B[38;5;196m#{auth_level}\x1B[0m" content_inner = [] content_inner << "import Axios from 'axios';" content_inner << '' content_inner << 'export default {' if resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::GET) content_inner << " get#{table_name}() {" content_inner << " return Axios.get(`/#{@schema_resources["#{schema_table}"][:resource]}`).then((response) => {" content_inner << ' return response.data;' content_inner << ' }, (e) => {' content_inner << ' return Promise.reject(e.data);' content_inner << ' });' content_inner << ' },' content_inner << " get#{table_name}(id) {" content_inner << " return Axios.get(`/#{@schema_resources["#{schema_table}"][:resource]}/${id}`).then((response) => {" content_inner << ' return response.data;' content_inner << ' }, (e) => {' content_inner << ' return Promise.reject(e.data);' content_inner << ' });' content_inner << ' },' end if resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::POST) content_inner << " post#{table_name}(obj) {" content_inner << " return Axios.post(`/#{@schema_resources["#{schema_table}"][:resource]}`, obj).then((response) => {" content_inner << ' return response.data;' content_inner << ' }, (e) => {' content_inner << ' return Promise.reject(e.data);' content_inner << ' });' content_inner << ' },' end if resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::PATCH) content_inner << " patch#{table_name}(obj) {" content_inner << " return Axios.patch(`/#{@schema_resources["#{schema_table}"][:resource]}`, obj).then((response) => {" content_inner << ' return response.data;' content_inner << ' }, (e) => {' content_inner << ' return Promise.reject(e.data);' content_inner << ' });' content_inner << ' },' end if resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::DELETE) content_inner << " delete#{table_name}(id) {" content_inner << " return Axios.delete(`/#{@schema_resources["#{schema_table}"][:resource]}/${id}`).then((response) => {" content_inner << ' return response.data;' content_inner << ' }, (e) => {' content_inner << ' return Promise.reject(e.data);' content_inner << ' });' content_inner << ' },' end if !resource_data[:dependents].nil? && resource_data[:dependents].any? resource_data[:dependents].each do |dependent| dcc = Blufin::Strings::snake_case_to_camel_case(dependent) dccl = Blufin::Strings::snake_case_to_camel_case_lower(dependent) uri = @schema_resources["#{@schema}.#{dependent}"][:resource] resource_data = @schema_resources["#{@schema}.#{dependent}"] if resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::GET) # TODO end if resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::POST) # TODO end if resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::PATCH) # TODO end if resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::DELETE) # TODO end end end content = [] content = content.push(*content_inner) content[content.length - 1] = ' }' content << '}' # TODO - REMOVE # puts "\x1B[38;5;154m#{content.to_yaml}\x1B[0m" if schema_table == 'common.account' # TODO # full_file_path = "#{get_java_path(@site, @schema, SERVICE, PACKAGE)}/#{class_name}.java" # TODO # write_file_java(full_file_path, content).gsub(@site_location, '') end end |