Class: PeakFlowUtils::TranslationsParserService
- Inherits:
-
ApplicationService
- Object
- ServicePattern::Service
- ApplicationService
- PeakFlowUtils::TranslationsParserService
- Defined in:
- app/services/peak_flow_utils/translations_parser_service.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Class Method Summary collapse
Instance Method Summary collapse
- #database_path ⇒ Object
- #perform ⇒ Object
- #update_groups_for_handler(handler_model) ⇒ Object
- #update_handlers ⇒ Object
- #update_translations_for_group(handler_model, group_model) ⇒ Object
- #with_transactioner ⇒ Object
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
2 3 4 |
# File 'app/services/peak_flow_utils/translations_parser_service.rb', line 2 def db @db end |
Class Method Details
.database_path ⇒ Object
24 25 26 |
# File 'app/services/peak_flow_utils/translations_parser_service.rb', line 24 def self.database_path @database_path ||= Rails.root.join("db/peak_flow_utils.sqlite3").to_s end |
Instance Method Details
#database_path ⇒ Object
28 29 30 |
# File 'app/services/peak_flow_utils/translations_parser_service.rb', line 28 def database_path @database_path ||= self.class.database_path end |
#perform ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'app/services/peak_flow_utils/translations_parser_service.rb', line 4 def perform PeakFlowUtils::DatabaseInitializerService.execute! cache_translations_in_dir(Rails.root.join("config/locales")) cache_translations_in_handlers clean_up_not_found succeed! end |
#update_groups_for_handler(handler_model) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/services/peak_flow_utils/translations_parser_service.rb', line 46 def update_groups_for_handler(handler_model) @groups_found ||= {} handler = handler_model.at_handler handler.groups.each do |group| debug "Updating group: #{group.name}" group_model = PeakFlowUtils::Group.find_or_initialize_by(handler_id: handler_model.id, identifier: group.id) group_model.update!(name: group.name) @groups_found[group_model.id] = true group_model.at_group = group yield group_model if block_given? end end |
#update_handlers ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/services/peak_flow_utils/translations_parser_service.rb', line 32 def update_handlers @handlers_found ||= {} PeakFlowUtils::HandlersFinderService.execute!.each do |handler| debug "Updating handler: #{handler.name}" handler_model = PeakFlowUtils::Handler.find_or_initialize_by(identifier: handler.id) handler_model.update!(name: handler.name) @handlers_found[handler_model.id] = true yield handler_model if block_given? end end |
#update_translations_for_group(handler_model, group_model) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/services/peak_flow_utils/translations_parser_service.rb', line 62 def update_translations_for_group(handler_model, group_model) group = group_model.at_group @translation_keys_found ||= {} @handler_translations_found ||= {} group.translations.each do |translation| debug "Updating translation: #{translation.key}" translation_key = PeakFlowUtils::TranslationKey.find_or_create_by!(key: translation.key) raise "KEY ERROR: #{translation_key.inspect}" unless translation_key.id.to_i.positive? @translation_keys_found[translation_key.id] = true handler_translation = PeakFlowUtils::HandlerText.find_or_initialize_by( translation_key_id: translation_key.id, handler_id: handler_model.id, group_id: group_model.id ) handler_translation.assign_attributes( default: translation.default, file_path: translation.file_path, line_no: translation.line_no, key_show: translation.key_show, full_path: translation.full_path, dir: translation.dir ) if @transactioner && handler_translation.persisted? @transactioner.save!(handler_translation) else handler_translation.save! end @handler_translations_found[handler_translation.id] = true end end |
#with_transactioner ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'app/services/peak_flow_utils/translations_parser_service.rb', line 15 def with_transactioner require "active-record-transactioner" ActiveRecordTransactioner.new do |transactioner| @transactioner = transactioner yield end end |