Class: Literal::Model
Constant Summary
Constants included
from Types
Types::BooleanType
Class Method Summary
collapse
Methods included from Types
_Any, _Array, _Boolean, _Class, _Enumerable, _Float, _Hash, _Integer, _Interface, _Maybe, _Set, _Tuple, _Union
#initialize
Class Method Details
.__attributes__ ⇒ Object
5
6
7
8
|
# File 'lib/literal/model.rb', line 5
def self.__attributes__
return @required_attributes if defined?(@required_attributes)
@required_attributes = superclass.is_a?(self) ? superclass.required_attributes.dup : []
end
|
.attribute(name, type) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/literal/model.rb', line 10
def self.attribute(name, type)
__attributes__ << name
writer_name = :"#{name}="
define_method writer_name do |value|
raise Literal::TypeError, "Expected #{name}: `#{value.inspect}` to be: `#{type.inspect}`." unless type === value
super(value)
end
name
end
|