Class: MediaContext

Inherits:
Context show all
Includes:
Mongoid::Document
Defined in:
app/models/contexts/media_context.rb

Overview

Base context for media data such as audio or video

Direct Known Subclasses

Audio, Video

Instance Method Summary (collapse)

Methods inherited from Context

#context_type, #set_default_position

Instance Method Details

- (Object) as_json(options = {})



26
27
28
29
# File 'app/models/contexts/media_context.rb', line 26

def as_json(options = {})
  options.merge!({ :only => [:asset_id, :source, :media_type ]})
  super(options)
end

- (Object) source

Returns the url source of the included media. If an attached asset is found, it returns the paperclip generated url, otherwise the `source` attribute is returned.



17
18
19
20
# File 'app/models/contexts/media_context.rb', line 17

def source
  return read_attribute("source") if self.asset_id.nil?
  self.asset.file.url(:original)
end

- (Boolean) source?

Returns:

  • (Boolean)


22
23
24
# File 'app/models/contexts/media_context.rb', line 22

def source?
  (source.nil? or source.to_s.blank?)
end