Sha256: 9ae390f49fc113a24491a338a3ea072cc23521e83ec50fe14f258853a62606c4

Contents?: true

Size: 1.09 KB

Versions: 19

Compression:

Stored size: 1.09 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|
              MeetingCalendar.new(meeting).events
            end.compact.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

19 entries across 19 versions & 1 rubygems

Version Path
decidim-meetings-0.26.10 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.26.9 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.26.8 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.26.7 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.26.5 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.26.4 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.26.3 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.26.2 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.26.1 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.26.0 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.26.0.rc2 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.26.0.rc1 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.25.2 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.25.1 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.25.0 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.25.0.rc4 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.25.0.rc3 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.25.0.rc2 app/services/decidim/meetings/calendar/component_calendar.rb
decidim-meetings-0.25.0.rc1 app/services/decidim/meetings/calendar/component_calendar.rb