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

simukappu / activity_notification / 20600234446

30 Dec 2025 03:42PM UTC coverage: 99.749%. Remained the same
20600234446

push

travis-ci

simukappu
Bump version to v2.4.1

3575 of 3584 relevant lines covered (99.75%)

1533.49 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
15✔
2
  # Optional target module to develop optional notification target classes.
3
  module OptionalTarget
15✔
4
    # Abstract optional target class to develop optional notification target class.
5
    class Base
15✔
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 = {})
15✔
11
        initialize_target(options) unless options.delete(:skip_initializing_target)
855✔
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
15✔
17
        self.class.name.demodulize.underscore.to_sym
8,565✔
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 = {})
15✔
23
        raise NotImplementedError, "You have to implement #{self.class}##{__method__}"
15✔
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 = {})
15✔
30
        raise NotImplementedError, "You have to implement #{self.class}##{__method__}"
15✔
31
      end
32

33
      protected
15✔
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 = {})
15✔
47
          partial_root_list = 
48
            options[:partial_root].present? ?
2,130✔
49
            [ options[:partial_root] ] :
50
            [ "activity_notification/optional_targets/#{notification.target.to_resources_name}/#{to_optional_target_name}",
852✔
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,130✔
56

57
          message, missing_template = nil, nil
2,130✔
58
          partial_root_list.each do |partial_root|
2,130✔
59
            begin
60
              message = notification.render(
6,480✔
61
                ActivityNotification::NotificationsController.renderer,
62
                options.merge(
63
                  partial_root: partial_root,
64
                  assigns: (options[:assignment] || {}).merge(notification: notification, target: notification.target)
6,480✔
65
                )
66
              ).to_s
67
              break
2,070✔
68
            rescue ActionView::MissingTemplate => e
69
              missing_template = e
4,410✔
70
              # Continue to next partial root
71
            end
72
          end
73
          message.blank? ? (raise missing_template) : message
2,130✔
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