Class: Attributor::Tempfile
- Inherits:
-
Object
- Object
- Attributor::Tempfile
- Includes:
- Type
- Defined in:
- lib/attributor/types/tempfile.rb
Class Method Summary collapse
- .dump(value, **opts) ⇒ Object
- .example(context = Attributor::DEFAULT_ROOT_CONTEXT, options: {}) ⇒ Object
- .family ⇒ Object
- .load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options) ⇒ Object
- .native_type ⇒ Object
Methods included from Type
Class Method Details
.dump(value, **opts) ⇒ Object
19 20 21 |
# File 'lib/attributor/types/tempfile.rb', line 19 def self.dump(value, **opts) value && value.read end |
.example(context = Attributor::DEFAULT_ROOT_CONTEXT, options: {}) ⇒ Object
11 12 13 14 15 16 17 |
# 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 /[:sentence:]/.gen file.write '.' file.rewind file end |
.family ⇒ Object
38 39 40 |
# File 'lib/attributor/types/tempfile.rb', line 38 def self.family String.family end |
.load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/attributor/types/tempfile.rb', line 23 def self.load(value,context=Attributor::DEFAULT_ROOT_CONTEXT, **) # 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 ⇒ Object
7 8 9 |
# File 'lib/attributor/types/tempfile.rb', line 7 def self.native_type return ::Tempfile end |