<commit_before># The classes in this module are used internally by RFM and are not intended for outside
# use.
#
# Author::    <NAME>  (mailto:<EMAIL>)
# Copyright:: Copyright (c) 2007 Six Fried Rice, LLC and Mufaddal Khumri
# License::   See MIT-LICENSE for details


module Rfm

  module Factory 
  	extend Config
  	config :parent=>'Rfm::Config'
  
  	class ServerFactory < Rfm::CaseInsensitiveHash
      
      def [](*args)
      	options = Factory.get_config(*args)
      	host = options[:strings].delete_at(0) || options[:host]
        super(host) or (self[host] = Rfm::Server.new(host, options.rfm_filter(:account_name, :password, :delete=>true)))
      end
			
			# Potential refactor
			# 		def [](*conf)
			# 			options = Factory.get_config(*conf)
			#   		server_name = options[:strings][0] || options[:host]
			#   		options[:host] = server_name
			# 			#server = servers[server_name, options]
			# 			super(server_name) or (self[server_name] = Rfm::Server.new(options.reject{|k,v| [:account_name, :password].include? k}))
			# 		end
    
    end # ServerFactory
    
    
    class DbFactory < Rfm::CaseInsensitiveHash # :nodoc: all
    
      def initialize(server)
        @server = server
        @loaded = false
      end
      
      def [](*args)
      	# was: (dbname, acnt=nil, pass=nil)
      	options = Factory.get_config(*args)
      	name = options[:strings].delete_at(0) || options[:database]
      	account_name = options[:strings].delete_at(0) || options[:account_name]
      	password = options[:strings].delete_at(0) || options[:password]
        super(name) or (self[name] = Rfm::Database.new(name, account_name, password, @server, options))
      end
      
      def all
        if !@loaded
        	xml = @server.connect(@server.state[:account_name], @server.state[:password], '-dbnames', {}).body
          Rfm::Resultset.new(xml, :server_object => @server).each {|record|
            name = record['DATABASE_NAME']
            self[name] = Rfm::Database.new(name, @server) if self.keys.find{|k| k.to_s.downcase == name.to_s.downcase} == nil
          }
          @loaded = true
        end
        self
      end
      
      def names
      	keys
      end
    
    end # DbFactory
    
    
    
    class LayoutFactory < Rfm::CaseInsensitiveHash # :nodoc: all
    
      def initialize(server, database)
        @server = server
        @database = database
        @loaded = false
      end
      
      def [](*args) # was layout_name
      	options = Factory.get_config(*args)
      	name = options[:strings].delete_at(0) || options[:layout]
        super(name) or (self[name] = Rfm::Layout.new(name, @database, options))
      end
      
      def all
        if !@loaded
	        get_layout_names.each {|record|
	          name = record['LAYOUT_NAME']
	        	begin
	          	(self[name] = Rfm::Layout.new(name, @database)) unless !self[name].nil? or name.to_s.strip == ''
	          rescue
	          	$stderr.puts $!
	          end
	        }
          @loaded = true
        end
        self
      end
      
      def get_layout_names_xml
      	@server.connect(@database.account_name, @database.password, '-layoutnames', {"-db" => @database.name})
      end
      
      def get_layout_names
      	#Rfm::Resultset.new(@server, get_layout_names_xml.body, nil)
      	Rfm::Resultset.new(get_layout_names_xml.body, :database_object => @database)
      end
    
    	def names
    		keys
    	end<commit_msg>Refined factory methods to handle reconfiguring objects when passed new parameters in [] methods.<commit_after># The classes in this module are used internally by RFM and are not intended for outside
# use.
#
# Author::    <NAME>  (mailto:<EMAIL>)
# Copyright:: Copyright (c) 2007 Six Fried Rice, LLC and <NAME>
# License::   See MIT-LICENSE for details


module Rfm

  module Factory 
  	extend Config
  	config :parent=>'Rfm::Config'
  
  	class ServerFactory < Rfm::CaseInsensitiveHash
      
      def [](*args)
      	options = Factory.get_config(*args)
      	host = options[:strings].delete_at(0) || options[:host]
        super(host) or (self[host] = Rfm::Server.new(host, options.rfm_filter(:account_name, :password, :delete=>true)))
        # This part reconfigures the named server, if you pass it new config in the [] method.
        super(host).config(options) if (options)
        super(host)
      end
			
			# Potential refactor
			# 		def [](*conf)
			# 			options = Factory.get_config(*conf)
			#   		server_name = options[:strings][0] || options[:host]
			#   		options[:host] = server_name
			# 			#server = servers[server_name, options]
			# 			super(server_name) or (self[server_name] = Rfm::Server.new(options.reject{|k,v| [:account_name, :password].include? k}))
			# 		end
    
    end # ServerFactory
    
    
    class DbFactory < Rfm::CaseInsensitiveHash # :nodoc: all
    
      def initialize(server)
        @server = server
        @loaded = false
      end
      
      def [](*args)
      	# was: (dbname, acnt=nil, pass=nil)
      	options = Factory.get_config(*args)
      	name = options[:strings].delete_at(0) || options[:database]
      	account_name = options[:strings].delete_at(0) || options[:account_name]
      	password = options[:strings].delete_at(0) || options[:password]
        super(name) or (self[name] = Rfm::Database.new(name, account_name, password, @server))
        # This part reconfigures the named database, if you pass it new config in the [] method.
        super(name).config({:account_name=>account_name, :password=>password}.merge(options)) if (account_name or password or options)
        super(name)
      end
      
      def all
        if !@loaded
        	xml = @server.connect(@server.state[:account_name], @server.state[:password], '-dbnames', {}).body
          Rfm::Resultset.new(xml, :server_object => @server).each {|record|
            name = record['DATABASE_NAME']
            self[name] = Rfm::Database.new(name, @server) if self.keys.find{|k| k.to_s.downcase == name.to_s.downcase} == nil
          }
          @loaded = true
        end
        self
      end
      
      def names
      	keys
      end
    
    end # DbFactory
    
    
    
    class LayoutFactory < Rfm::CaseInsensitiveHash # :nodoc: all
    
      def initialize(server, database)
        @server = server
        @database = database
        @loaded = false
      end
      
      def [](*args) # was layout_name
      	options = Factory.get_config(*args)
      	name = options[:strings].delete_at(0) || options[:layout]
        super(name) or (self[name] = Rfm::Layout.new(name, @database, options))
        # This part reconfigures the named layout, if you pass it new config in the [] method.
        super(name).config({:layout=>name}.merge(options)) if options
        super(name)
      end
      
      def all
        if !@loaded
	        get_layout_names.each {|record|
	          name = record['LAYOUT_NAME']
	        	begin
	          	(self[name] = Rfm::Layout.new(name, @database)) unless !self[name].nil? or name.to_s.strip == ''
	          rescue
	          	$stderr.puts $!
	          end
	        }
          @loaded = true
        end
        self
      end
      
      def get_layout_names_xml
      	@server.connect(@database.account_name, @database.password, '-layoutnames', {"-db" => @database.name})
      end
      
      def get_layout_names
      	#Rfm::Resultset.new(@server, get_layout_names_xml.body, nil)
      	Rfm::Resultset.new(get_layout_names_xml.body, :database_object => @database)
      end
    
    	def names
    		keys
    	end
{'fraction_non_alphanumeric': 0.12445616348055373, 'fraction_numerical': 0.0026367831245880024, 'mean_word_length': 2.385095939312807, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6060023', 'n_tokens_mistral': 2445, 'n_tokens_neox': 2364, 'n_words': 541}