Class: Riddl::Parameter::Complex
- Inherits:
-
Object
- Object
- Riddl::Parameter::Complex
- Defined in:
- lib/ruby/riddl/parameter.rb
Instance Attribute Summary collapse
-
#additional ⇒ Object
readonly
Returns the value of attribute additional.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#mimetype ⇒ Object
readonly
Returns the value of attribute mimetype.
-
#mimextra ⇒ Object
readonly
Returns the value of attribute mimextra.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(name, mimetype, file = nil, filename = nil, additional = []) ⇒ Complex
constructor
A new instance of Complex.
- #reopen ⇒ Object
- #to_json ⇒ Object
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
#additional ⇒ Object (readonly)
Returns the value of attribute additional.
27 28 29 |
# File 'lib/ruby/riddl/parameter.rb', line 27 def additional @additional end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
27 28 29 |
# File 'lib/ruby/riddl/parameter.rb', line 27 def filename @filename end |
#mimetype ⇒ Object (readonly)
Returns the value of attribute mimetype.
27 28 29 |
# File 'lib/ruby/riddl/parameter.rb', line 27 def mimetype @mimetype end |
#mimextra ⇒ Object (readonly)
Returns the value of attribute mimextra.
27 28 29 |
# File 'lib/ruby/riddl/parameter.rb', line 27 def mimextra @mimextra end |
#name ⇒ Object
Returns the value of attribute name.
28 29 30 |
# File 'lib/ruby/riddl/parameter.rb', line 28 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
27 28 29 |
# File 'lib/ruby/riddl/parameter.rb', line 27 def type @type end |
#value ⇒ Object (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
#reopen ⇒ Object
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_json ⇒ Object
29 30 31 |
# File 'lib/ruby/riddl/parameter.rb', line 29 def to_json(*) "{\"name\": \"#{@name}\", \"value\": \"#{@value}\"}" end |