Class: Praxis::Multipart
- Inherits:
-
Attributor::Hash
- Object
- Attributor::Hash
- Praxis::Multipart
- Defined in:
- lib/praxis/types/multipart.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#parts ⇒ Object
Returns the value of attribute parts.
-
#preamble ⇒ Object
Returns the value of attribute preamble.
Class Method Summary collapse
- .example(context = nil, options: {}) ⇒ Object
- .load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, content_type:) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
56 57 58 |
# File 'lib/praxis/types/multipart.rb', line 56 def headers @headers end |
#parts ⇒ Object
Returns the value of attribute parts.
55 56 57 |
# File 'lib/praxis/types/multipart.rb', line 55 def parts @parts end |
#preamble ⇒ Object
Returns the value of attribute preamble.
54 55 56 |
# File 'lib/praxis/types/multipart.rb', line 54 def preamble @preamble end |
Class Method Details
.example(context = nil, options: {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/praxis/types/multipart.rb', line 26 def self.example(context=nil, options: {}) form = MIME::Multipart::FormData.new super(context, options: ).each do |k,v| body = if v.respond_to?(:dump) && !v.kind_of?(String) JSON.pretty_generate(v.dump) else v end entity = MIME::Text.new(body) form.add entity, String(k) end content_type = form.headers.get('Content-Type') body = form.body.to_s self.load(body, context, content_type: content_type) #result.each do |k, v| # result.parts[k] = MultipartPart.new(v) #end #result.headers = {'Content-Type'} end |
.load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, content_type:) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/praxis/types/multipart.rb', line 7 def self.load(value, context=Attributor::DEFAULT_ROOT_CONTEXT, content_type:) #return super if content_type.nil? headers = {'Content-Type' => content_type} parser = MultipartParser.new(headers, value) preamble, parts = parser.parse hash = Hash[parts.collect { |name, part| [name, part.body] }] instance = super(hash, context, **) instance.preamble = preamble instance.parts = parts instance.headers = headers instance end |
Instance Method Details
#validate(context = Attributor::DEFAULT_ROOT_CONTEXT) ⇒ Object
59 60 61 |
# File 'lib/praxis/types/multipart.rb', line 59 def validate(context=Attributor::DEFAULT_ROOT_CONTEXT) super end |