<commit_before>require 'rubygems'
require 'sqlite3'
require 'active_record'

# connect to database.  This will create one if it doesn't exist
MY_DB_NAME = "oneenv.db"
MY_DB = SQLite3::Database.new(MY_DB_NAME)

# get active record set up
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => MY_DB_NAME)

class Cookbook < ActiveRecord::Base
    #has_one :enviroment
    #self.primary_key= name
    self.connection.create_table(:cookbooks,:force=>true) do |t|
        t.column :name, :string, :null=>false, :unique=>true
        t.column :path, :string
        # Parece ser que type esta reservado por ruby, cambiado por place
        t.column :place, :string, :default=>'L'
    end
    validates_uniqueness_of :name
    # Obliga a que el campo :place sea R o L
    validates :place, :inclusion => {:in=> ['R', 'L'], :message=> "%{value} no es un valor correcto" }
end

class Env_db < ActiveRecord::Base
    belongs_to :cookbook
    #set_table_name :enviroments
    self.table_name= 'enviroments'
    self.connection.create_table(:enviroments,:force=>true) do |t|
        # El identificador autonumerado se crea automaticamente
        t.column :name, :string, :default=>'env-' #+:id.to_s
        t.column :ssh, :string, :default=>nil
        t.column :cookbooks, :cookbook
    end
   
end

#=begin
Cookbook.create(:name=>'emacs', :path=>'/ruta/hacia/emacs')
Cookbook.create(:name=>'vim', :path=>'/ruta/hacia/vim')
Cookbook.create(:name=>'apache', :path=>'/ruta/hacia/apache')
#=begin
Env_db.create(:name=>'nombre1', :ssh=>'clave1', :cookbooks => Cookbook.find(2))
Env_db.create(:ssh=>'clave2')
Env_db.create(:name=>'nombre3', :ssh=>'clave3', :cookbooks => Cookbook.first(:conditions => {:name => 'emacs'}))
#=end<commit_msg>Valor por defecto de cada entorno env-ID<commit_after>require 'rubygems'
require 'sqlite3'
require 'active_record'

# connect to database.  This will create one if it doesn't exist
MY_DB_NAME = "oneenv.db"
MY_DB = SQLite3::Database.new(MY_DB_NAME)

# get active record set up
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => MY_DB_NAME)

class Cookbook < ActiveRecord::Base
    #has_one :enviroment
    #self.primary_key= name
    self.connection.create_table(:cookbooks,:force=>true) do |t|
        t.column :name, :string, :null=>false, :unique=>true
        t.column :path, :string
        # Parece ser que type esta reservado por ruby, cambiado por place
        t.column :place, :string, :default=>'L'
    end
    validates_uniqueness_of :name
    # Obliga a que el campo :place sea R o L
    validates :place, :inclusion => {:in=> ['R', 'L'], :message=> "%{value} no es un valor correcto" }
end

class Env_db < ActiveRecord::Base
    belongs_to :cookbook
    #set_table_name :enviroments
    self.table_name= 'enviroments'
    #self.primary_key= 'id'
    self.connection.create_table(:enviroments,:force=>true) do |t|
        # El identificador autonumerado se crea automaticamente
        t.column :name, :string, :default=>'env-'+ (last.id-1).to_s
        t.column :ssh, :string, :default=>nil
        t.column :cookbooks, :cookbook
    end
   
end

#=begin
Cookbook.create(:name=>'emacs', :path=>'/ruta/hacia/emacs')
Cookbook.create(:name=>'vim', :path=>'/ruta/hacia/vim')
Cookbook.create(:name=>'apache', :path=>'/ruta/hacia/apache')
#=begin
Env_db.create(:name=>'nombre1', :ssh=>'clave1', :cookbooks => Cookbook.find(2))
Env_db.create(:ssh=>'clave2')
Env_db.create(:name=>'nombre3', :ssh=>'clave3', :cookbooks => Cookbook.first(:conditions => {:name => 'emacs'}))
#=end
{'fraction_non_alphanumeric': 0.15934684684684686, 'fraction_numerical': 0.005349099099099099, 'mean_word_length': 4.491499227202473, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '577990', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1262, 'n_words': 291}