Sha256: 1a09b0a42e366d8031f9e24cd32a5165eae62e409157bd07cd0808afc69c5d20

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

module Olivander
  module Resources
    module CrudController
      def index
        execute_crud_chain(crud_action: :index)
      end

      def new
        execute_crud_chain(crud_action: :new)
      end

      def create
        execute_crud_chain(crud_action: :create)
      end

      def show
        execute_crud_chain(crud_action: :show)
      end

      def edit
        execute_crud_chain(crud_action: :edit)
      end

      def update
        execute_crud_chain(crud_action: :update)
      end

      def destroy
        execute_crud_chain(crud_action: :destroy)
      end

      def execute_crud_chain(crud_action: action_name, only: [], skip: [], &block)
        chain = default_crud_chain(crud_action)
        chain.clear_keys_except(only) if only.size.positive?
        chain.clear_keys(skip) if skip.size.positive?
        yield(chain) if block_given?
        chain.execute
      end

      def default_crud_chain(crud_action = '')
        chain = Olivander::Resources::CrudChain.new(self)
        chain.links.keys.each do |k|
          method_name = "crud_chain_#{crud_action}_#{k}"
          method_name = "crud_chain_#{k}" unless respond_to?(method_name)
          next unless respond_to?(method_name)

          chain.on(k) do
            send(method_name)
          end
        end
        chain
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
five-two-nw-olivander-0.1.2.2 app/controllers/olivander/resources/crud_controller.rb
five-two-nw-olivander-0.1.2.1 app/controllers/olivander/resources/crud_controller.rb
five-two-nw-olivander-0.1.2 app/controllers/olivander/resources/crud_controller.rb