class Praxis::Types::MultipartArray::PartDefinition

Attributes

filename_attribute[RW]
headers_attribute[RW]
payload_attribute[RW]

Public Class Methods

new(&block) click to toggle source
# File lib/praxis/types/multipart_array/part_definition.rb, line 9
def initialize(&block)
  instance_eval(&block)
end

Public Instance Methods

create_attribute(type = Attributor::Struct, **opts, &block) click to toggle source
# File lib/praxis/types/multipart_array/part_definition.rb, line 18
def create_attribute(type = Attributor::Struct, **opts, &block)
  # TODO: how do we want to handle any referenced types?
  Attributor::Attribute.new(type, opts, &block)
end
filename(type = String, **opts) click to toggle source
# File lib/praxis/types/multipart_array/part_definition.rb, line 43
def filename(type = String, **opts)
  @filename_attribute = create_attribute(type, **opts)
end
header(name, val = nil, **options) click to toggle source
# File lib/praxis/types/multipart_array/part_definition.rb, line 28
def header(name, val = nil, **options)
  block = proc { header(name, val, **options) }

  if @headers_attribute
    update_attribute(@headers_attribute, options, block)
  else
    type = Attributor::Hash.of(key: String)
    @headers_attribute = create_attribute(type,
                                          dsl_compiler: Praxis::ActionDefinition::HeadersDSLCompiler,
                                          case_insensitive_load: false, # :(
                                          allow_extra: true,
                                          &block)
  end
end
payload(type = Attributor::Struct, **opts, &block) click to toggle source
# File lib/praxis/types/multipart_array/part_definition.rb, line 23
def payload(type = Attributor::Struct, **opts, &block)
  # return @payload if !block_given? && type == Attributor::Struct
  @payload_attribute = create_attribute(type, **opts, &block)
end
update_attribute(attribute, options, block) click to toggle source
# File lib/praxis/types/multipart_array/part_definition.rb, line 13
def update_attribute(attribute, options, block)
  attribute.options.merge!(options)
  attribute.type.attributes(**options, &block)
end