-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvalue.rb
More file actions
45 lines (34 loc) · 722 Bytes
/
value.rb
File metadata and controls
45 lines (34 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true
module Solid::Value
module ClassMethods
UNDEFINED = ::Object.new
def new(value = UNDEFINED)
return value if value.is_a?(self)
UNDEFINED.equal?(value) ? super() : super(value: value)
end
def attribute(...)
super(:value, ...)
end
def validates(...)
super(:value, ...)
end
def normalizes(...)
super(:value, ...)
end
end
def self.included(subclass)
subclass.include Solid::Model
subclass.extend ClassMethods
subclass.attribute
end
def ==(other)
other.is_a?(self.class) && other.value == value
end
def hash
value.hash
end
def to_s
value.to_s
end
alias_method :eql?, :==
end