Sha256: 0e8cf043739de2f5607abdf81237fc5794f1a88c376a33346653fd9b0222f094

Contents?: true

Size: 1.08 KB

Versions: 27

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    module Calendar
      # This class handles how to convert a component meetings to the ICalendar
      # format. It caches its result until the component is updated again.
      class ComponentCalendar < BaseCalendar
        # Renders the meetings in an ICalendar format. It caches the results in
        # Rails' cache.
        #
        # Returns a String.
        def events
          Rails.cache.fetch(cache_key) do
            meetings.map do |meeting|
              MeetingToEvent.new(meeting).to_ical
            end.join
          end
        end

        private

        alias component resource

        # Finds the component meetings.
        #
        # Returns a collection of Meetings.
        def meetings
          Decidim::Meetings::Meeting.where(component: component)
        end

        # Defines the cache key for the given component.
        #
        # Returns a String.
        def cache_key
          "meetings-calendar-component-#{component.id}-#{component.updated_at.to_i}"
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
decidim-meetings-0.19.0 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.17.2 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.18.0 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.17.1 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.16.1 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.17.0 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.16.0 app/services/decidim/meetings/calendar/component_calendar.rb