Class: ServerlessRedirector::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/serverless_redirector/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Controller

Returns a new instance of Controller.



18
19
20
21
22
23
24
25
# File 'lib/serverless_redirector/controller.rb', line 18

def initialize(options = {})
  @dry_run = false
  @log_path = nil
  @destination_uri = nil
  @manifest_path = nil
  @skip_deletes = false
  unpack_options options
end

Instance Attribute Details

#destination_uriObject

Configuration has some options:



12
13
14
# File 'lib/serverless_redirector/controller.rb', line 12

def destination_uri
  @destination_uri
end

#dry_runObject

Configuration has some options:



12
13
14
# File 'lib/serverless_redirector/controller.rb', line 12

def dry_run
  @dry_run
end

#log_pathObject

Configuration has some options:



12
13
14
# File 'lib/serverless_redirector/controller.rb', line 12

def log_path
  @log_path
end

#manifest_pathObject

Configuration has some options:



12
13
14
# File 'lib/serverless_redirector/controller.rb', line 12

def manifest_path
  @manifest_path
end

#skip_deletesObject

Configuration has some options:



12
13
14
# File 'lib/serverless_redirector/controller.rb', line 12

def skip_deletes
  @skip_deletes
end

Instance Method Details

#invoke!Object



42
43
44
45
46
47
48
49
# File 'lib/serverless_redirector/controller.rb', line 42

def invoke!
  logger = create_logger
  manifest = create_manifest
  destination = create_destination

  syncer = ServerlessRedirector::Syncer.new(manifest, destination, logger, skip_deletes)
  syncer.run dry_run
end

#unpack_options(options) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/serverless_redirector/controller.rb', line 27

def unpack_options(options)
  @dry_run = !!options[:dry_run] if options.key?(:dry_run)
  @skip_deletes = !!options[:skip_deletes] if options.key?(:skip_deletes)

  @manifest_path   = options.fetch(:manifest_path) if options.key?(:manifest_path)
  @log_path        = options.fetch(:log_path) if options.key?(:log_path)
  @destination_uri = options.fetch(:destination_uri) if options.key?(:destination_uri)
end

#validateObject

Raises:

  • (ArgumentError)


36
37
38
39
40
# File 'lib/serverless_redirector/controller.rb', line 36

def validate
  raise ArgumentError.new("Manifest path does not exist") unless manifest_path && ::File.exist?(manifest_path)
  raise ArgumentError.new("Destination URI Invalid") unless destination_uri && ::URI.parse(destination_uri).present? 
  # Otherwise fine here...
end