Class: Composable::Form::Command
- Inherits:
-
Object
- Object
- Composable::Form::Command
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, Core::AttributeDSL, Core::Callbacks, Core::ComposableDSL
- Defined in:
- lib/composable/form/command.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.composable(attribute, model: nil, **options, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/composable/form/command.rb', line 19 def composable(attribute, model: nil, **, &block) super(attribute, **, &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 |
.inherited(subclass) ⇒ Object
14 15 16 17 |
# File 'lib/composable/form/command.rb', line 14 def inherited(subclass) super subclass.prepend(Core::Command) end |
Instance Method Details
#call ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/composable/form/command.rb', line 32 def call return unless valid? run_callbacks :save do save_composables { save } end end |
#new_record? ⇒ Boolean
44 45 46 |
# File 'lib/composable/form/command.rb', line 44 def new_record? true end |
#persisted? ⇒ Boolean
40 41 42 |
# File 'lib/composable/form/command.rb', line 40 def persisted? false end |