Class: Praxis::Types::MultipartArray::PartDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/praxis/types/multipart_array/part_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ PartDefinition

Returns a new instance of PartDefinition.



9
10
11
# File 'lib/praxis/types/multipart_array/part_definition.rb', line 9

def initialize(&block)
  instance_eval(&block)
end

Instance Attribute Details

#filename_attributeObject

Returns the value of attribute filename_attribute.



7
8
9
# File 'lib/praxis/types/multipart_array/part_definition.rb', line 7

def filename_attribute
  @filename_attribute
end

#headers_attributeObject

Returns the value of attribute headers_attribute.



7
8
9
# File 'lib/praxis/types/multipart_array/part_definition.rb', line 7

def headers_attribute
  @headers_attribute
end

#payload_attributeObject

Returns the value of attribute payload_attribute.



7
8
9
# File 'lib/praxis/types/multipart_array/part_definition.rb', line 7

def payload_attribute
  @payload_attribute
end

Instance Method Details

#create_attribute(type = Attributor::Struct, **opts, &block) ⇒ Object



18
19
20
21
# 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) ⇒ Object



43
44
45
# 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) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 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) ⇒ Object



23
24
25
26
# 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) ⇒ Object



13
14
15
16
# 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