-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
6 changed files
with
51 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module ActiveRecord | ||
module Type | ||
class Time < ActiveModel::Type::Time | ||
include Internal::Timezone | ||
|
||
class Value < DelegateClass(::TimeOfDay) # :nodoc: | ||
end | ||
|
||
def map(value) | ||
value | ||
end | ||
|
||
def serialize(value) | ||
case value = super | ||
when ::TimeOfDay | ||
Value.new(value) | ||
else | ||
value | ||
end | ||
end | ||
|
||
def serialize_cast_value(value) | ||
Value.new(value) if value | ||
end | ||
|
||
private def cast_value(value) | ||
return value.time_of_day if value.is_a?(::DateTime) || value.is_a?(::Time) | ||
return value unless value.is_a?(::String) | ||
return if value.empty? | ||
|
||
TimeOfDay._parse(value) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'active_record/connection_adapters/abstract/quoting' | ||
|
||
module Activerecord | ||
module Time | ||
module Quoting | ||
def quote(value) | ||
return "'#{value}'" if value.is_a?(TimeOfDay) | ||
|
||
super(value) | ||
super | ||
end | ||
|
||
def type_cast(value) | ||
return value.to_s if value.is_a?(TimeOfDay) | ||
|
||
super(value) | ||
super | ||
end | ||
end | ||
end | ||
end | ||
|
||
ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend Activerecord::Time::Quoting | ||
|
||
module Activerecord | ||
module Time | ||
module Casting | ||
private def cast_value(value) | ||
return value.time_of_day if value.is_a?(::DateTime) || value.is_a?(::Time) | ||
return value unless value.is_a?(::String) | ||
return if value.empty? | ||
|
||
TimeOfDay._parse(value) | ||
end | ||
end | ||
end | ||
end | ||
ActiveRecord::Type::Time.prepend Activerecord::Time::Casting |
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 |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
module Activerecord | ||
module Time | ||
VERSION = '0.22.0' | ||
VERSION = '1.0.0' | ||
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
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