Class: Model

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/model/model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.validates(&blk) ⇒ Object



11
12
13
# File 'lib/model/model.rb', line 11

def self.validates &blk
  @@validation_schema = Dry::Validation.Schema &blk
end

Instance Method Details

#to(clazz) ⇒ Object



19
20
21
22
# File 'lib/model/model.rb', line 19

def to clazz
  new_attributes = attributes.merge(clazz.different_attributes(attributes, self.class))
  clazz.new new_attributes
end

#to_jsonObject



24
25
26
# File 'lib/model/model.rb', line 24

def to_json
  attributes
end

#validateObject



15
16
17
# File 'lib/model/model.rb', line 15

def validate
  @@validation_schema.call(attributes).messages
end