metal_archives 3.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +59 -12
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +34 -20
  5. data/CHANGELOG.md +4 -0
  6. data/LICENSE.md +17 -4
  7. data/README.md +29 -14
  8. data/bin/console +8 -11
  9. data/config/inflections.rb +7 -0
  10. data/config/initializers/.keep +0 -0
  11. data/docker-compose.yml +10 -1
  12. data/lib/metal_archives.rb +56 -22
  13. data/lib/metal_archives/cache/base.rb +40 -0
  14. data/lib/metal_archives/cache/memory.rb +68 -0
  15. data/lib/metal_archives/cache/null.rb +22 -0
  16. data/lib/metal_archives/cache/redis.rb +49 -0
  17. data/lib/metal_archives/collection.rb +3 -5
  18. data/lib/metal_archives/configuration.rb +28 -21
  19. data/lib/metal_archives/errors.rb +9 -1
  20. data/lib/metal_archives/http_client.rb +42 -46
  21. data/lib/metal_archives/models/artist.rb +55 -26
  22. data/lib/metal_archives/models/band.rb +43 -36
  23. data/lib/metal_archives/models/{base_model.rb → base.rb} +53 -53
  24. data/lib/metal_archives/models/label.rb +7 -8
  25. data/lib/metal_archives/models/release.rb +11 -17
  26. data/lib/metal_archives/parsers/artist.rb +40 -35
  27. data/lib/metal_archives/parsers/band.rb +73 -29
  28. data/lib/metal_archives/parsers/base.rb +14 -0
  29. data/lib/metal_archives/parsers/country.rb +21 -0
  30. data/lib/metal_archives/parsers/date.rb +31 -0
  31. data/lib/metal_archives/parsers/genre.rb +67 -0
  32. data/lib/metal_archives/parsers/label.rb +21 -13
  33. data/lib/metal_archives/parsers/parser.rb +15 -77
  34. data/lib/metal_archives/parsers/release.rb +22 -18
  35. data/lib/metal_archives/parsers/year.rb +29 -0
  36. data/lib/metal_archives/version.rb +3 -3
  37. data/metal_archives.env.example +7 -4
  38. data/metal_archives.gemspec +7 -4
  39. data/nginx/default.conf +2 -2
  40. metadata +76 -32
  41. data/.github/workflows/release.yml +0 -69
  42. data/.rubocop_todo.yml +0 -92
  43. data/lib/metal_archives/lru_cache.rb +0 -61
  44. data/lib/metal_archives/middleware/cache_check.rb +0 -18
  45. data/lib/metal_archives/middleware/encoding.rb +0 -16
  46. data/lib/metal_archives/middleware/headers.rb +0 -38
  47. data/lib/metal_archives/middleware/rewrite_endpoint.rb +0 -38
  48. data/lib/metal_archives/nil_date.rb +0 -91
  49. data/lib/metal_archives/range.rb +0 -69
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "faraday"
4
-
5
- module MetalArchives
6
- module Middleware
7
- ##
8
- # Log cache status
9
- #
10
- class CacheCheck < Faraday::Response::Middleware # :nodoc:
11
- def on_complete(env)
12
- return unless MetalArchives.config.endpoint
13
-
14
- MetalArchives.config.logger.info "Cache #{env[:response_headers]['x-cache-status'].downcase} for #{env.url}" if env[:response_headers].key? "x-cache-status"
15
- end
16
- end
17
- end
18
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "faraday"
4
-
5
- module MetalArchives
6
- module Middleware
7
- ##
8
- # Force UTF-8 conversion
9
- #
10
- class Encoding < Faraday::Response::Middleware # :nodoc:
11
- def on_complete(env)
12
- env.response.body.force_encoding("utf-8")
13
- end
14
- end
15
- end
16
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "faraday"
4
-
5
- module MetalArchives
6
- module Middleware
7
- ##
8
- # Add appropriate request headers
9
- #
10
- class Headers < Faraday::Middleware # :nodoc:
11
- def call(env)
12
- headers = {
13
- "User-Agent" => user_agent_string,
14
- "Via" => via_string,
15
- "Accept" => accept_string,
16
- }
17
-
18
- env[:request_headers].merge! headers
19
-
20
- @app.call env
21
- end
22
-
23
- private
24
-
25
- def user_agent_string
26
- "#{MetalArchives.config.app_name}/#{MetalArchives.config.app_version} ( #{MetalArchives.config.app_contact} )"
27
- end
28
-
29
- def accept_string
30
- "application/json"
31
- end
32
-
33
- def via_string
34
- "gem metal_archives/#{VERSION}"
35
- end
36
- end
37
- end
38
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "faraday"
4
-
5
- module MetalArchives
6
- module Middleware
7
- ##
8
- # Dynamically rewrite endpoints
9
- #
10
- class RewriteEndpoint < Faraday::Middleware
11
- def call(env)
12
- env[:url] = RewriteEndpoint.rewrite(env[:url])
13
-
14
- @app.call env
15
- end
16
-
17
- class << self
18
- def rewrite(uri)
19
- return uri unless MetalArchives.config.endpoint
20
-
21
- new_uri = uri.clone
22
-
23
- default_uri = URI MetalArchives.config.default_endpoint
24
- rewritten_uri = URI MetalArchives.config.endpoint
25
-
26
- if uri.host == default_uri.host && uri.scheme == default_uri.scheme
27
- new_uri.host = rewritten_uri.host
28
- new_uri.scheme = rewritten_uri.scheme
29
-
30
- MetalArchives.config.logger.debug "Rewrite #{uri} to #{new_uri}"
31
- end
32
-
33
- new_uri
34
- end
35
- end
36
- end
37
- end
38
- end
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "date"
4
-
5
- module MetalArchives
6
- ##
7
- # Date with nullable year, month and day
8
- #
9
- # WARNING: No validation on actual date is performed
10
- #
11
- class NilDate
12
- include Comparable
13
-
14
- attr_accessor :year, :month, :day
15
-
16
- def initialize(year = nil, month = nil, day = nil)
17
- @year = year
18
- @month = month
19
- @day = day
20
- end
21
-
22
- def year?
23
- !@year.nil?
24
- end
25
-
26
- def month?
27
- !@month.nil?
28
- end
29
-
30
- def day?
31
- !@day.nil?
32
- end
33
-
34
- ##
35
- # Return a +Date+ object
36
- #
37
- def date
38
- raise MetalArchives::Errors::ArgumentError, "Invalid conversion to Date: #{self}" unless year?
39
-
40
- ::Date.new @year, month || 1, day || 1
41
- end
42
-
43
- ##
44
- # Parse YYYY[-MM[-DD]]
45
- #
46
- def self.parse(value)
47
- split = value.split("-")
48
-
49
- year = Integer(split[0], 10) if split.any? && split[0] && !split[0].empty?
50
- year = nil if year == 0
51
-
52
- month = Integer(split[1], 10) if split.length > 1 && split[1] && !split[1].empty?
53
- month = nil if month == 0
54
-
55
- day = Integer(split[2], 10) if split.length > 2 && split[2] && !split[2].empty?
56
- day = nil if day == 0
57
-
58
- MetalArchives::NilDate.new year, month, day
59
- rescue StandardError => e
60
- raise MetalArchives::Errors::ArgumentError, "Invalid date: #{value}: #{e}"
61
- end
62
-
63
- ##
64
- # Comparison operator
65
- #
66
- def <=>(other)
67
- return nil if other.nil?
68
-
69
- # Return nil if one of the two years is nil
70
- return nil if (@year.nil? && !other.year.nil?) || (!@year.nil? && other.year.nil?)
71
-
72
- # Return nil if one of the two months is nil
73
- return nil if (@month.nil? && !other.month.nil?) || (!@month.nil? && other.month.nil?)
74
-
75
- # Return nil if one of the two months is nil
76
- return nil if (@day.nil? && !other.day.nil?) || (!@day.nil? && other.day.nil?)
77
-
78
- comp_year = @year <=> other.year
79
- if comp_year == 0
80
- comp_month = @month <=> other.month
81
- if comp_month == 0
82
- @day <=> other.day
83
- else
84
- comp_month
85
- end
86
- else
87
- comp_year
88
- end
89
- end
90
- end
91
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MetalArchives
4
- ##
5
- # Range which can start and/or end with +nil+
6
- #
7
- class Range
8
- include Comparable
9
-
10
- ##
11
- # Begin- and endpoint of range
12
- #
13
- attr_accessor :begin, :end
14
-
15
- ##
16
- # Create a new range
17
- #
18
- # [+_begin+]
19
- # Start of range
20
- #
21
- # Default: +nil+
22
- #
23
- # [+_end+]
24
- # End of range
25
- #
26
- # Default: +nil+
27
- #
28
- def initialize(_begin = nil, _end = nil)
29
- @begin = _begin
30
- @end = _end
31
- end
32
-
33
- ##
34
- # Whether start of range is present
35
- #
36
- def begin?
37
- !@begin.nil?
38
- end
39
-
40
- ##
41
- # Whether end of range is present
42
- #
43
- def end?
44
- !@end.nil?
45
- end
46
-
47
- ##
48
- # Comparison operator
49
- #
50
- def <=>(other)
51
- comp_begin = self.begin <=> other.begin
52
- comp_end = self.end <=> other.end
53
- # Return nil if begin or end is uncomparable
54
- return nil if comp_begin.nil? || comp_end.nil?
55
-
56
- # Compare end if begin is equal
57
- return comp_end if comp_begin.zero?
58
-
59
- # Compare begin if end is equal
60
- return comp_begin if comp_begin.zero?
61
-
62
- return nil unless self.begin.is_a?(Integer) && self.end.is_a?(Integer)
63
- return nil unless other.begin.is_a?(Integer) && other.end.is_a?(Integer)
64
-
65
- # Compare actual range
66
- (self.end - self.begin) <=> (other.end - other.begin)
67
- end
68
- end
69
- end