Sha256: 41319d1efb3f1a93a87dbd75e811e5be46d5fd2fbbd8ba347a655fc1ded2cd66
Contents?: true
Size: 1020 Bytes
Versions: 8
Compression:
Stored size: 1020 Bytes
Contents
# frozen_string_literal: true module Composable module Form class Command extend ActiveModel::Naming include Core::AttributeDSL include Core::ComposableDSL include Core::Callbacks include ActiveModel::Conversion class << self def inherited(subclass) super subclass.prepend(Core::Command) end def composable(attribute, model: nil, **options, &block) super(attribute, **options, &block) return unless model define_singleton_method(:model_name) do ActiveModel::Name.new(model) end delegate :id, :persisted?, :new_record?, to: attribute.to_sym, allow_nil: true end end def call return unless valid? run_callbacks :save do save_composables { save } end end def persisted? false end def new_record? true end private def save end end end end
Version data entries
8 entries across 8 versions & 1 rubygems