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.



11
12
13
# File 'lib/praxis/types/multipart_array/part_definition.rb', line 11

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

Instance Attribute Details

#filename_attributeObject

Returns the value of attribute filename_attribute.



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

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.



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

def payload_attribute
  @payload_attribute
end

Instance Method Details

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



20
21
22
23
# File 'lib/praxis/types/multipart_array/part_definition.rb', line 20

def create_attribute(type=Attributor::Struct, **opts, &block)
  # TODO: how do we want to handle any referenced types?
  return Attributor::Attribute.new(type, opts, &block)
end

#filename(type = String, **opts) ⇒ Object



45
46
47
# File 'lib/praxis/types/multipart_array/part_definition.rb', line 45

def filename(type=String, **opts)
  @filename_attribute = create_attribute(type, **opts)
end

#header(name, val = nil, **options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/praxis/types/multipart_array/part_definition.rb', line 30

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



25
26
27
28
# File 'lib/praxis/types/multipart_array/part_definition.rb', line 25

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



15
16
17
18
# File 'lib/praxis/types/multipart_array/part_definition.rb', line 15

def update_attribute(attribute, options, block)
  attribute.options.merge!(options)
  attribute.type.attributes(options, &block)
end