Class: Riddl::Parameter::Complex

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/riddl/parameter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, mimetype, file = nil, filename = nil, additional = []) ⇒ Complex

Returns a new instance of Complex.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ruby/riddl/parameter.rb', line 32

def initialize(name,mimetype,file=nil,filename=nil,additional=[])
  @name = name
  @mimetype = mimetype.gsub(/(;.*)/,'')
  @mimextra = $1 || ''
  @filename = filename
  @type = :body
  @additional = additional

  @value = block_given? ? yield : file
  unless (@value && (@value.class == String || (file.respond_to?(:read) && file.respond_to?(:rewind))))
    raise "ERROR input is not a stream or string"
  end
end

Instance Attribute Details

#additionalObject (readonly)

Returns the value of attribute additional.



27
28
29
# File 'lib/ruby/riddl/parameter.rb', line 27

def additional
  @additional
end

#filenameObject (readonly)

Returns the value of attribute filename.



27
28
29
# File 'lib/ruby/riddl/parameter.rb', line 27

def filename
  @filename
end

#mimetypeObject (readonly)

Returns the value of attribute mimetype.



27
28
29
# File 'lib/ruby/riddl/parameter.rb', line 27

def mimetype
  @mimetype
end

#mimextraObject (readonly)

Returns the value of attribute mimextra.



27
28
29
# File 'lib/ruby/riddl/parameter.rb', line 27

def mimextra
  @mimextra
end

#nameObject

Returns the value of attribute name.



28
29
30
# File 'lib/ruby/riddl/parameter.rb', line 28

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



27
28
29
# File 'lib/ruby/riddl/parameter.rb', line 27

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



27
28
29
# File 'lib/ruby/riddl/parameter.rb', line 27

def value
  @value
end

Instance Method Details

#reopenObject



45
46
47
48
49
50
51
# File 'lib/ruby/riddl/parameter.rb', line 45

def reopen
  if @value.class == File || @value.class == Riddl::Parameter::Tempfile
    pname = @value.path
    @value.close
    @value = File.open(pname,'r')
  end  
end

#to_jsonObject



29
30
31
# File 'lib/ruby/riddl/parameter.rb', line 29

def to_json(*)
  "{\"name\": \"#{@name}\", \"value\": \"#{@value}\"}"
end