-
-
Save confact/9f2e9048935ce33196697f3393223910 to your computer and use it in GitHub Desktop.
Trying to add db parsing to enum and cast it correctly.
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
module AvramEnum | |
macro included | |
def self.adapter | |
Lucky | |
end | |
module Lucky | |
alias ColumnType = Int32 | |
include Avram::Type | |
def from_db!(value : Int32) | |
{{@type}}.new(value) | |
end | |
def parse(value : String) | |
{{@type}}.from_value(value.to_i) | |
rescue ArgumentError | |
FailedCast.new | |
end | |
def parse(value : Int32) | |
{{@type}}.from_value(value) | |
rescue ArgumentError | |
FailedCast.new | |
end | |
def to_db(value : Int32) | |
value.to_s | |
end | |
def to_db(value : Enum) | |
value.value.to_s | |
end | |
class Criteria(T, V) < Avram::Criteria(T, V) | |
@upper = false | |
@lower = false | |
end | |
end | |
end | |
end | |
struct Enum | |
macro inherited | |
include AvramEnum | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment