This file contains hidden or 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 Numeric | |
def negative | |
if self <= 0 | |
self | |
else | |
self * -1 | |
end | |
end | |
end |
This file contains hidden or 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 Animal < Struct.new(:species) | |
end | |
o1 = Animal.new(:duck) | |
o2 = Animal.new(:duck) | |
o3 = Animal.new(:goose) | |
[o1,o2,o3].each do |animal| | |
sound = animal.species == :duck ? 'Quack' : 'Say What?' |
This file contains hidden or 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
# Concept From: http://github.com/eugenebolshakov/override_rake_task | |
# Namespace Support: Ken Collins <[email protected]> | |
Rake::TaskManager.class_eval do | |
def alias_task(fq_name) | |
new_name = "#{fq_name}:original" | |
@tasks[new_name] = @tasks.delete(fq_name) | |
end | |
end |
This file contains hidden or 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
# Place this in your rails lib directory and require in your Rakefile. | |
Rake::TaskManager.class_eval do | |
def alias_task(fq_name) | |
new_name = "#{fq_name}:original" | |
@tasks[new_name] = @tasks.delete(fq_name) | |
end | |
end | |
def alias_task(fq_name) |
This file contains hidden or 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
# Place this in lib/tasks | |
namespace :db do | |
alias_task_chain :charset => :environment do | |
config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] | |
case config['adapter'] | |
when 'sqlserver' | |
ActiveRecord::Base.establish_connection(config) | |
puts ActiveRecord::Base.connection.charset |
This file contains hidden or 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
# Assume ApplicationController has the filters setup that you see in | |
# BEFORE_FILTERS. Also assume you have mixed in MyControllerFilters into | |
# application controller so you can use all its class/instance methods. | |
module MyControllerFilters | |
BEFORE_FILTERS = [ | |
:shoot_zombies, | |
:set_timezone, | |
:authorize_request, |
This file contains hidden or 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
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb | |
index f3fd37c..4e95cac 100644 | |
--- a/activerecord/test/schema/schema.rb | |
+++ b/activerecord/test/schema/schema.rb | |
@@ -335,7 +335,7 @@ ActiveRecord::Schema.define do | |
t.decimal :decimal_number_with_default, :precision => 3, :scale => 2, :default => 2.78 | |
t.float :temperature | |
# Oracle supports precision up to 38 | |
- if current_adapter?(:OracleAdapter) | |
+ if current_adapter?(:OracleAdapter,:SQLServerAdapter) |
This file contains hidden or 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 quoted_date_format | |
@current_lauguage ||= user_option['language'] | |
@current_dateformat ||= user_option['dateformat'] | |
if sqlserver_2005? || sqlserver_2008? && @current_dateformat != 'mdy' | |
sqlserver_2005? ? :sqlserver_iso8601_3 : :sqlserver_iso8601_6 | |
else | |
:sqlserver_db | |
end | |
end |
This file contains hidden or 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
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!( | |
:sqlserver_db => Proc.new { |value| | |
value.respond_to?(:usec) && value.usec != 0 ? | |
value.strftime("%Y-%m-%dT%H:%M:%S.#{sprintf("%03d",value.usec/1000)}") : | |
value.strftime "%Y-%m-%dT%H:%M:%S" | |
} | |
) | |
>> Time.now.to_s(:sqlserver_db) | |
=> "2010-06-30T09:07:45.905" |
This file contains hidden or 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
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!( | |
:db => "%Y-%m-%dT%H:%M:%S" | |
) | |
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!( | |
:db => "%Y%m%d" | |
) |