Sha256: fa0b0cfa34cf56e2d6127f4525ccb32d003b16f85ce27e370bffdd6ecbe07282

Contents?: true

Size: 745 Bytes

Versions: 15

Compression:

Stored size: 745 Bytes

Contents

# frozen_string_literal: true

module PUNK
  class Action < Service
    def self.perform(**kwargs)
      action = profile_info("perform", kwargs) { run(**kwargs) }
      action.result
    end

    def process
      raise NotImplemented, "action must provide process method"
    end

    def present(view_class, **kwargs)
      raise InternalServerError, "not a view: #{view_class}" unless view_class < View
      view_class.run(**kwargs)
    end

    protected

    def on_success
      raise InternalServerError, "not a view: #{result}" unless result.is_a?(View)
    end

    def on_failure
      @_result = Fail.run(message: "action failed: #{self.class}", error_messages: errors.full_messages, status: invalid? ? 400 : 500)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
punk-0.4.1 lib/punk/framework/action.rb
punk-0.3.6 lib/punk/framework/action.rb
punk-0.3.5 lib/punk/framework/action.rb
punk-0.3.4 lib/punk/framework/action.rb
punk-0.3.3 lib/punk/framework/action.rb
punk-0.3.2 lib/punk/framework/action.rb
punk-0.3.1 lib/punk/framework/action.rb
punk-0.2.0 lib/punk/framework/action.rb
punk-0.1.4 lib/punk/framework/action.rb
punk-0.1.3 lib/punk/framework/action.rb
punk-0.1.2 lib/punk/framework/action.rb
punk-0.1.0 lib/punk/framework/action.rb
punk-0.0.3 lib/punk/framework/action.rb
punk-0.0.2 lib/punk/framework/action.rb
punk-0.0.1 lib/punk/framework/action.rb