Skip to content

Instantly share code, notes, and snippets.

@confact
Last active March 25, 2020 19:17
Show Gist options
  • Save confact/27d62ee6ca27a47182bd1a665f9b6a3f to your computer and use it in GitHub Desktop.
Save confact/27d62ee6ca27a47182bd1a665f9b6a3f to your computer and use it in GitHub Desktop.
Second attempt
module AvramEnumConstants
module Lucky
alias ColumnType = Int32
end
end
module AvramEnum
def self.adapter
Lucky
end
module Lucky
def from_db!(value : Int32)
new(value)
end
def parse(value : String)
from_value(value.to_i)
end
def parse(value : Int32)
from_value(value)
end
def to_db(value : Int32)
value.to_s
end
def to_db(value : Enum)
value.value.to_s
end
end
end
struct Enum
extend AvramEnum
include AvramEnumConstants
end
class MergeRequest < BaseModel
enum Status
Open = 0
Closed = 1
Merged = 2
end
table do
column name : String
column status : MergeRequest::Status
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment