Class: CapicuaGen::Gaspar::CodeMaidCleanerFeature

Inherits:
Feature
  • Object
show all
Includes:
CapicuaGen, CapicuaGen::Gaspar
Defined in:
lib/CapicuaGenGaspar/CodeTransformer/CodeMaidCleaner/Source/code_maid_cleaner_feature.rb

Overview

Caracteristica generadora para limpiar y formatear el codigo generado a traves de la herramienta CodeMaid (Extesion de Visual Studio)

Constant Summary collapse

BINARY =
"RunCodeMaidCleaner.exe"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CapicuaGen::Gaspar

#get_about_class_full_name, #get_about_class_name, #get_app_config_file, #get_db_connection_name_method, #get_db_connection_provider_method, #get_db_connection_string_method, #get_entity_by_catalog_name, #get_entity_catalogs_full_name, #get_entity_catalogs_name, #get_entity_data_access_full_name, #get_entity_data_access_name, #get_entity_full_name, #get_entity_interface_full_name, #get_entity_interface_name, #get_entity_name, #get_main_form_class_full_name, #get_main_form_class_name, #get_namespaces, #get_namespaces_text, #get_splash_class_full_name, #get_splash_class_name

Constructor Details

#initialize(values = {}) ⇒ CodeMaidCleanerFeature

Inicializa la caracteristica



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/CapicuaGenGaspar/CodeTransformer/CodeMaidCleaner/Source/code_maid_cleaner_feature.rb', line 54

def initialize(values= {})
  super(values)


  # Configuro los tipos si estos no han sido configurados previamente

  self.types           = [:transformer] if self.types.blank?

  @target_feature_types= [:soluction] if @target_feature_types.blank?


  @bin_directories     = [] if self.bin_directories.blank?
  @bin_directories << File.join(File.dirname(__FILE__), '../bin')


end

Instance Attribute Details

#bin_directoriesObject

Returns the value of attribute bin_directories.



47
48
49
# File 'lib/CapicuaGenGaspar/CodeTransformer/CodeMaidCleaner/Source/code_maid_cleaner_feature.rb', line 47

def bin_directories
  @bin_directories
end

#target_feature_typesObject

Returns the value of attribute target_feature_types.



47
48
49
# File 'lib/CapicuaGenGaspar/CodeTransformer/CodeMaidCleaner/Source/code_maid_cleaner_feature.rb', line 47

def target_feature_types
  @target_feature_types
end

Instance Method Details

#find_binaryObject



151
152
153
154
155
156
157
# File 'lib/CapicuaGenGaspar/CodeTransformer/CodeMaidCleaner/Source/code_maid_cleaner_feature.rb', line 151

def find_binary
  bin_directories.each do |bin|
    current_path= File.join(bin, BINARY)
    return current_path if File.exist?(current_path)
  end

end

#generateObject

Genera las cabeceras y pie de paginas



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
# File 'lib/CapicuaGenGaspar/CodeTransformer/CodeMaidCleaner/Source/code_maid_cleaner_feature.rb', line 72

def generate
  super()


  message_helper.add_indent

  begin

    directory_base= self.generation_attributes[:out_dir]
    binary_file   = find_binary
    parameters    = ' /mo'
    files         = []


    # Recorro todas las caracteristicas

    generator.features.each do |feature|

      return unless feature.respond_to?('get_relative_out_files')

      #Obtengo todos los archivos asociados

      feature.get_relative_out_files(:directory_base => directory_base).each do |unix_path|

        file= unix_path.gsub(/\//, '\\')
        Dir.chdir directory_base do
          file= File.absolute_path(file)
        end
        extension= File.extname(file).downcase

        case extension
          when '.sln'
            parameters<<" /s \"#{file}\""
          when '.csproj'
            parameters<<" /p \"#{file}\"" if @target_feature_types.include?(:proyect)
          else

            Dir.chdir directory_base do
              #Compruebo si debe ser includo

              stat=File::Stat.new(unix_path)
              if (stat.mtime > self.generator.start_time)
                file= File.basename(unix_path)
                files<<file
              end
            end
        end

      end
    end

    Dir.chdir directory_base do
      #Guardo el archivo de directorio

      file= Tempfile.new('files')

      begin
        file.write(files.join($/))
        file.close
        file_path= file.path.gsub /\//, '\\'

        parameters<<" /f #{file_path}"

        #Ejecuto el programa

        IO.popen("\"#{binary_file}\" #{parameters}").each do |line|
          message_helper.puts_code_clean(line.chomp)
        end


      ensure
        file.close
        file.unlink # deletes the temp file

      end


    end
  ensure
    message_helper.remove_indent
    puts
  end

end