Sha256: 7e0605b1adda92010f5f96dd125b5907d77081286f98e615a59ab91114ac160e

Contents?: true

Size: 967 Bytes

Versions: 6

Compression:

Stored size: 967 Bytes

Contents

module {{namespace_module}}
  module Accounts
    module Show
      class Control
        include Shogun::Control
        include Accounts

        def initialize(payload:)
          @normalizer = Normalizer.new(raw: payload.to_hash)
          @validator = Validator.new(data: @normalizer)

          if @validator.valid?
            @model = Model.find_by(id: @normalizer.id)

            if @model
              @presenter = Presenter.new(resource: @model, meta: @normalizer.as_meta)
              @denormalizer = Denormalizer.new(object: @presenter, fields: @normalizer.fields)
              @status = OK
            else
              @status = NOT_FOUND
            end
          else
            @presenters = Shogun::Presenters.new(resources: @validator.invalids, cast: Errors::Presenter)
            @denormalizer = Errors::Denormalizer.new(object: @presenters)
            @status = UNPROCESSABLE_ENTITY
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shogun-6.4.2 scaffold/new/project/lib/namespace/accounts/show/control.rb
shogun-6.4.1 scaffold/new/project/lib/namespace/accounts/show/control.rb
shogun-6.4.0 scaffold/new/project/lib/namespace/accounts/show/control.rb
shogun-6.3.0 scaffold/new/project/lib/namespace/accounts/show/control.rb
shogun-6.2.3 scaffold/new/project/lib/namespace/accounts/show/control.rb
shogun-6.2.2 scaffold/new/project/lib/namespace/accounts/show/control.rb