metal_archives 2.2.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +93 -0
  3. data/.gitignore +6 -6
  4. data/.overcommit.yml +35 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +66 -6
  7. data/CHANGELOG.md +33 -0
  8. data/Gemfile +1 -1
  9. data/LICENSE.md +17 -4
  10. data/README.md +65 -86
  11. data/Rakefile +8 -7
  12. data/bin/console +38 -0
  13. data/bin/setup +8 -0
  14. data/config/inflections.rb +7 -0
  15. data/config/initializers/.keep +0 -0
  16. data/docker-compose.yml +23 -0
  17. data/lib/metal_archives.rb +82 -27
  18. data/lib/metal_archives/cache/base.rb +40 -0
  19. data/lib/metal_archives/cache/memory.rb +68 -0
  20. data/lib/metal_archives/cache/null.rb +22 -0
  21. data/lib/metal_archives/cache/redis.rb +49 -0
  22. data/lib/metal_archives/{utils/collection.rb → collection.rb} +3 -5
  23. data/lib/metal_archives/configuration.rb +33 -50
  24. data/lib/metal_archives/{error.rb → errors.rb} +9 -1
  25. data/lib/metal_archives/http_client.rb +45 -44
  26. data/lib/metal_archives/models/artist.rb +90 -45
  27. data/lib/metal_archives/models/band.rb +77 -52
  28. data/lib/metal_archives/models/base.rb +225 -0
  29. data/lib/metal_archives/models/label.rb +14 -15
  30. data/lib/metal_archives/models/release.rb +25 -29
  31. data/lib/metal_archives/parsers/artist.rb +86 -50
  32. data/lib/metal_archives/parsers/band.rb +155 -88
  33. data/lib/metal_archives/parsers/base.rb +14 -0
  34. data/lib/metal_archives/parsers/country.rb +21 -0
  35. data/lib/metal_archives/parsers/date.rb +31 -0
  36. data/lib/metal_archives/parsers/genre.rb +67 -0
  37. data/lib/metal_archives/parsers/label.rb +39 -31
  38. data/lib/metal_archives/parsers/parser.rb +18 -63
  39. data/lib/metal_archives/parsers/release.rb +98 -89
  40. data/lib/metal_archives/parsers/year.rb +31 -0
  41. data/lib/metal_archives/version.rb +12 -1
  42. data/metal_archives.env.example +10 -0
  43. data/metal_archives.gemspec +43 -28
  44. data/nginx/default.conf +60 -0
  45. metadata +179 -74
  46. data/.travis.yml +0 -12
  47. data/lib/metal_archives/middleware/cache_check.rb +0 -20
  48. data/lib/metal_archives/middleware/encoding.rb +0 -16
  49. data/lib/metal_archives/middleware/headers.rb +0 -38
  50. data/lib/metal_archives/middleware/rewrite_endpoint.rb +0 -38
  51. data/lib/metal_archives/models/base_model.rb +0 -215
  52. data/lib/metal_archives/utils/lru_cache.rb +0 -61
  53. data/lib/metal_archives/utils/nil_date.rb +0 -99
  54. data/lib/metal_archives/utils/range.rb +0 -66
  55. data/spec/configuration_spec.rb +0 -96
  56. data/spec/factories/artist_factory.rb +0 -37
  57. data/spec/factories/band_factory.rb +0 -60
  58. data/spec/factories/nil_date_factory.rb +0 -9
  59. data/spec/factories/range_factory.rb +0 -8
  60. data/spec/models/artist_spec.rb +0 -138
  61. data/spec/models/band_spec.rb +0 -164
  62. data/spec/models/base_model_spec.rb +0 -219
  63. data/spec/models/release_spec.rb +0 -133
  64. data/spec/parser_spec.rb +0 -19
  65. data/spec/spec_helper.rb +0 -111
  66. data/spec/support/factory_girl.rb +0 -5
  67. data/spec/support/metal_archives.rb +0 -33
  68. data/spec/utils/collection_spec.rb +0 -72
  69. data/spec/utils/lru_cache_spec.rb +0 -53
  70. data/spec/utils/nil_date_spec.rb +0 -156
  71. data/spec/utils/range_spec.rb +0 -62
