Class: XxxRename::SiteClientMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/xxx_rename/site_client_matcher.rb

Defined Under Namespace

Classes: MatchResponse

Instance Method Summary collapse

Constructor Details

#initialize(config, override_site: nil) ⇒ SiteClientMatcher

Returns a new instance of SiteClientMatcher.

Parameters:



13
14
15
16
# File 'lib/xxx_rename/site_client_matcher.rb', line 13

def initialize(config, override_site: nil)
  @config = config
  @override_site = override_site
end

Instance Method Details

#disable_site(client) ⇒ Set[String]

Disable a site client permanently for the duration of the program runtime. This is helpful when we are rate limited, or fail auth for sites that require one, and protects the app from calling the API unnecessarily. Once a site is disabled, the matcher will never return the site client even after a successful match

Parameters:

Returns:

  • (Set[String])


40
41
42
43
44
# File 'lib/xxx_rename/site_client_matcher.rb', line 40

def disable_site(client)
  site_client_sym = client.class.site_client_name
  site_clients[site_client_sym] = nil
  disabled_sites.add(site_client_sym)
end

#fetch(key) ⇒ Object



26
27
28
# File 'lib/xxx_rename/site_client_matcher.rb', line 26

def fetch(key)
  site_clients.fetch(key.to_sym, nil)
end

#initialise_site_client(site) ⇒ XxxRename::SiteClients::Base

Initialise a site client and store it in memory Consecutive calls to this method with the same site client name will not cause it to reinitialise the site client. This can provide performance benefits if the site client needs to do some work during initialisation, e.g. login, fetch tokens, etc

Usually, you won’t need to call this method manually, as the matcher will do it for you. But it can be used by certain functions like ActorsHelper.

Parameters:

  • site (Symbol)

Returns:



64
65
66
67
68
69
70
71
72
73
# File 'lib/xxx_rename/site_client_matcher.rb', line 64

def initialise_site_client(site)
  return site_clients[site] if site_clients.key?(site) && !site_clients[site].nil?

  if disabled_sites.member?(site)
    XxxRename.logger.debug "#{site} is disabled"
    return nil
  end

  site_clients[site] = generate_class(site)
end

#match(file) ⇒ Array[MatchResponse]

Parameters:

  • file (String)

Returns:



20
21
22
23
24
# File 'lib/xxx_rename/site_client_matcher.rb', line 20

def match(file)
  @match_response = []
  find_matches(file)
  @match_response
end

#site_disabled?(site) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/xxx_rename/site_client_matcher.rb', line 46

def site_disabled?(site)
  disabled_sites.member?(site)
end