class Attributor::Tempfile

Public Class Methods

dump(value, **_opts) click to toggle source
# File lib/attributor/types/tempfile.rb, line 19
def self.dump(value, **_opts)
  value && value.read
end
example(context = Attributor::DEFAULT_ROOT_CONTEXT, options: {}) click to toggle source
# File lib/attributor/types/tempfile.rb, line 11
def self.example(context = Attributor::DEFAULT_ROOT_CONTEXT, options: {})
  file = ::Tempfile.new(Attributor.humanize_context(context))
  file.write Faker::Lorem.paragraph
  file.write '.'
  file.rewind
  file
end
family() click to toggle source
# File lib/attributor/types/tempfile.rb, line 38
def self.family
  String.family
end
json_schema_type() click to toggle source
# File lib/attributor/types/tempfile.rb, line 42
def self.json_schema_type
  :string
end
load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options) click to toggle source
Calls superclass method
# File lib/attributor/types/tempfile.rb, line 23
def self.load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options)
  # TODO: handle additional cases that make sense
  case value
  when ::String
    name = Attributor.humanize_context(context)

    file = ::Tempfile.new(name)
    file.write(value)
    file.rewind
    return file
  end

  super
end
native_type() click to toggle source
# File lib/attributor/types/tempfile.rb, line 7
def self.native_type
  ::Tempfile
end