Class: Scribo::SiteFindService

Inherits:
ApplicationService show all
Defined in:
app/services/scribo/site_find_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationService

#call

Constructor Details

#initialize(options = {}) ⇒ SiteFindService

Returns a new instance of SiteFindService.



9
10
11
12
# File 'app/services/scribo/site_find_service.rb', line 9

def initialize(options = {})
  super()
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'app/services/scribo/site_find_service.rb', line 7

def options
  @options
end

Instance Method Details

#performObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/scribo/site_find_service.rb', line 14

def perform
  return options[:site] if options[:site].is_a?(Scribo::Site)

  scribable = Scribo.config.scribable_for_request(options[:request])
  return nil unless scribable

  scope = scribable.sites
  scope = scope.for_host(options[:host])
  scope = scope.for_path(options[:path]) if options[:path]
  scope.first
end