-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* develop: added simplecov refactoring
- Loading branch information
Showing
32 changed files
with
398 additions
and
343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,5 +55,6 @@ DEPENDENCIES | |
coveralls | ||
faraday (~> 0.9.2) | ||
rspec (~> 3.4.0) | ||
simplecov | ||
timecop | ||
webmock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
FileUtils.mkdir_p('log') unless Dir.exist?('log') | ||
|
||
logger = UrlInspectorLogger.new('log/main.log') | ||
logger.formatter = UrlInspectorLogger::CustomFormatter.new | ||
UrlInspector::Log.logger = Logger.new('log/main.log') |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require_relative 'url_inspector/file_parser' | ||
|
||
require_relative 'url_inspector/http_client' | ||
require_relative 'url_inspector/http_client/response' | ||
|
||
require_relative 'url_inspector/log' | ||
|
||
require_relative 'url_inspector/strategy' | ||
|
||
require_relative 'url_inspector/thread_strategy' | ||
require_relative 'url_inspector/thread_strategy/inspector' | ||
|
||
require_relative 'url_inspector/thread_pool_strategy' | ||
require_relative 'url_inspector/thread_pool_strategy/task_runner' | ||
require_relative 'url_inspector/thread_pool_strategy/inspect_task' | ||
|
||
module UrlInspector | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module UrlInspector | ||
class FileParser | ||
attr_reader :file_name | ||
|
||
def initialize(file_name) | ||
@file_name = file_name | ||
end | ||
|
||
def parse | ||
urls = [] | ||
|
||
File.readlines(file_name).each_with_index do |raw_line, index| | ||
url = raw_line.delete("\n") | ||
|
||
if valid_url?(url) | ||
urls << url | ||
else | ||
raise ArgumentError, "Please, check line##{index + 1} in your file" | ||
end | ||
end | ||
|
||
raise ArgumentError, "File doesn't have urls" if urls.empty? | ||
urls.uniq | ||
end | ||
|
||
private | ||
|
||
def valid_url?(url) | ||
uri = URI.parse(url) | ||
uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module UrlInspector | ||
class HttpClient | ||
class << self | ||
def get(url) | ||
connection = connection(url) | ||
response = connection.get | ||
HttpClient::Response.new(response.status) | ||
rescue Faraday::Error | ||
HttpClient::Response.new | ||
end | ||
|
||
private | ||
|
||
def connection(url) | ||
params = { | ||
open_timeout: 10, | ||
timeout: 10 | ||
} | ||
Faraday.new(url, request: params) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module UrlInspector | ||
class HttpClient | ||
class Response | ||
attr_reader :status | ||
|
||
def initialize(status = nil) | ||
@status = status | ||
end | ||
|
||
def success? | ||
return false if status.nil? | ||
status.between?(200, 209) || status.between?(300, 309) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module UrlInspector | ||
module Log | ||
class CustomFormatter < Logger::Formatter | ||
def call(severity, datetime, _progname, msg) | ||
formatted_datetime = datetime.strftime('%d.%m.%Y %H:%M:%S') | ||
thread_id = Thread.current.object_id | ||
"[#{formatted_datetime}] [#{thread_id}] [#{severity}] #{msg}\n" | ||
end | ||
end | ||
|
||
def log_success(url, interval) | ||
msg = log_msg(url, interval) | ||
logger.info(msg) | ||
end | ||
|
||
def log_error(url, interval) | ||
msg = log_msg(url, interval) | ||
logger.error(msg) | ||
end | ||
|
||
private | ||
|
||
def log_msg(url, interval) | ||
"url=#{url} next_interval=#{interval}" | ||
end | ||
|
||
def logger | ||
@logger ||= Log.logger | ||
end | ||
|
||
class << self | ||
attr_reader :logger | ||
|
||
def logger=(logger) | ||
@logger = logger | ||
@logger.formatter = CustomFormatter.new | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module UrlInspector | ||
class Strategy | ||
attr_reader :urls, :normal_interval, :emergency_interval | ||
|
||
def initialize(options = {}) | ||
@urls = options[:urls] | ||
@normal_interval = options[:normal_interval] | ||
@emergency_interval = options[:emergency_interval] | ||
end | ||
|
||
def perform | ||
end | ||
|
||
def shutdown | ||
end | ||
end | ||
end |
Oops, something went wrong.