• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

simukappu / activity_notification / 20661354035

02 Jan 2026 03:51PM UTC coverage: 99.759%. Remained the same
20661354035

push

travis-ci

simukappu
[WIP] Allow use with Rails 8.1

3727 of 3736 relevant lines covered (99.76%)

1706.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/lib/activity_notification/optional_targets/base.rb
1
module ActivityNotification
17✔
2
  # Optional target module to develop optional notification target classes.
3
  module OptionalTarget
17✔
4
    # Abstract optional target class to develop optional notification target class.
5
    class Base
17✔
6
      # Initialize method to create view context in this OptionalTarget instance
7
      # @param [Hash] options Options for initializing target
8
      # @option options [Boolean] :skip_initializing_target (false) Whether skip calling initialize_target method
9
      # @option options [Hash]    others                            Options for initializing target
10
      def initialize(options = {})
17✔
11
        initialize_target(options) unless options.delete(:skip_initializing_target)
969✔
12
      end
13

14
      # Returns demodulized symbol class name as optional target name
15
      # @return Demodulized symbol class name as optional target name
16
      def to_optional_target_name
17✔
17
        self.class.name.demodulize.underscore.to_sym
9,707✔
18
      end
19

20
      # Initialize method to be overridden in user implementation class
21
      # @param [Hash] _options Options for initializing
22
      def initialize_target(_options = {})
17✔
23
        raise NotImplementedError, "You have to implement #{self.class}##{__method__}"
17✔
24
      end
25

26
      # Publishing notification method to be overridden in user implementation class
27
      # @param [Notification] _notification Notification instance
28
      # @param [Hash] _options Options for publishing
29
      def notify(_notification, _options = {})
17✔
30
        raise NotImplementedError, "You have to implement #{self.class}##{__method__}"
17✔
31
      end
32

33
      protected
17✔
34

35
        # Renders notification message with view context
36
        # @param [Notification] notification Notification instance
37
        # @param [Hash]         options      Options for rendering
38
        # @option options [Hash]           :assignment   (nil)                     Optional instance variables to assign for views
39
        # @option options [String]         :partial_root ("activity_notification/optional_targets/#{target}/#{optional_target_name}", "activity_notification/optional_targets/#{target}/base", "activity_notification/optional_targets/default/#{optional_target_name}", "activity_notification/optional_targets/default/base") Partial template name
40
        # @option options [String]         :partial      (self.key.tr('.', '/'))   Root path of partial template
41
        # @option options [String]         :layout       (nil)                     Layout template name
42
        # @option options [String]         :layout_root  ('layouts')               Root path of layout template
43
        # @option options [String, Symbol] :fallback     (:default)                Fallback template to use when MissingTemplate is raised. Set :text to use i18n text as fallback.
44
        # @option options [Hash]           others                                  Parameters to be set as locals
45
        # @return [String] Rendered view or text as string
46
        def render_notification_message(notification, options = {})
17✔
47
          partial_root_list = 
48
            options[:partial_root].present? ?
2,414✔
49
            [ options[:partial_root] ] :
50
            [ "activity_notification/optional_targets/#{notification.target.to_resources_name}/#{to_optional_target_name}",
1,136✔
51
              "activity_notification/optional_targets/#{notification.target.to_resources_name}/base",
52
              "activity_notification/optional_targets/default/#{to_optional_target_name}",
53
              "activity_notification/optional_targets/default/base"
54
            ]
55
          options[:fallback] ||= :default
2,414✔
56

57
          message, missing_template = nil, nil
2,414✔
58
          partial_root_list.each do |partial_root|
2,414✔
59
            begin
60
              message = notification.render(
7,344✔
61
                ActivityNotification::NotificationsController.renderer,
62
                options.merge(
63
                  partial_root: partial_root,
64
                  assigns: (options[:assignment] || {}).merge(notification: notification, target: notification.target)
7,344✔
65
                )
66
              ).to_s
67
              break
2,346✔
68
            rescue ActionView::MissingTemplate => e
69
              missing_template = e
4,998✔
70
              # Continue to next partial root
71
            end
72
          end
73
          message.blank? ? (raise missing_template) : message
2,414✔
74
        end
75
    end
76
  end
77
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc