Module: ActiveRecordContentBlob::Blobable::ClassMethods
- Defined in:
- lib/content_blob/blobable.rb
Instance Method Summary collapse
-
#build_with_a_blob(hsh, blob_content = nil) ⇒ Object
returns a new record with an attached blob e.g.
- #create_with_a_blob(hsh, blob_content = nil) ⇒ Object
-
#prepare_content_for_blob(some_content) ⇒ Object
allow this to be redefined.
Instance Method Details
#build_with_a_blob(hsh, blob_content = nil) ⇒ Object
returns a new record with an attached blob e.g. Record.build_with_a_blob(record_hsh, record_big_hsh)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/content_blob/blobable.rb', line 29 def build_with_a_blob(hsh, blob_content=nil) hsh_syms = hsh.symbolize_keys # exclude :contents from instantiating a new Record record = self.new(hsh_syms.reject{|k,v| k == :contents}) stuff = if blob_content.present? # build a blob using :blob_content blob_content elsif c = hsh_syms[:contents] c else # then build a blob from the hsh hsh end prepared_stuff = prepare_content_for_blob(stuff) record.build_a_blob(prepared_stuff) return record end |
#create_with_a_blob(hsh, blob_content = nil) ⇒ Object
50 51 52 |
# File 'lib/content_blob/blobable.rb', line 50 def create_with_a_blob(hsh, blob_content=nil) build_with_a_blob(hsh, blob_content).save end |
#prepare_content_for_blob(some_content) ⇒ Object
allow this to be redefined
55 56 57 |
# File 'lib/content_blob/blobable.rb', line 55 def prepare_content_for_blob(some_content) some_content end |