@@ -1,219 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
-
4
- ##
5
- # Sample model without :id property or :assemble method
6
- #
7
- class ModelOne < MetalArchives::BaseModel
8
- property :property_one
9
- end
10
-
11
- ##
12
- # Sample model without :assemble method
13
- #
14
- class ModelTwo < MetalArchives::BaseModel
15
- property :id
16
- property :property_one
17
- end
18
-
19
- ##
20
- # Sample complete model
21
- #
22
- class ModelThree < MetalArchives::BaseModel
23
- property :id
24
- property :property_one
25
-
26
- def assemble
27
- { :property_one => 'Property One' }
28
- end
29
- end
30
-
31
- ##
32
- # Sample complete model
33
- #
34
- class ModelFour < MetalArchives::BaseModel
35
- property :id
36
- property :property_one
37
-
38
- def assemble
39
- { :property_one => 'Property One' }
40
- end
41
- end
42
-
43
- ##
44
- # Sample invalid model
45
- #
46
- class ModelFive < MetalArchives::BaseModel
47
- property :id
48
- property :property_one
49
-
50
- def assemble
51
- raise MetalArchives::Errors::APIError
52
- end
53
- end
54
-
55
- RSpec.describe MetalArchives::BaseModel do
56
- it 'requires an :id property' do
57
- expect(-> { ModelOne.new(:property_one => 'foo') }).to raise_error MetalArchives::Errors::NotImplementedError
58
- end
59
-
60
- it 'requires an :assemble method' do
61
- expect(-> { ModelTwo.new(:id => 'foo').property_one }).to raise_error MetalArchives::Errors::NotImplementedError
62
- end
63
-
64
- it 'defines methods' do
65
- model = ModelTwo.new :id => 'foo'
66
-
67
- expect(model).to respond_to :id
68
- expect(model).to respond_to :id=
69
- expect(model).to respond_to :id?
70
- expect(model).to respond_to :property_one
71
- expect(model).to respond_to :property_one=
72
- expect(model).to respond_to :property_one?
73
- expect(model).not_to respond_to :property_two
74
- expect(model).not_to respond_to :property_two=
75
- expect(model).not_to respond_to :property_two?
76
- end
77
-
78
- it 'returns properties' do
79
- model = ModelThree.new :id => 'foo', :property_one => 'bar'
80
-
81
- model.instance_eval { |m| @loaded = true }
82
- expect(model.id).to eq 'foo'
83
- expect(model.property_one).to eq 'bar'
84
- end
85
-
86
- it 'sets properties' do
87
- model = ModelThree.new :id => 'foo', :property_one => 'bar'
88
-
89
- model.instance_eval { |m| @loaded = true }
90
- model.id = 'baz'
91
- model.property_one = 'bat'
92
-
93
- expect(model.id).to eq 'baz'
94
- expect(model.property_one).to eq 'bat'
95
- end
96
-
97
- it 'checks properties' do
98
- model = ModelThree.new :id => 'foo', :property_one => 'bar'
99
- model2 = ModelThree.new :id => 'foo'
100
- model2.load!
101
- model2.property_one = nil
102
-
103
- expect(model.id?).to be true
104
- expect(model.property_one?).to be true
105
-
106
- expect(model2.id?).to be true
107
- expect(model2.property_one?).to be false
108
- end
109
-
110
- it 'calls assemble' do
111
- model = ModelThree.new :id => 'foo'
112
-
113
- expect(model.id).to eq 'foo'
114
- expect(model.property_one).to eq 'Property One'
115
- end
116
-
117
- it 'lazily loads' do
118
- model = ModelThree.new :id => 'foo'
119
-
120
- expect(model).to be_instance_variable_defined '@id'
121
- expect(model).not_to be_instance_variable_defined '@property_one'
122
-
123
- model.property_one
124
-
125
- expect(model).to be_instance_variable_defined '@id'
126
- expect(model).to be_instance_variable_defined '@property_one'
127
- expect(model.property_one).to eq 'Property One'
128
- end
129
-
130
-
131
- it 'implements the load! operation' do
132
- model = ModelThree.new :id => 'foo'
133
-
134
- expect(model).to be_instance_variable_defined '@id'
135
- expect(model).not_to be_instance_variable_defined '@property_one'
136
-
137
- model.load!
138
-
139
- expect(model).to be_instance_variable_defined '@id'
140
- expect(model).to be_instance_variable_defined '@property_one'
141
- expect(model.property_one).to eq 'Property One'
142
- end
143
-
144
- it 'implements the equal operator' do
145
- m1 = ModelThree.new :id => 'id_one'
146
- m2 = ModelThree.new :id => 'id_one'
147
- m3 = ModelThree.new :id => 'id_two'
148
- m4 = ModelFour.new :id => 'id_one'
149
-
150
- expect(m1).to eq m2
151
- expect(m2).not_to eq m3
152
- expect(m1).not_to eq m3
153
- expect(m1).not_to eq m4
154
- expect(m2).not_to eq m4
155
- end
156
-
157
- describe 'loaded?' do
158
- it 'has a :loaded? method' do
159
- expect(ModelThree.new).to respond_to :loaded?
160
- end
161
-
162
- it 'returns false on lazy load' do
163
- m = ModelThree.new :id => 'id_one'
164
-
165
- expect(m).not_to be_loaded
166
- end
167
-
168
- it 'returns true on load!' do
169
- m = ModelThree.new :id => 'id_one'
170
- m.load!
171
-
172
- expect(m).to be_loaded
173
- end
174
- end
175
-
176
- describe 'cached?' do
177
- context 'valid model' do
178
- it 'has a :cached? method' do
179
- expect(ModelThree.new).to respond_to :cached?
180
- end
181
-
182
- it "doesn't cache lazily loaded objects" do
183
- m = ModelThree.new :id => 'id_one'
184
-
185
- expect(m).not_to be_loaded
186
- expect(m).not_to be_cached
187
- end
188
-
189
- it 'caches loaded objects' do
190
- m = ModelThree.new :id => 'id_one'
191
- m.load!
192
-
193
- expect(m).to be_loaded
194
- expect(m).to be_cached
195
- end
196
- end
197
-
198
- context 'invalid model' do
199
- it 'has a :cached? method' do
200
- expect(ModelFive.new).to respond_to :cached?
201
- end
202
-
203
- it "doesn't cache lazily loaded objects" do
204
- m = ModelFive.new :id => 'id_one'
205
-
206
- expect(m).not_to be_loaded
207
- expect(m).not_to be_cached
208
- end
209
-
210
- it "doesn't cache loaded invalid objects" do
211
- m = ModelFive.new :id => 'id_one'
212
- expect(-> { m.load! }).to raise_error MetalArchives::Errors::APIError
213
-
214
- expect(m).not_to be_loaded
215
- expect(m).not_to be_cached
216
- end
217
- end
218
- end
219
- end
@@ -1,133 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe MetalArchives::Release do
4
- describe 'properties' do
5
- it 'Tales of Ancient Prophecies has properties' do
6
- release = MetalArchives::Release.find 416934
7
-
8
- expect(release).to be_instance_of MetalArchives::Release
9
- expect(release.id).to eq 416934
10
- expect(release.title).to eq 'Tales of Ancient Prophecies'
11
- expect(release.type).to eq :full_length
12
- expect(release.date_released).to eq MetalArchives::NilDate.new(2014, 6, 4)
13
- expect(release.catalog_id).to eq 'BLOD091CD'
14
- expect(release.version_description).to be_nil
15
- expect(release.format).to eq :cd
16
- expect(release.limitation).to be_nil
17
- expect(release.notes).to be_nil
18
- end
19
-
20
- it '...And Oceans has properties' do
21
- release = MetalArchives::Release.find 123563
22
-
23
- expect(release).to be_instance_of MetalArchives::Release
24
- expect(release.id).to eq 123563
25
- expect(release.title).to eq '...and Oceans'
26
- expect(release.type).to eq :compilation
27
- expect(release.date_released).to eq MetalArchives::NilDate.new(2000)
28
- expect(release.catalog_id).to eq 'NMLP 025'
29
- expect(release.version_description).to be_nil
30
- expect(release.format).to eq :vinyl
31
- expect(release.limitation).to be_nil
32
- expect(release.notes).to be_nil
33
- end
34
-
35
- it 'uses NilDate' do
36
- release = MetalArchives::Release.find 123563
37
-
38
- expect(release.title).to eq '...and Oceans'
39
- expect(release.date_released).to be_instance_of MetalArchives::NilDate
40
- expect(release.date_released).to eq MetalArchives::NilDate.new(2000, nil, nil)
41
- end
42
- end
43
-
44
- describe 'methods' do
45
- describe 'find' do
46
- it 'finds a release' do
47
- release = MetalArchives::Release.find 416934
48
-
49
- expect(release).not_to be_nil
50
- expect(release).to be_instance_of MetalArchives::Release
51
- expect(release.id).to eq 416934
52
- expect(release.title).to eq 'Tales of Ancient Prophecies'
53
- end
54
-
55
- it 'lazily loads' do
56
- release = MetalArchives::Release.find -1
57
-
58
- expect(release).to be_instance_of MetalArchives::Release
59
- end
60
- end
61
-
62
- describe 'find!' do
63
- it 'finds a release' do
64
- release = MetalArchives::Release.find! 416934
65
-
66
- expect(release).to be_instance_of MetalArchives::Release
67
- expect(release.title).to eq 'Tales of Ancient Prophecies'
68
- end
69
-
70
- it 'raises on invalid id' do
71
- expect(-> { MetalArchives::Release.find! -1 }).to raise_error MetalArchives::Errors::APIError
72
- expect(-> { MetalArchives::Release.find! 0 }).to raise_error MetalArchives::Errors::InvalidIDError
73
- expect(-> { MetalArchives::Release.find! nil }).to raise_error MetalArchives::Errors::InvalidIDError
74
- end
75
- end
76
-
77
- describe 'find_by' do
78
- it 'finds a release by title' do
79
- release = MetalArchives::Release.find_by :title => 'Tales of Ancient Prophecies'
80
-
81
- expect(release).to be_instance_of MetalArchives::Release
82
- expect(release.id).to eq 416934
83
- end
84
-
85
- it 'returns nil on invalid id' do
86
- release = MetalArchives::Release.find_by :title => 'SomeNonExistantName'
87
-
88
- expect(release).to be_nil
89
- end
90
- end
91
-
92
- describe 'find_by!' do
93
- it 'finds a release' do
94
- release = MetalArchives::Release.find_by! :title => 'Tales of Ancient Prophecies'
95
-
96
- expect(release).to be_instance_of MetalArchives::Release
97
- expect(release.id).to eq 416934
98
- end
99
-
100
- it 'returns nil on invalid id' do
101
- release = MetalArchives::Release.find_by! :title => 'SomeNonExistantName'
102
-
103
- expect(release).to be_nil
104
- end
105
- end
106
-
107
- describe 'search' do
108
- it 'returns a collection' do
109
- collection = MetalArchives::Release.search 'Rhapsody'
110
-
111
- expect(collection).to be_instance_of MetalArchives::Collection
112
- expect(collection.first).to be_instance_of MetalArchives::Release
113
- end
114
-
115
- it 'returns an empty collection' do
116
- expect(MetalArchives::Release.search 'SomeNoneExistantName').to be_empty
117
- end
118
-
119
- it 'searches by title' do
120
- expect(MetalArchives::Release.search_by(:title => 'Rhapsody').count).to eq 13
121
- # expect(MetalArchives::Release.search_by(:title => 'Lost Horizon').count).to eq 3
122
- # expect(MetalArchives::Release.search_by(:title => 'Lost Horizon', :exact => true).count).to eq 2
123
- # expect(MetalArchives::Release.search_by(:title => 'Alquimia', :genre => 'Melodic Power').count).to eq 2
124
- end
125
- end
126
-
127
- describe 'all' do
128
- it 'returns a collection' do
129
- expect(MetalArchives::Release.all).to be_instance_of MetalArchives::Collection
130
- end
131
- end
132
- end
133
- end
data/spec/parser_spec.rb DELETED
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe MetalArchives::Parsers::Parser do
4
- it 'parses countries' do
5
- expect(described_class.parse_country('United States')).to eq ISO3166::Country['US']
6
- expect(described_class.parse_country('Germany')).to eq ISO3166::Country['DE']
7
- expect(described_class.parse_country('Belgium')).to eq ISO3166::Country['BE']
8
- end
9
-
10
- it 'parses genres' do
11
- expect(described_class.parse_genre('Death, Power, Black')).to match_array ['Black', 'Death', 'Power']
12
- expect(described_class.parse_genre('Death, Power, Black')).to match_array ['Black', 'Death', 'Power']
13
- expect(described_class.parse_genre('Death (early), Heavy/Power Metal, Black (later)')).to match_array ['Black', 'Death', 'Heavy', 'Power']
14
- expect(described_class.parse_genre(' Death , Power Metal, Power, Power')).to match_array ['Death', 'Power']
15
- expect(described_class.parse_genre('Heavy/Speed Power Metal')).to match_array ['Heavy Power', 'Speed Power']
16
- expect(described_class.parse_genre('Traditional Heavy/Power Metal')).to match_array ['Traditional Heavy', 'Traditional Power']
17
- expect(described_class.parse_genre('Traditional/Classical Heavy/Power Metal')).to match_array ['Traditional Heavy', 'Traditional Power', 'Classical Heavy', 'Classical Power']
18
- end
19
- end
data/spec/spec_helper.rb DELETED
@@ -1,111 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # This file was generated by the `rspec --init` command. Conventionally, all
4
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
- # The generated `.rspec` file contains `--require spec_helper` which will cause
6
- # this file to always be loaded, without a need to explicitly require it in any
7
- # files.
8
- #
9
- # Given that it is always loaded, you are encouraged to keep this file as
10
- # light-weight as possible. Requiring heavyweight dependencies from this file
11
- # will add to the boot time of your test suite on EVERY test run, even for an
12
- # individual file that may not need all of that loaded. Instead, consider making
13
- # a separate helper file that requires the additional dependencies and performs
14
- # the additional setup, and require it from the spec files that actually need
15
- # it.
16
- #
17
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18
-
19
- require 'factory_girl'
20
- require 'faker'
21
- require 'coveralls'
22
- Coveralls.wear!
23
-
24
- require 'metal_archives'
25
-
26
- Dir[File.join(__dir__, 'support/**/*.rb')].each { |f| require f }
27
- Dir[File.join(__dir__, 'factories/**/*.rb')].each { |f| require f }
28
-
29
- RSpec.configure do |config|
30
- # rspec-expectations config goes here. You can use an alternate
31
- # assertion/expectation library such as wrong or the stdlib/minitest
32
- # assertions if you prefer.
33
- config.expect_with :rspec do |expectations|
34
- # This option will default to `true` in RSpec 4. It makes the `description`
35
- # and `failure_message` of custom matchers include text for helper methods
36
- # defined using `chain`, e.g.:
37
- # be_bigger_than(2).and_smaller_than(4).description
38
- # # => "be bigger than 2 and smaller than 4"
39
- # ...rather than:
40
- # # => "be bigger than 2"
41
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
42
- end
43
-
44
- # rspec-mocks config goes here. You can use an alternate test double
45
- # library (such as bogus or mocha) by changing the `mock_with` option here.
46
- config.mock_with :rspec do |mocks|
47
- # Prevents you from mocking or stubbing a method that does not exist on
48
- # a real object. This is generally recommended, and will default to
49
- # `true` in RSpec 4.
50
- mocks.verify_partial_doubles = true
51
- end
52
-
53
- # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
54
- # have no way to turn it off -- the option exists only for backwards
55
- # compatibility in RSpec 3). It causes shared context metadata to be
56
- # inherited by the metadata hash of host groups and examples, rather than
57
- # triggering implicit auto-inclusion in groups with matching metadata.
58
- config.shared_context_metadata_behavior = :apply_to_host_groups
59
-
60
- # The settings below are suggested to provide a good initial experience
61
- # with RSpec, but feel free to customize to your heart's content.
62
- # # This allows you to limit a spec run to individual examples or groups
63
- # # you care about by tagging them with `:focus` metadata. When nothing
64
- # # is tagged with `:focus`, all examples get run. RSpec also provides
65
- # # aliases for `it`, `describe`, and `context` that include `:focus`
66
- # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
67
- # config.filter_run_when_matching :focus
68
- #
69
- # # Allows RSpec to persist some state between runs in order to support
70
- # # the `--only-failures` and `--next-failure` CLI options. We recommend
71
- # # you configure your source control system to ignore this file.
72
- # config.example_status_persistence_file_path = "spec/examples.txt"
73
- #
74
- # # Limits the available syntax to the non-monkey patched syntax that is
75
- # # recommended. For more details, see:
76
- # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
77
- # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
78
- # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
79
- # config.disable_monkey_patching!
80
- #
81
- # # This setting enables warnings. It's recommended, but in some cases may
82
- # # be too noisy due to issues in dependencies.
83
- # config.warnings = true
84
- #
85
- # # Many RSpec users commonly either run the entire suite or an individual
86
- # # file, and it's useful to allow more verbose output when running an
87
- # # individual spec file.
88
- # if config.files_to_run.one?
89
- # # Use the documentation formatter for detailed output,
90
- # # unless a formatter has already been configured
91
- # # (e.g. via a command-line flag).
92
- # config.default_formatter = "doc"
93
- # end
94
- #
95
- # # Print the 10 slowest examples and example groups at the
96
- # # end of the spec run, to help surface which specs are running
97
- # # particularly slow.
98
- # config.profile_examples = 10
99
- #
100
- # # Run specs in random order to surface order dependencies. If you find an
101
- # # order dependency and want to debug it, you can fix the order by providing
102
- # # the seed, which is printed after each run.
103
- # # --seed 1234
104
- # config.order = :random
105
- #
106
- # # Seed global randomization in this process using the `--seed` CLI option.
107
- # # Setting this allows you to use `--seed` to deterministically reproduce
108
- # # test failures related to randomization by passing the same `--seed` value
109
- # # as the one that triggered the failure.
110
- # Kernel.srand config.seed
111
- end