Class: Neetob::CLI::Redirections::Check

Inherits:
Base
  • Object
show all
Defined in:
lib/neetob/cli/redirections/check.rb

Constant Summary

Constants inherited from Base

Base::NEETO_APPS_LIST_LINK

Instance Attribute Summary collapse

Attributes inherited from Base

#ui

Instance Method Summary collapse

Methods included from Utils

#camel_case_to_slug, #is_upper?, #symbolize_keys

Constructor Details

#initialize(source, destination, sandbox = false) ⇒ Check

Returns a new instance of Check.



9
10
11
12
13
14
# File 'lib/neetob/cli/redirections/check.rb', line 9

def initialize(source, destination, sandbox = false)
  super()
  @source = source
  @destination = destination
  @sandbox = sandbox
end

Instance Attribute Details

#destinationObject

Returns the value of attribute destination.



7
8
9
# File 'lib/neetob/cli/redirections/check.rb', line 7

def destination
  @destination
end

#sandboxObject

Returns the value of attribute sandbox.



7
8
9
# File 'lib/neetob/cli/redirections/check.rb', line 7

def sandbox
  @sandbox
end

#sourceObject

Returns the value of attribute source.



7
8
9
# File 'lib/neetob/cli/redirections/check.rb', line 7

def source
  @source
end

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/neetob/cli/redirections/check.rb', line 16

def run
  source_url = URI.parse(source)
  destination_url = URI.parse(destination)

  response = Net::HTTP.get_response(source_url)

  if response.code.in? %w(301 302 308)
    if response["location"].chomp("/") == destination.chomp("/")
      ui.success(
        "The redirection from #{source} to #{destination} is working properly.",
        print_to_audit_log: false)
    else
      ui.error(
        "The redirection from #{source} to #{destination} is not working properly.",
        print_to_audit_log: false)
    end
  else
    ui.error(
      "The redirection from #{source} to #{destination} is not working properly.",
      print_to_audit_log: false)
  end

  if Thread.current[:audit_mode]
    response.code.in?(%w(301 302 308)) && (response["location"].chomp("/") == destination.chomp("/"))
  end
end