replace all older rocket sign to new ":" from examples of active record and active models

This commit is contained in:
Rajarshi Das 2013-06-24 11:19:51 +05:30
parent 11ac1e8a2c
commit cbd4a2e317
3 changed files with 20 additions and 20 deletions

View File

@ -4,7 +4,7 @@ class Person
include ActiveModel::Conversion
include ActiveModel::Validations
validates_presence_of :name
validates :name, presence: true
attr_accessor :name

View File

@ -5,12 +5,12 @@ require 'benchmark/ips'
TIME = (ENV['BENCHMARK_TIME'] || 20).to_i
RECORDS = (ENV['BENCHMARK_RECORDS'] || TIME*1000).to_i
conn = { :adapter => 'sqlite3', :database => ':memory:' }
conn = { adapter: 'sqlite3', database: ':memory:' }
ActiveRecord::Base.establish_connection(conn)
class User < ActiveRecord::Base
connection.create_table :users, :force => true do |t|
connection.create_table :users, force: true do |t|
t.string :name, :email
t.timestamps
end
@ -19,7 +19,7 @@ class User < ActiveRecord::Base
end
class Exhibit < ActiveRecord::Base
connection.create_table :exhibits, :force => true do |t|
connection.create_table :exhibits, force: true do |t|
t.belongs_to :user
t.string :name
t.text :notes
@ -77,28 +77,28 @@ today = Date.today
puts "Inserting #{RECORDS} users and exhibits..."
RECORDS.times do
user = User.create(
:created_at => today,
:name => ActiveRecord::Faker.name,
:email => ActiveRecord::Faker.email
created_at: today,
name: ActiveRecord::Faker.name,
email: ActiveRecord::Faker.email
)
Exhibit.create(
:created_at => today,
:name => ActiveRecord::Faker.name,
:user => user,
:notes => notes
created_at: today,
name: ActiveRecord::Faker.name,
user: user,
notes: notes
)
end
Benchmark.ips(TIME) do |x|
ar_obj = Exhibit.find(1)
attrs = { :name => 'sam' }
attrs_first = { :name => 'sam' }
attrs_second = { :name => 'tom' }
attrs = { name: 'sam' }
attrs_first = { name: 'sam' }
attrs_second = { name: 'tom' }
exhibit = {
:name => ActiveRecord::Faker.name,
:notes => notes,
:created_at => Date.today
name: ActiveRecord::Faker.name,
notes: notes,
:created_at: Date.today
}
x.report("Model#id") do

View File

@ -2,13 +2,13 @@ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
require 'active_record'
class Person < ActiveRecord::Base
establish_connection :adapter => 'sqlite3', :database => 'foobar.db'
connection.create_table table_name, :force => true do |t|
establish_connection adapter: 'sqlite3', database: 'foobar.db'
connection.create_table table_name, force: true do |t|
t.string :name
end
end
bob = Person.create!(:name => 'bob')
bob = Person.create!(name: 'bob')
puts Person.all.inspect
bob.destroy
puts Person.all.inspect