-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
151 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
module UuidAttribute | ||
# UUID Attribute | ||
class Type < ActiveModel::Type::Binary | ||
def type | ||
:uuid | ||
end | ||
|
||
def serialize(value) | ||
#puts "SERIALIZE" | ||
return if value.blank? | ||
return value if value.is_a?(ActiveRecord::Type::Binary::Data) | ||
|
||
binary_data = value | ||
binary_data = Utils.raw_bytes(Utils.normalize(Utils.parse(value))) if value.is_a?(String) | ||
# binary_data = value.raw if value.is_a?(UUID) | ||
|
||
ActiveRecord::Type::Binary::Data.new( | ||
binary_data | ||
) | ||
end | ||
|
||
def deserialize(value) | ||
# puts "DESERIALIZE" | ||
return nil if value.nil? | ||
value = value.to_s if value.is_a?(ActiveModel::Type::Binary::Data) | ||
|
||
# return UUID.new(Utils.normalize(Utils.parse(value))) | ||
return Utils.shorten(Utils.normalize(Utils.parse(value))) | ||
# ActiveRecord::Type::Binary::Data.new(Utils.raw_bytes(Utils.normalize(Utils.parse(value)))) | ||
end | ||
|
||
def cast(value) | ||
# puts "CAST" | ||
return nil if value.nil? | ||
# return value if value.is_a?(UUID) | ||
|
||
value = value.to_s if value.is_a?(ActiveModel::Type::Binary::Data) | ||
return Utils.shorten(Utils.normalize(Utils.parse(value))) | ||
# super | ||
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
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,28 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module UuidAttribute | ||
# UUID Attribute | ||
class UUID < ActiveModel::Type::Binary | ||
def type | ||
:uuid | ||
class UUID | ||
def initialize(value) | ||
@hex = Utils.normalize(Utils.parse(value)) | ||
@shorten = Utils.shorten(@hex) | ||
end | ||
|
||
def serialize(value) | ||
return if value.blank? | ||
|
||
ActiveRecord::Type::Binary::Data.new( | ||
Utils.raw_bytes(Utils.normalize(Utils.parse(value))) | ||
) | ||
def to_s | ||
@shorten | ||
end | ||
|
||
def deserialize(value) | ||
return nil if value.nil? | ||
|
||
Utils.shorten(Utils.parse(value.to_s)) | ||
def hex | ||
@hex | ||
end | ||
|
||
def cast(value) | ||
deserialize(value) | ||
def raw | ||
UuidAttribute::Utils.raw_bytes(@hex) | ||
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,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module UuidAttribute | ||
VERSION = "0.9.11" | ||
VERSION = "0.9.12" | ||
end |