Sha256: 7f2acb06c89922390d1ad35a0c91d9347bc3b77a0da4d5ede62ac6e141e89eba

Contents?: true

Size: 1.15 KB

Versions: 9

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Lite
  module Form
    module Helpers
      module Persistence

        module ClassMethods

          %i[create save update].each do |method_name|
            define_method(method_name) do |params = {}|
              klass = new(params)
              klass.send(method_name)
              klass
            end
          end

        end

        class << self

          def included(klass)
            klass.extend(ClassMethods)
          end

        end

        def persisted?
          false
        end

        def create
          raise Lite::Form::NotImplementedError unless defined?(create_action)
          return unless valid?

          run_callbacks(:create) { @result = create_action }
        end

        def save
          raise Lite::Form::NotImplementedError unless defined?(save_action)
          return unless valid?

          run_callbacks(:save) { @result = save_action }
        end

        def update
          raise Lite::Form::NotImplementedError unless defined?(update_action)
          return unless valid?

          run_callbacks(:update) { @result = update_action }
        end

      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lite-form-1.1.2 lib/lite/form/helpers/persistence.rb
lite-form-1.1.1 lib/lite/form/helpers/persistence.rb
lite-form-1.1.0 lib/lite/form/helpers/persistence.rb
lite-form-1.0.5 lib/lite/form/helpers/persistence.rb
lite-form-1.0.4 lib/lite/form/helpers/persistence.rb
lite-form-1.0.3 lib/lite/form/helpers/persistence.rb
lite-form-1.0.2 lib/lite/form/helpers/persistence.rb
lite-form-1.0.1 lib/lite/form/helpers/persistence.rb
lite-form-1.0.0 lib/lite/form/helpers/persistence.rb