<commit_before>require 'spiderfw/controller/app_controller'

module Spider
    
    module App
        
        def self.included(mod)
            mod.module_eval do
                
                include Spider::DataTypes
                
                #@controller ||= :"Spider::AppController"
                class << self
                    attr_reader :path, :pub_path, :test_path, :setup_path, :widgets_path, :views_path
                    attr_reader :short_name, :route_url
                    attr_reader :short_prefix
                    attr_reader :command
                    
                    def init
                        @short_name ||= Inflector.underscore(self.name).gsub('/', '_')
                        @pub_path ||= @path+'/pub'
                        @test_path ||= @path+'/test'
                        @setup_path ||= @path+'/setup'
                        @widgets_path ||= @path+'/widgets'
                        @views_path ||= @path+'/views'
                        @route_url ||= Inflector.underscore(self.name)
                    end
                    
                    def request_url
                        Spider::ControllerMixins::HTTPMixin.reverse_proxy_mapping('/'+@route_url)
                    end
                    
                    def controller
                        #controllers = self.const_get(:Controllers)
                        if (!@controller || !const_defined?(@controller))
                            @controller = :AppController
                            return const_set(@controller, Spider::AppController.clone)
                            
                        end
                        return const_get(@controller)
                    end
                    
                    def models
                        mods = []
                        self.constants.each { |c| mods += get_models(const_get(c)) }
                        return mods
                    end
                    
                    def get_models(m)
                        models = []
                        if m.respond_to?(:subclass_of?) && m.subclass_of?(Spider::Model::BaseModel)
                             models << m
                             m.constants.each do |c|
                                 sub_mod = m.const_get(c)
                                 next if !sub_mod.subclass_of?(Spider::Model::BaseModel) || sub_mod.app != self
                                 models += get_models(sub_mod)
                             end
                         end
                         return models
                    end
                    
                    def controllers
                        self.constants.map{ |m| const_get(m) }.select{ |m| m.subclass_of? Spider::Controller }
                    end
                    
                    def register_tag(tag, obj)
                        @tags ||= {}
                        @tags[tag] = obj
                    end
                    
                    def get_tag(tag)
                        @tags[tag]
                    end
                    
                    def has_tag?(tag)
                        @tags[tag] ? true : false
                    end
                    
                    def route(path, dest=nil, options=nil)
                        self.controller.route(path, dest, options)
                    end
                    
                    def relative_path
                        if (@path.index(Spider.paths[:apps]) == 0)
                            return @path[Spider.paths[:apps].length+1..-1]
                        else
                            return @path[Spider.paths[:core_apps].length+1..-1]
                        end
                    end
                end
                
                # controllers = Spider::App::Controllers.clone
                # controllers.app = mod
                # Spider.logger.debug("Controllers.app")
                # Spider.logger.debug(controllers.to_s)
                # Spider.logger.debug(controllers.app)
                #     
                # mod.const_set(:Controllers, controllers) unless mod.const_defined?(:Controllers)<commit_msg>Added label, version<commit_after>require 'spiderfw/controller/app_controller'

module Spider
    
    module App
        
        def self.included(mod)
            mod.module_eval do
                
                include Spider::DataTypes
                
                #@controller ||= :"Spider::AppController"
                class << self
                    attr_reader :path, :pub_path, :test_path, :setup_path, :widgets_path, :views_path
                    attr_reader :short_name, :route_url, :label, :version
                    attr_reader :short_prefix
                    attr_reader :command
                    
                    def init
                        @short_name ||= Inflector.underscore(self.name).gsub('/', '_')
                        @pub_path ||= @path+'/pub'
                        @test_path ||= @path+'/test'
                        @setup_path ||= @path+'/setup'
                        @widgets_path ||= @path+'/widgets'
                        @views_path ||= @path+'/views'
                        @route_url ||= Inflector.underscore(self.name)
                        @label ||= @short_name.split('_').each{ |p| p[0] = p[0].chr.upcase }.join(' ')
                    end
                    
                    def request_url
                        Spider::ControllerMixins::HTTPMixin.reverse_proxy_mapping('/'+@route_url)
                    end
                    
                    def controller
                        #controllers = self.const_get(:Controllers)
                        if (!@controller || !const_defined?(@controller))
                            @controller = :AppController
                            return const_set(@controller, Spider::AppController.clone)
                            
                        end
                        return const_get(@controller)
                    end
                    
                    def models
                        mods = []
                        self.constants.each { |c| mods += get_models(const_get(c)) }
                        return mods
                    end
                    
                    def get_models(m)
                        models = []
                        if m.respond_to?(:subclass_of?) && m.subclass_of?(Spider::Model::BaseModel)
                             models << m
                             m.constants.each do |c|
                                 sub_mod = m.const_get(c)
                                 next if !sub_mod.subclass_of?(Spider::Model::BaseModel) || sub_mod.app != self
                                 models += get_models(sub_mod)
                             end
                         end
                         return models
                    end
                    
                    def controllers
                        self.constants.map{ |m| const_get(m) }.select{ |m| m.subclass_of? Spider::Controller }
                    end
                    
                    def register_tag(tag, obj)
                        @tags ||= {}
                        @tags[tag] = obj
                    end
                    
                    def get_tag(tag)
                        @tags[tag]
                    end
                    
                    def has_tag?(tag)
                        return false unless @tags
                        @tags[tag] ? true : false
                    end
                    
                    def route(path, dest=nil, options=nil)
                        self.controller.route(path, dest, options)
                    end
                    
                    def relative_path
                        if (@path.index(Spider.paths[:apps]) == 0)
                            return @path[Spider.paths[:apps].length+1..-1]
                        else
                            return @path[Spider.paths[:core_apps].length+1..-1]
                        end
                    end
                end
                
                # controllers = Spider::App::Controllers.clone
                # controllers.app = mod
                # Spider.logger.debug("Controllers.app")
                # Spider.logger.debug(controllers.to_s)
                # Spider.logger.debug(controllers.app)
                #     
                # mod.const_set(:Controllers, controllers) unless mod.const_defined?(:Controllers)
{'fraction_non_alphanumeric': 0.08545115411517837, 'fraction_numerical': 0.0013989274889251574, 'mean_word_length': 0.8493209743479198, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '614904', 'n_tokens_mistral': 2039, 'n_tokens_neox': 1875, 'n_words': 335}