diff --git a/app/admin/book.rb b/app/admin/book.rb index a780c59..d9f9ef4 100644 --- a/app/admin/book.rb +++ b/app/admin/book.rb @@ -43,7 +43,7 @@ def scoped_collection FIO_FIELDS = %i[first_name last_name middle_name] member_action :download, method: :post do - info = Books::Extract.call(id: params[:id]) + info = Books::ExtractService.call(id: params[:id]) send_file info[:tempfile], type: 'application/octet-stream', filename: info[:filename] end diff --git a/app/services/authors/counter_cache.rb b/app/contexts/authors/counter_cache_command.rb similarity index 92% rename from app/services/authors/counter_cache.rb rename to app/contexts/authors/counter_cache_command.rb index 775662a..5db55d8 100644 --- a/app/services/authors/counter_cache.rb +++ b/app/contexts/authors/counter_cache_command.rb @@ -1,4 +1,4 @@ -class Authors::CounterCache +class Authors::CounterCacheCommand include Callable QUERY = <<~SQL diff --git a/app/services/authors/parse.rb b/app/contexts/authors/parse_service.rb similarity index 96% rename from app/services/authors/parse.rb rename to app/contexts/authors/parse_service.rb index 59f5793..bd7a015 100644 --- a/app/services/authors/parse.rb +++ b/app/contexts/authors/parse_service.rb @@ -1,4 +1,4 @@ -class Authors::Parse +class Authors::ParseService include Callable extend Dry::Initializer diff --git a/app/services/books/extract.rb b/app/contexts/books/extract_service.rb similarity index 96% rename from app/services/books/extract.rb rename to app/contexts/books/extract_service.rb index 931db6d..a8fb265 100644 --- a/app/services/books/extract.rb +++ b/app/contexts/books/extract_service.rb @@ -1,4 +1,4 @@ -class Books::Extract +class Books::ExtractService include Callable extend Dry::Initializer diff --git a/app/services/books/links.rb b/app/contexts/books/links_service.rb similarity index 98% rename from app/services/books/links.rb rename to app/contexts/books/links_service.rb index df7aed4..8217b65 100644 --- a/app/services/books/links.rb +++ b/app/contexts/books/links_service.rb @@ -1,4 +1,4 @@ -class Books::Links +class Books::LinksService include Callable extend Dry::Initializer diff --git a/app/services/books/parse.rb b/app/contexts/books/parse_service.rb similarity index 97% rename from app/services/books/parse.rb rename to app/contexts/books/parse_service.rb index 30d61b6..3383bb0 100644 --- a/app/services/books/parse.rb +++ b/app/contexts/books/parse_service.rb @@ -1,4 +1,4 @@ -class Books::Parse +class Books::ParseService include Callable extend Dry::Initializer diff --git a/app/services/folders/parse.rb b/app/contexts/folders/parse_service.rb similarity index 91% rename from app/services/folders/parse.rb rename to app/contexts/folders/parse_service.rb index c89fc56..fbe4187 100644 --- a/app/services/folders/parse.rb +++ b/app/contexts/folders/parse_service.rb @@ -1,4 +1,4 @@ -class Folders::Parse +class Folders::ParseService include Callable extend Dry::Initializer diff --git a/app/services/genres/counter_cache.rb b/app/contexts/genres/counter_cache_command.rb similarity index 92% rename from app/services/genres/counter_cache.rb rename to app/contexts/genres/counter_cache_command.rb index 9738268..06f3bed 100644 --- a/app/services/genres/counter_cache.rb +++ b/app/contexts/genres/counter_cache_command.rb @@ -1,4 +1,4 @@ -class Genres::CounterCache +class Genres::CounterCacheCommand include Callable QUERY = <<~SQL diff --git a/app/services/genres/parse.rb b/app/contexts/genres/parse_service.rb similarity index 94% rename from app/services/genres/parse.rb rename to app/contexts/genres/parse_service.rb index 3c2558a..5e97abb 100644 --- a/app/services/genres/parse.rb +++ b/app/contexts/genres/parse_service.rb @@ -1,4 +1,4 @@ -class Genres::Parse +class Genres::ParseService include Callable extend Dry::Initializer diff --git a/app/services/keywords/counter_cache.rb b/app/contexts/keywords/counter_cache_command.rb similarity index 92% rename from app/services/keywords/counter_cache.rb rename to app/contexts/keywords/counter_cache_command.rb index 4cc7a57..dc9a60c 100644 --- a/app/services/keywords/counter_cache.rb +++ b/app/contexts/keywords/counter_cache_command.rb @@ -1,4 +1,4 @@ -class Keywords::CounterCache +class Keywords::CounterCacheCommand include Callable QUERY = <<~SQL diff --git a/app/services/keywords/parse.rb b/app/contexts/keywords/parse_service.rb similarity index 94% rename from app/services/keywords/parse.rb rename to app/contexts/keywords/parse_service.rb index ad91785..d1fe4c6 100644 --- a/app/services/keywords/parse.rb +++ b/app/contexts/keywords/parse_service.rb @@ -1,4 +1,4 @@ -class Keywords::Parse +class Keywords::ParseService include Callable extend Dry::Initializer diff --git a/app/services/languages/counter_cache.rb b/app/contexts/languages/counter_cache_command.rb similarity index 92% rename from app/services/languages/counter_cache.rb rename to app/contexts/languages/counter_cache_command.rb index 01dba8f..a363dbc 100644 --- a/app/services/languages/counter_cache.rb +++ b/app/contexts/languages/counter_cache_command.rb @@ -1,4 +1,4 @@ -class Languages::CounterCache +class Languages::CounterCacheCommand include Callable QUERY = <<~SQL diff --git a/app/services/languages/parse.rb b/app/contexts/languages/parse_service.rb similarity index 92% rename from app/services/languages/parse.rb rename to app/contexts/languages/parse_service.rb index f50bc98..60eefeb 100644 --- a/app/services/languages/parse.rb +++ b/app/contexts/languages/parse_service.rb @@ -1,4 +1,4 @@ -class Languages::Parse +class Languages::ParseService include Callable extend Dry::Initializer diff --git a/db/seeds.rb b/db/seeds.rb index d8e7ea1..253cdee 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,8 +1,8 @@ if (File.exist? Settings.app.sql_dump_path) Seeds::SqlDumpLoad.call(filename: Settings.app.sql_dump_path) - Authors::CounterCache.call - Genres::CounterCache.call - Keywords::CounterCache.call + Authors::CounterCacheCommand.call + Genres::CounterCacheCommand.call + Keywords::CounterCacheCommand.call else Book.destroy_all Seeds::GenreLoad.call(filename: 'db/seeds/genres.yml') diff --git a/lib/connector.rb b/lib/connector.rb new file mode 100644 index 0000000..a9e11fe --- /dev/null +++ b/lib/connector.rb @@ -0,0 +1,3 @@ +class Connector + include Singleton +end diff --git a/app/services/seeds/genre_load.rb b/lib/seeds/genre_load.rb similarity index 100% rename from app/services/seeds/genre_load.rb rename to lib/seeds/genre_load.rb diff --git a/app/services/seeds/language_load.rb b/lib/seeds/language_load.rb similarity index 100% rename from app/services/seeds/language_load.rb rename to lib/seeds/language_load.rb diff --git a/app/services/seeds/lines_from_inpx.rb b/lib/seeds/lines_from_inpx.rb similarity index 100% rename from app/services/seeds/lines_from_inpx.rb rename to lib/seeds/lines_from_inpx.rb diff --git a/app/services/seeds/sql_dump_load.rb b/lib/seeds/sql_dump_load.rb similarity index 100% rename from app/services/seeds/sql_dump_load.rb rename to lib/seeds/sql_dump_load.rb diff --git a/lib/setting.rb b/lib/setting.rb new file mode 100644 index 0000000..c04669d --- /dev/null +++ b/lib/setting.rb @@ -0,0 +1,9 @@ +class Setting + include Singleton + extend Forwardable + def_delegators :@list, :[]=, :[] + + def initialize + @list = {} + end +end diff --git a/lib/tasks/inpx.rake b/lib/tasks/inpx.rake index 81d38e6..7274456 100644 --- a/lib/tasks/inpx.rake +++ b/lib/tasks/inpx.rake @@ -45,7 +45,7 @@ namespace :inpx do puts title folders = Parallel.map(Range.new(0, count - 1), in_processes: count) do |index| start = Time.zone.now - folders = Folders::Parse.call(books: chunks[index]) + folders = Folders::ParseService.call(books: chunks[index]) finish = Time.zone.now puts format("Процесс %d: %0.2f сек", index, (finish - start)) folders.uniq @@ -57,7 +57,7 @@ namespace :inpx do puts title Parallel.map(Range.new(0, count - 1), in_processes: count) do |index| start = Time.zone.now - Books::Parse.call(books: chunks[index]) + Books::ParseService.call(books: chunks[index]) finish = Time.zone.now puts format("Процесс %d: %0.2f сек", index, (finish - start)) end @@ -67,7 +67,7 @@ namespace :inpx do puts title authors = Parallel.map(Range.new(0, count - 1), in_processes: count) do |index| start = Time.zone.now - authors = Authors::Parse.call(books: chunks[index]) + authors = Authors::ParseService.call(books: chunks[index]) finish = Time.zone.now puts format("Процесс %d: %0.2f сек", index, (finish - start)) authors.flatten.uniq @@ -79,7 +79,7 @@ namespace :inpx do puts title keywords = Parallel.map(Range.new(0, count - 1), in_processes: count) do |index| start = Time.zone.now - keywords = Keywords::Parse.call(books: chunks[index]) + keywords = Keywords::ParseService.call(books: chunks[index]) finish = Time.zone.now puts format("Процесс %d: %0.2f сек", index, (finish - start)) keywords.uniq @@ -96,7 +96,7 @@ namespace :inpx do Parallel.map(Range.new(0, count - 1), in_processes: count) do |index| start = Time.zone.now - Books::Links.call( + Books::LinksService.call( books: chunks[index], genres_map: genres_map, keywords_map: keywords_map, @@ -106,10 +106,10 @@ namespace :inpx do puts format("Процесс %d: %0.2f сек", index, (finish - start)) end - Authors::CounterCache.call - Genres::CounterCache.call - Keywords::CounterCache.call - Languages::CounterCache.call + Authors::CounterCacheCommand.call + Genres::CounterCacheCommand.call + Keywords::CounterCacheCommand.call + Languages::CounterCacheCommand.call puts "Связей книг и авторов #{BooksAuthor.count}" puts "Связей книг и ключевых слов #{BooksKeyword.count}" diff --git a/spec/services/authors/counter_cache_spec.rb b/spec/services/authors/counter_cache_spec.rb index b406dbe..1a5614c 100644 --- a/spec/services/authors/counter_cache_spec.rb +++ b/spec/services/authors/counter_cache_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Authors::CounterCache do +RSpec.describe Authors::CounterCacheCommand do subject(:operation) { described_class } let(:fio) { 'Алешкин,Тимофей,Владимирович' } diff --git a/spec/services/authors/parse_spec.rb b/spec/services/authors/parse_spec.rb index 2dd369f..0ecf1fc 100644 --- a/spec/services/authors/parse_spec.rb +++ b/spec/services/authors/parse_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Authors::Parse do +RSpec.describe Authors::ParseService do subject(:operation) { described_class } let(:books) { File.readlines('spec/fixtures/fb2-ru-ok-sf.inp') } diff --git a/spec/services/books/extract_spec.rb b/spec/services/books/extract_spec.rb index 4407738..a63cc57 100644 --- a/spec/services/books/extract_spec.rb +++ b/spec/services/books/extract_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Books::Extract do +RSpec.describe Books::ExtractService do subject(:operation) { described_class } let(:book) { create(:extract_book) } diff --git a/spec/services/books/links_spec.rb b/spec/services/books/links_spec.rb index f8b8d9c..c148885 100644 --- a/spec/services/books/links_spec.rb +++ b/spec/services/books/links_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Books::Links do +RSpec.describe Books::LinksService do subject(:operation) { described_class } let(:books) { File.readlines('spec/fixtures/fb2-ru-ok-sf.inp') } diff --git a/spec/services/books/parse_spec.rb b/spec/services/books/parse_spec.rb index 7582b33..61e482b 100644 --- a/spec/services/books/parse_spec.rb +++ b/spec/services/books/parse_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Books::Parse do +RSpec.describe Books::ParseService do subject(:operation) { described_class } let(:books) { File.readlines('spec/fixtures/fb2-ru-ok-sf.inp') } diff --git a/spec/services/folders/parse_spec.rb b/spec/services/folders/parse_spec.rb index 59620e9..e0d929d 100644 --- a/spec/services/folders/parse_spec.rb +++ b/spec/services/folders/parse_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Folders::Parse do +RSpec.describe Folders::ParseService do subject(:operation) { described_class } let(:books) { File.readlines('spec/fixtures/fb2-ru-ok-sf.inp') } diff --git a/spec/services/genres/counter_cache_spec.rb b/spec/services/genres/counter_cache_spec.rb index 4243cce..72a531a 100644 --- a/spec/services/genres/counter_cache_spec.rb +++ b/spec/services/genres/counter_cache_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Genres::CounterCache do +RSpec.describe Genres::CounterCacheCommand do subject(:operation) { described_class } before { inp_full_load('spec/fixtures/fb2-ru-ok-sf.inp') } diff --git a/spec/services/genres/parse_spec.rb b/spec/services/genres/parse_spec.rb index dd5ed9f..762e675 100644 --- a/spec/services/genres/parse_spec.rb +++ b/spec/services/genres/parse_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Genres::Parse do +RSpec.describe Genres::ParseService do subject(:operation) { described_class } let(:filename) { 'spec/fixtures/fb2-ru-ok-sf.inp' } diff --git a/spec/services/keywords/counter_cache_spec.rb b/spec/services/keywords/counter_cache_spec.rb index 5654e48..2c8909f 100644 --- a/spec/services/keywords/counter_cache_spec.rb +++ b/spec/services/keywords/counter_cache_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Keywords::CounterCache do +RSpec.describe Keywords::CounterCacheCommand do subject(:operation) { described_class } before { inp_full_load('spec/fixtures/fb2-ru-ok-sf.inp') } diff --git a/spec/services/keywords/parse_spec.rb b/spec/services/keywords/parse_spec.rb index 0f76956..40cbe98 100644 --- a/spec/services/keywords/parse_spec.rb +++ b/spec/services/keywords/parse_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Keywords::Parse do +RSpec.describe Keywords::ParseService do subject(:operation) { described_class } let(:books) { File.readlines('spec/fixtures/fb2-ru-ok-sf.inp') } diff --git a/spec/services/languages/counter_cache_spec.rb b/spec/services/languages/counter_cache_spec.rb index aff8eac..27c4318 100644 --- a/spec/services/languages/counter_cache_spec.rb +++ b/spec/services/languages/counter_cache_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Languages::CounterCache do +RSpec.describe Languages::CounterCacheCommand do subject(:operation) { described_class } before { inp_full_load('spec/fixtures/fb2-ru-ok-sf.inp') } diff --git a/spec/services/languages/parse_spec.rb b/spec/services/languages/parse_spec.rb index 0af6e02..967aeca 100644 --- a/spec/services/languages/parse_spec.rb +++ b/spec/services/languages/parse_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Languages::Parse do +RSpec.describe Languages::ParseService do subject(:operation) { described_class } let(:filename) { 'spec/fixtures/fb2-ru-ok-sf.inp' } diff --git a/spec/support/loader_helpers.rb b/spec/support/loader_helpers.rb index f65641e..3a9b901 100644 --- a/spec/support/loader_helpers.rb +++ b/spec/support/loader_helpers.rb @@ -17,7 +17,7 @@ def inp_full_load(path) lines = File.readlines(path) - Books::Links.call( + Books::LinksService.call( books: lines, genres_map: Genre.pluck(:slug, :id).to_h, keywords_map: Keyword.pluck(:name, :id).to_h, @@ -51,21 +51,21 @@ def load_languages end def load_folders(lines) - folders = Folders::Parse.call(books: lines) + folders = Folders::ParseService.call(books: lines) Folder.create(folders.map { |f| { name: f } }) end def load_books(lines) - Books::Parse.call(books: lines) + Books::ParseService.call(books: lines) end def load_keywords(lines) - keywords = Keywords::Parse.call(books: lines) + keywords = Keywords::ParseService.call(books: lines) Keyword.import keywords.uniq.map { |name| Keyword.new(name: name) } end def load_authors(lines) - authors = Authors::Parse.call(books: lines) + authors = Authors::ParseService.call(books: lines) Author.import authors.flatten.uniq.map { |attr| Author.new(attr) } end end