This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddRandomSlugToReports < ActiveRecord::Migration | |
def self.up | |
change_table :reports do |t| | |
t.string :slug | |
t.index :slug | |
end | |
Report.reset_column_information | |
Report.all.each do |report| | |
report.generate_slug! | |
report.save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the basics of class reloading in ruby | |
# it's all based around unloading with Module#remove_const | |
# then reloading with Kernel#load | |
# the rest is just housekeeping | |
require 'foo' | |
Foo.exclaim! | |
Object.instance_eval { remove_const :Foo } | |
load 'foo.rb' | |
Foo.still_there? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
require 'yaml' | |
require 'set' | |
# This overrides 'require' to records the time it takes to require a file, and | |
# then generate a report. It's intelligent enough to figure out where files were | |
# required from and construct a hierarchy of the required files. | |
# | |
# To use, copy this file to lib/require_benchmarking.rb, then add this to the | |
# top of the Rails::Initializer block in environment.rb: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sequence4(n, m, c, b) | |
# p("Inside sequence4") | |
i = 0 | |
while(i < n) | |
b.call i*m + c | |
i += 1 | |
end | |
end | |
proc1 = Proc.new { |x| puts x } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The ASF licenses this file to You under the Apache License, Version 2.0 | |
# (the "License"); you may not use this file except in compliance with | |
# the License. You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo < ActiveRecord::Base | |
searchable do | |
# ... | |
end | |
handle_asynchronously :solr_index | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Denormalized multi-valued indexing with Solr and Sunspot | |
class Company | |
has_many :services | |
has_many :products | |
searchable do | |
text :name | |
text :description | |
string :service_names, :multiple => true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nick@ariga:~/src/sunspot/sunspot_rails master BUNDLE_GEMFILE=spec/rails3/Gemfile RAILS_ROOT=spec/rails3/ bundle exec rspec spec/ | |
You did not specify how you would like Rails to report deprecation notices for your test environment, please set config.active_support.deprecation to :stderr at config/environments/test.rb | |
DEPRECATION WARNING: You are using the old router DSL which will be removed in Rails 3.1. Please check how to update your routes file at: http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/. (called from <top (required)> at /Users/nick/src/sunspot/sunspot_rails/spec/rails3/config/routes.rb:1) | |
/usr/local/Cellar/ruby/1.9.2-p0/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/example_group.rb:30:in `block (2 levels) in delegate_to_metadata': wrong number of arguments (1 for 0) (ArgumentError) | |
from /Users/nick/src/sunspot/sunspot_rails/spec/request_lifecycle_spec.rb:19:in `block in <top (required)>' | |
from /usr/local/Cellar/ruby/1.9.2-p0/lib/ruby/gems/1.9.1/gems/rspec- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Experimenting with a brute force check to see if your Solr index is in sync | |
# with your database. This example uses Sunspot for the #solr_index method, | |
# but not for the searching. We query Solr and the local database directly | |
# to page through this stuff as quickly as possible. | |
# | |
# Got a better approach? Ping @websolr on Twitter :) | |
# | |
start = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo < AR::Base | |
searchable do | |
string :tag_names, :multiple => true | |
end | |
def tag_names | |
tags.map(&:name) | |
end |