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.24.3 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.23.6 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.24.2 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.23.5 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.24.1 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.24.0 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.24.0.rc2 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.23.4 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.24.0.rc1 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.23.3 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.23.2 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.23.1 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.23.1.rc1 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.23.0 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.22.0 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.21.0 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.20.1 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.20.0 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.19.1 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.18.1 app/services/decidim/meetings/calendar/component_calendar.rb