Created
February 7, 2022 03:05
-
-
Save serradura/8711f21dac3e6c23fb34f05337671070 to your computer and use it in GitHub Desktop.
Micro::Attributes::FormObject
This file contains hidden or 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
# frozen_string_literal: true | |
module Micro::Attributes | |
module FormObject | |
module ClassMethods | |
def empty | |
instance = self.allocate | |
instance.send(:attributes=, Kind::Empty::HASH) | |
instance | |
end | |
end | |
module InstanceMethods | |
def initialize(input) | |
self.attributes = input | |
run_validations! | |
end | |
def persisted? | |
false | |
end | |
def has_errors? | |
!errors.empty? | |
end | |
private def __call_after_attributes_assign | |
end | |
end | |
def self.included(base) | |
base.send(:include, Micro::Attributes.with(:activemodel_validation)) | |
base.send(:include, ActiveModel::Conversion) | |
base.extend(ActiveModel::Naming) | |
base.extend(ActiveModel::Translation) | |
base.extend(ClassMethods) | |
base.send(:include, InstanceMethods) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment