Sha256: fbcede5e506044fc7e6d86e4b04376708641833b468615ca48a036ca5469f369

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

class Audio < Content
  DISPLAY_NAME = 'Audio'
  after_initialize :set_kind, :create_config

  after_find :load_config
  before_validation :save_config

  attr_accessor :config

  # Automatically set the kind for the content
  # if it is new.  We use this hidden type that no fields
  # render so Dynamic Content meta content never gets displayed.
  def set_kind
    return unless new_record?
    self.kind = Kind.where(:name => 'Dynamic').first
  end

  # Create a new configuration hash if one does not already exist.
  # Called during `after_initialize`, where a config may or may not exist.
  def create_config
    self.config = {} if !self.config
  end

  # Load a configuration hash.
  # Converts the JSON data stored for the content into the configuration.
  # Called during `after_find`.
  def load_config
    self.config = JSON.load(self.data)
  end

  # Prepare the configuration to be saved.
  # Compress the config hash back into JSON to be stored in the database.
  # Called during `before_valication`.
  def save_config
    self.data = JSON.dump(self.config)
  end

  def self.form_attributes
    attributes = super()
    attributes.concat([:config => [:url]])
  end

  def render_details
    { :path => self.config['url'] }
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
concerto_audio-0.0.6 app/models/audio.rb
concerto_audio-0.0.5 app/models/audio.rb
concerto_audio-0.0.4 app/models/audio.rb
concerto_audio-0.0.3 app/models/audio.rb
concerto_audio-0.0.2 app/models/audio.rb
concerto_audio-0.0.1 app/models/audio.rb