Sha256: 4e8a6e1caa01cccd1a068f761cf2d7bdce7d294d5eabb258681cd0b08157ac3c

Contents?: true

Size: 867 Bytes

Versions: 4

Compression:

Stored size: 867 Bytes

Contents

# Models a controller action. To be used within the block of a WebUI.

require 'katapult/element'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/string/inquiry'

module Katapult
  class Action < Element

    options :method, :scope

    def initialize(*args)
      super

      self.scope ||= (name == 'index') ? :collection : :member
      set_method
    end

    delegate :post?, :get?, :put?, to: :method_inquiry
    delegate :member?, :collection?, to: :scope_inquiry

    private

    def method_inquiry
      @method.to_s.inquiry
    end

    def scope_inquiry
      @scope.to_s.inquiry
    end

    def set_method
      self.method ||= case name
      when 'create', 'update'
        :post
      when 'destroy'
        :delete
      else # index, show, new, edit + custom actions
        :get
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
katapult-0.5.0 lib/katapult/elements/action.rb
katapult-0.4.1 lib/katapult/elements/action.rb
katapult-0.4.0 lib/katapult/elements/action.rb
katapult-0.3.0 lib/katapult/action.rb