Module: FuryDumper
- Defined in:
- lib/fury_dumper.rb,
lib/fury_dumper/api.rb,
lib/fury_dumper/config.rb,
lib/fury_dumper/dumper.rb,
lib/fury_dumper/engine.rb,
lib/fury_dumper/version.rb,
lib/fury_dumper/encrypter.rb,
lib/fury_dumper/dumpers/model.rb,
lib/fury_dumper/dumpers/dump_state.rb,
lib/fury_dumper/dumpers/model_queue.rb,
lib/fury_dumper/dumpers/relation_items.rb,
lib/generators/fury_dumper/config_generator.rb,
app/controllers/fury_dumper/dump_process_controller.rb
Defined Under Namespace
Modules: Dumpers, Generators Classes: Api, Config, DumpProcessController, Dumper, Encrypter, Engine, Error
Constant Summary collapse
- VERSION =
'0.1.1'
Class Method Summary collapse
- .check_type(field, expected_type, field_name) ⇒ Object
- .configuration ⇒ Object
-
.dump(password:, host:, port:, user:, field_values:, database:, model_name: 'Lead', field_name: 'id', debug_mode: :none, ask: true) ⇒ Object
Start dumping.
Class Method Details
.check_type(field, expected_type, field_name) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/fury_dumper.rb', line 90 def self.check_type(field, expected_type, field_name) is_ok = if expected_type.is_a?(Array) expected_type.any? do |type| field.is_a?(type) end else field.is_a?(expected_type) end types_str = expected_type.is_a?(Array) ? expected_type.join(' or ') : expected_type raise ArgumentError, "Expected #{field_name} as #{types_str}, got: #{field.class}" unless is_ok end |
.configuration ⇒ Object
21 22 23 |
# File 'lib/fury_dumper.rb', line 21 def self.configuration @configuration ||= Config.config end |
.dump(password:, host:, port:, user:, field_values:, database:, model_name: 'Lead', field_name: 'id', debug_mode: :none, ask: true) ⇒ Object
Start dumping
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 |
# File 'lib/fury_dumper.rb', line 47 def self.dump(password:, host:, port:, user:, field_values:, database:, model_name: 'Lead', field_name: 'id', debug_mode: :none, ask: true) check_type(model_name, String, 'model name') check_type(field_name, String, 'field name') check_type(field_values, [Array, Range], 'field values') states = [] field_values.to_a.in_groups_of(FuryDumper::Config.batch_size) do |batch| relation_items = FuryDumper::Dumpers::RelationItems.new_with_key_value(item_key: field_name, item_values: batch) sync = Dumper.new \ password: password, host: host, port: port, user: user, database: database, model: FuryDumper::Dumpers::Model.new(source_model: model_name, relation_items: relation_items), debug_mode: debug_mode if ask && !sync.equal_schemas? confirm = ask('Are you sure to continue? [Y/N] ') { |yn| yn.limit = 1, yn.validate = /[yn]/i } ask = false return unless confirm.downcase == 'y' # rubocop:disable Lint/NonLocalExitFromIterator end sync.sync_models states << sync.dump_state end states.each_with_index do |state, index| p "Batch ##{index}:" state.print_statistic end true end |