Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James Vanneman
committed
Mar 18, 2013
1 parent
2e5c71c
commit e01a0ba
Showing
8 changed files
with
51 additions
and
31 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module Searchlogic | ||
module SearchExt | ||
class TypeCaster | ||
attr_reader :value, :type, :column_for_typecast | ||
def initialize(value, type) | ||
@value = value | ||
@type = type | ||
@column_for_typecast = set_column(type) | ||
binding.pry | ||
end | ||
|
||
def column_type | ||
if defined?(Chronic) && value.kind_of?(String) && date_or_time? | ||
column_for_typecast.type_cast(value) || Chronic.try(:parse, sanitize_cdl_in_date(value)) | ||
else | ||
column_for_typecast.type_cast(value) | ||
end | ||
end | ||
|
||
private | ||
def set_column(type) | ||
::ActiveRecord::ConnectionAdapters::Column.new("", nil).tap{|col| col.instance_variable_set(:@type, type)} | ||
end | ||
|
||
def date_or_time? | ||
type == :datetime || type == :date || type == :time | ||
end | ||
|
||
def sanitize_cdl_in_date(value) | ||
value.gsub(",", "/") | ||
end | ||
end | ||
end | ||
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