<commit_before>require 'rubygems'
require 'active_record'

puts "Connecting to database..."

ActiveRecord::Base.establish_connection(
  :adapter => 'nuodb',
  :database => 'test',
  :username => 'cloud',
  :password => '<PASSWORD>'
)

puts "Create tables..."

class User < ActiveRecord::Base
  has_one :addr, :class_name => 'Addr'
  def to_s
    return "User(#{id}), Username: #{user_name}, Name: #{first_name} #{last_name}, #{admin ? "admin" : "member"}\n" +
    "  Address: #{addr}\n"
  end
end

class Addr < ActiveRecord::Base
  belongs_to :User
  def to_s
    return "Addr(#{id}:#{user_id}) Street: #{street} City: #{city} Zip: #{zip}"
  end
end

ActiveRecord::Schema.drop_table(User.table_name) rescue nil
ActiveRecord::Schema.drop_table(Addr.table_name) rescue nil

ActiveRecord::Schema.define do
  create_table User.table_name do |t|
    t.string :first_name, :limit => 20
    t.string :last_name, :limit => 20
    t.string :email, :limit => 20
    t.string :user_name, :limit => 20
    t.boolean :admin
  end
  create_table Addr.table_name do |t|
    t.integer :user_id
    t.string :street, :limit => 20
    t.string :city, :limit => 20
    t.string :zip, :limit => 6
  end
end

puts "Create user records..."

@u = User.create do |u|
  u.first_name = "Fred"
  u.last_name = "Flintstone"
  u.email = "<EMAIL>"
  u.user_name = "fred"
  u.admin = true
end

@u.create_addr do |a|
  a.street = "301 Cobblestone Way"
  a.city = "Bedrock"
  a.zip = "00001"
end

puts "Created #{@u}"

@u = User.create do |u|
  u.first_name = "Barney"
  u.last_name = "Rubble"
  u.email = "<EMAIL>"
  u.user_name = "barney"
  u.admin = false
end

@u.create_addr do |a|
  a.street = "303 Cobblestone Way"
  a.city = "Bedrock"
  a.zip = "00001"
end

puts "Created #{@u}"

puts "Print user records..."<commit_msg>Use local variable "u" rather than instance variable "@u"<commit_after>require 'rubygems'
require 'active_record'

puts "Connecting to database..."

ActiveRecord::Base.establish_connection(
  :adapter => 'nuodb',
  :database => 'test',
  :username => 'cloud',
  :password => '<PASSWORD>'
)

puts "Create tables..."

class User < ActiveRecord::Base
  has_one :addr, :class_name => 'Addr'
  def to_s
    return "User(#{id}), Username: #{user_name}, Name: #{first_name} #{last_name}, #{admin ? "admin" : "member"}\n" +
    "  Address: #{addr}\n"
  end
end

class Addr < ActiveRecord::Base
  belongs_to :User
  def to_s
    return "Addr(#{id}:#{user_id}) Street: #{street} City: #{city} Zip: #{zip}"
  end
end

ActiveRecord::Schema.drop_table(User.table_name) rescue nil
ActiveRecord::Schema.drop_table(Addr.table_name) rescue nil

ActiveRecord::Schema.define do
  create_table User.table_name do |t|
    t.string :first_name, :limit => 20
    t.string :last_name, :limit => 20
    t.string :email, :limit => 20
    t.string :user_name, :limit => 20
    t.boolean :admin
  end
  create_table Addr.table_name do |t|
    t.integer :user_id
    t.string :street, :limit => 20
    t.string :city, :limit => 20
    t.string :zip, :limit => 6
  end
end

puts "Create user records..."

u = User.create do |u|
  u.first_name = "Fred"
  u.last_name = "Flintstone"
  u.email = "<EMAIL>"
  u.user_name = "fred"
  u.admin = true
end

u.create_addr do |a|
  a.street = "301 Cobblestone Way"
  a.city = "Bedrock"
  a.zip = "00001"
end

puts "Created #{u}"

u = User.create do |u|
  u.first_name = "Barney"
  u.last_name = "Rubble"
  u.email = "<EMAIL>"
  u.user_name = "barney"
  u.admin = false
end

u.create_addr do |a|
  a.street = "303 Cobblestone Way"
  a.city = "Bedrock"
  a.zip = "00001"
end

puts "Created #{u}"

puts "Print user records..."
{'fraction_non_alphanumeric': 0.16188637617209045, 'fraction_numerical': 0.015995587424158852, 'mean_word_length': 3.596958174904943, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 33, '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': '4703486', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1380, 'n_words': 365}