Module: Ladder::File
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveTriples::Identifiable, Mongoid::Document
- Defined in:
- lib/ladder/file.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
-
#data ⇒ Object
Output content of object from stored file or readable input.
-
#save ⇒ Object
Make save behave like Mongoid::Document as much as possible.
-
#update_resource ⇒ Object
Return an empty ActiveTriples resource for serializing related resources.
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
23 24 25 |
# File 'lib/ladder/file.rb', line 23 def file @file end |
Instance Method Details
#data ⇒ Object
Output content of object from stored file or readable input
36 37 38 39 40 41 42 |
# File 'lib/ladder/file.rb', line 36 def data @grid_file ||= self.class.grid.get(id) if persisted? return @grid_file.data if @grid_file file.rewind if file.respond_to? :rewind file.read end |
#save ⇒ Object
Make save behave like Mongoid::Document as much as possible
27 28 29 30 31 32 |
# File 'lib/ladder/file.rb', line 27 def save raise Mongoid::Errors::InvalidValue.new(IO, NilClass) if file.nil? attributes[:content_type] = file.content_type if file.respond_to? :content_type @grid_file ? @grid_file.save : !! @grid_file = self.class.grid.put(file, attributes.symbolize_keys) end |
#update_resource ⇒ Object
Return an empty ActiveTriples resource for serializing related resources
46 47 48 |
# File 'lib/ladder/file.rb', line 46 def update_resource resource end |