Submitted by swarut on Mon, 07/02/2012 - 17:14
Here is a comment on the branch I was working on a few weeks ago.
RiCal.Calendar et al use instance_eval, so calling to_ics methods from such contexts resulted in idiomatic usage of opts.delete(:foo) bleeding the mutation into the calling scope. This meant that calling in a loop such as opts = { user: user } items.each { item.to_ics(opts) } resulted in the user k/v being absent after the first iteration.
I did not understand it much, especially it is about the block which is the concept that I do not understand it well.
-
# Provides an iCalendar VEVENT representation of the decorated Event, by way # of RiCal.## @param opts [Hash] A customizable set of options.# @options opts [User] :user The user for whom the ICS is being rendered, so# we can only set a VALARM if he or she has submitted an affirmative RSVP# for the Event.## @return [RiCal::Component::Event] the Event represented as an RiCal# component object. You may call {RiCal::Compenent#export} on the resulting# object in order to get a String representation that includes requisite# wrappers for iCalendar spec compliance, such as a VCALENDAR.## TODO: add test to check for rsvp eventdef to_ics(opts={})
opts = opts.dupuser = opts.delete(:user)
RiCal.Event do |ev|
ev.uid = ical_uidev.created = event.created_at.to_date
ev.last_modified = event.updated_at.to_date
ev.description = event.description if event.description
ev.dtstart = event.starts_at
ev.dtend = event.ends_at
ev.location = event.decorate.location
# TODO: format correctly if speaker/speaker title missingif event.has_speaker?
ev.summary = "#{event.title} by #{event.speaker_title} #{event.speaker_name}"
elseev.summary = event.title
end# TODO: move this RSVP check to a model methodif user && user.wants_ical_reminders? && event.rsvps.where{user_id.eq(user.id) & joining.in(['Y', 'M'])}.any?
ev.alarm do |alarm|
alarm.description = "#{event.title}"
alarm.trigger = ":-PT#{user.decorate.ical_reminder_offset}"
alarm.action = "DISPLAY"
endendendend
Must research this more.