Sha256: 60a1c5fadef472b18318618ec76e82c7d562089f106325b1ce5edfa483363b14

Contents?: true

Size: 1.05 KB

Versions: 34

Compression:

Stored size: 1.05 KB

Contents

class Event < ActiveRecord::Base
  include SocialStream::Models::Object

  scheduler

  belongs_to :room

  validates_presence_of :title

  validate :room_belongs_to_receiver

  def to_json(options = {})
    if recurrence
      st = options[:start].try(:to_date)
      en = (options[:end] || end_at.end_of_month + 7.days).to_date

      recurrence.events(:starts => st, :until  => en).map do |d|

        start_diff = d - start_at.to_date
        end_diff   = d - end_at.to_date

        build_json start_at.advance(:days => start_diff),
                   end_at.advance(:days => end_diff)
      end
    else
      build_json 
    end
  end

  protected

  def build_json(start_time = start_at, end_time = end_at)
      {
        :id => id,
        :title => title,
        :start => start_time,
        :end => end_time,
        :allDay => all_day?,
        :roomId => room_id
      }

  end

  private

  def room_belongs_to_receiver
    return if room_id.blank?

    unless _contact.receiver.room_ids.include?(room_id)
      errors.add(:room_id, :invalid)
    end
  end
end

Version data entries

34 entries across 34 versions & 4 rubygems

Version Path
social_stream-0.22.1 events/app/models/event.rb
social_stream-events-0.8.2 app/models/event.rb
social_stream-0.22.0 events/app/models/event.rb
social_stream-0.21.4 events/app/models/event.rb
social_stream-events-0.8.1 app/models/event.rb
social_stream-0.21.3 events/app/models/event.rb
social_stream-0.21.2 events/app/models/event.rb
social_stream-0.21.1 events/app/models/event.rb
social_stream-0.21.0 events/app/models/event.rb
social_stream-events-0.8.0 app/models/event.rb
social_stream-0.20.2 events/app/models/event.rb
social_stream-events-0.7.1 app/models/event.rb
social_stream-0.20.1 events/app/models/event.rb
social_stream-0.20.0 events/app/models/event.rb
social_stream-events-0.7.0 app/models/event.rb
social_stream-0.19.3 events/app/models/event.rb
social_stream-events-0.6.2 app/models/event.rb
social_stream-0.19.2 events/app/models/event.rb
social_stream-0.19.1 events/app/models/event.rb
social_stream-events-0.6.1 app/models/event.rb