Class: Checkoff::Internal::AsanaEventFilter

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/checkoff/internal/asana_event_filter.rb

Overview

Uses an enhanced version of Asana event filter configuration

See developers.asana.com/reference/createwebhook | body params | data | filters | add object for a general description of the scheme.

Additional supported filter keys:

  • ‘checkoff:parent.gid’ - requires that the ‘gid’ key in the ‘parent’ object match the given value

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #finer, #info, #logger, #warn

Constructor Details

#initialize(filters:, clients: Checkoff::Clients.new, tasks: Checkoff::Tasks.new, client: clients.client) ⇒ AsanaEventFilter

Returns a new instance of AsanaEventFilter.

Parameters:

  • filters (Array<Hash>, nil)

    The filters to match against

  • clients (Checkoff::Clients) (defaults to: Checkoff::Clients.new)
  • tasks (Checkoff::Tasks) (defaults to: Checkoff::Tasks.new)
  • client (Asana::Client) (defaults to: clients.client)


24
25
26
27
28
29
30
31
# File 'lib/checkoff/internal/asana_event_filter.rb', line 24

def initialize(filters:,
               clients: Checkoff::Clients.new,
               tasks: Checkoff::Tasks.new,
               client: clients.client)
  @filters = filters
  @client = client
  @tasks = tasks
end

Instance Method Details

#matches?(asana_event) ⇒ Boolean

Parameters:

  • asana_event (Hash)

    The event that Asana sent

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/checkoff/internal/asana_event_filter.rb', line 34

def matches?(asana_event)
  logger.debug { "Filtering using #{@filters.inspect}" }
  return true if @filters.nil?

  failures = []

  @filters.any? do |filter|
    filter_matches = filter_matches_asana_event?(filter, asana_event, failures)
    logger.debug { "Filter #{filter.inspect} matched? #{filter_matches} against event #{asana_event.inspect}" }
    unless filter_matches
      logger.debug do
        "Filter #{filter.inspect} failed to match event #{asana_event.inspect} because of #{failures.inspect}"
      end
      failures << filter
    end
    filter_matches
  end
end