Class: BigqueryMigration::ActionRunner
- Inherits:
-
Object
- Object
- BigqueryMigration::ActionRunner
- Defined in:
- lib/bigquery_migration/action_runner.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize(config_path = nil, opts = {}) ⇒ ActionRunner
constructor
A new instance of ActionRunner.
- #run ⇒ Object
- #run_actions ⇒ Object
- #validate_config! ⇒ Object
Constructor Details
#initialize(config_path = nil, opts = {}) ⇒ ActionRunner
Returns a new instance of ActionRunner.
10 11 12 13 14 15 16 |
# File 'lib/bigquery_migration/action_runner.rb', line 10 def initialize(config_path = nil, opts = {}) @config_path = config_path @opts = opts config = ConfigLoader.new(@config_path, opts[:vars]).load @config = HashUtil.deep_symbolize_keys(config) validate_config! end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/bigquery_migration/action_runner.rb', line 8 def config @config end |
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
8 9 10 |
# File 'lib/bigquery_migration/action_runner.rb', line 8 def config_path @config_path end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
8 9 10 |
# File 'lib/bigquery_migration/action_runner.rb', line 8 def opts @opts end |
Instance Method Details
#run ⇒ Object
18 19 20 21 |
# File 'lib/bigquery_migration/action_runner.rb', line 18 def run success, responses = run_actions { success: success, dry_run: @opts[:dry_run], actions: responses } end |
#run_actions ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bigquery_migration/action_runner.rb', line 23 def run_actions success = true responses = [] @config[:actions].each do |action_config| _success, result = Action.new(action_config, @opts).run response = action_config.merge({'result' => result}) responses << response unless _success success = false break end end [success, responses] end |
#validate_config! ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bigquery_migration/action_runner.rb', line 40 def validate_config! unless config.is_a?(Hash) raise ConfigError, "config file format has to be YAML Hash" end unless config[:actions] raise ConfigError, "config must have `actions` key" end unless config[:actions].is_a?(Array) raise ConfigError, "config[:actions] must be an Array" end config[:actions].each do |action_config| unless action_config[:action] raise ConfigError, "Elements of `config[:actions]` must have `action` key" end end end |