Module: ActiveRecordContentBlob::Blobable::ClassMethods
- Defined in:
- lib/content_blob/blobable.rb
Instance Method Summary collapse
-
#build_with_blob(hsh, blob_content = nil) ⇒ Object
returns a new record with an attached blob.
- #create_with_blob(hsh, blob_content = nil) ⇒ Object
Instance Method Details
#build_with_blob(hsh, blob_content = nil) ⇒ Object
returns a new record with an attached blob
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/content_blob/blobable.rb', line 25 def build_with_blob(hsh, blob_content=nil) hsh_syms = hsh.symbolize_keys # delete a possible :content_blob so that we can initialize # the record record = self.new(hsh_syms.reject{|k,v| k == :contents}) if blob_content.nil? # then build a blob only if hsh_syms has :content_blob key if hsh_syms.key?(:contents) blob_content = hsh_syms[:contents] record.build_a_blob(blob_content) end else # second argument is for the blo record.build_a_blob(blob_content) end return record end |
#create_with_blob(hsh, blob_content = nil) ⇒ Object
46 47 48 |
# File 'lib/content_blob/blobable.rb', line 46 def create_with_blob(hsh, blob_content=nil) build_with_blob(hsh, blob_content).save end |