masamune 0.17.15 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/lib/masamune/actions/aws_emr.rb +5 -5
  3. data/lib/masamune/actions/hadoop_filesystem.rb +1 -1
  4. data/lib/masamune/actions/hadoop_streaming.rb +3 -3
  5. data/lib/masamune/actions/hive.rb +5 -5
  6. data/lib/masamune/actions/postgres.rb +5 -5
  7. data/lib/masamune/actions/s3cmd.rb +1 -1
  8. data/lib/masamune/cached_filesystem.rb +1 -1
  9. data/lib/masamune/commands/aws_emr.rb +11 -11
  10. data/lib/masamune/commands/hadoop_filesystem.rb +8 -8
  11. data/lib/masamune/commands/hadoop_streaming.rb +2 -2
  12. data/lib/masamune/commands/hive.rb +19 -19
  13. data/lib/masamune/commands/postgres.rb +19 -19
  14. data/lib/masamune/commands/postgres_admin.rb +13 -13
  15. data/lib/masamune/commands/s3cmd.rb +7 -7
  16. data/lib/masamune/configuration.rb +36 -52
  17. data/lib/masamune/environment.rb +4 -3
  18. data/lib/masamune/method_logger.rb +4 -0
  19. data/lib/masamune/schema/store.rb +17 -5
  20. data/lib/masamune/thor.rb +1 -3
  21. data/lib/masamune/version.rb +1 -1
  22. data/spec/masamune/actions/aws_emr_spec.rb +4 -4
  23. data/spec/masamune/actions/hadoop_filesystem_spec.rb +1 -1
  24. data/spec/masamune/actions/hadoop_streaming_spec.rb +5 -5
  25. data/spec/masamune/actions/hive_spec.rb +4 -4
  26. data/spec/masamune/actions/postgres_spec.rb +2 -2
  27. data/spec/masamune/actions/s3cmd_spec.rb +1 -1
  28. data/spec/masamune/commands/aws_emr_spec.rb +1 -1
  29. data/spec/masamune/commands/hadoop_filesystem_spec.rb +1 -1
  30. data/spec/masamune/commands/hadoop_streaming_spec.rb +1 -1
  31. data/spec/masamune/commands/hive_spec.rb +1 -1
  32. data/spec/masamune/commands/postgres_admin_spec.rb +15 -2
  33. data/spec/masamune/commands/postgres_spec.rb +1 -1
  34. data/spec/masamune/commands/s3cmd_spec.rb +1 -1
  35. data/spec/masamune/configuration_spec.rb +96 -1
  36. data/spec/masamune/environment_spec.rb +28 -1
  37. data/spec/masamune/schema/catalog_spec.rb +1 -1
  38. data/spec/masamune/tasks/aws_emr_thor_spec.rb +2 -2
  39. data/spec/masamune/tasks/hive_thor_spec.rb +7 -7
  40. data/spec/masamune/tasks/postgres_thor_spec.rb +4 -4
  41. data/spec/masamune/tasks/shell_thor_spec.rb +1 -1
  42. data/spec/masamune/thor_spec.rb +8 -13
  43. data/spec/support/masamune/example_group.rb +4 -3
  44. data/spec/support/masamune/job_example_group.rb +26 -27
  45. data/spec/support/masamune/mock_command.rb +3 -3
  46. data/spec/support/masamune/shared_example_group.rb +8 -10
  47. data/spec/support/masamune/step_example_group.rb +25 -28
  48. data/spec/support/masamune/task_example_group.rb +75 -28
  49. data/spec/support/masamune/thor_mute.rb +4 -2
  50. data/spec/support/rspec/example/action_example_group.rb +5 -3
  51. data/spec/support/rspec/example/task_example_group.rb +4 -67
  52. data/spec/support/rspec/example/transform_example_group.rb +7 -5
  53. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ecd8682fd1fc01a49affd8d28d3e299c601c75c
4
- data.tar.gz: 45f3801d782a6cb2d2dc07e3a72a2f3286925bdc
3
+ metadata.gz: 78cc6a05c7d3d967eb2f5f66a89c9b2eb4d22bca
4
+ data.tar.gz: 7c2ae67465453c5064819aa16338ed2b1b73a656
5
5
  SHA512:
6
- metadata.gz: 4f8ee35378be875d5e37154757a471d09f5364375a9330b105744ed2093ec4e1280b0ae1dfe0118b1b656bb18fc797353b438532aa57d97718420b8c72ee1406
7
- data.tar.gz: ec1c92befce218f594d0688f4e801f80554f8470895b8dc616e6d4013b93d52cdc6b3005caec0d6ccc9173447cd43cfea12756c74d1ad4e3c16f50e55ef94cb9
6
+ metadata.gz: 1b4b73612c75ca6e73f4ecc49b68d034cae34acbfa4359f5588ab51dcfea2878e7890988fa5abca21d515b90d048005ec4a5282c6f306117c2e430e44b2061a8
7
+ data.tar.gz: a5d0c3525357265e77f5fdc09bcf6a0f2af9e9c81262d4bfed1bb1d809c7fb407704c7f68db2ad9ccb281d5c58ba075aa38c2c4f31fc45f3c6ed4def9cdf63e7
@@ -28,14 +28,14 @@ module Masamune::Actions
28
28
  opts = opts.to_hash.symbolize_keys
29
29
 
30
30
  command = Masamune::Commands::AwsEmr.new(environment, opts)
31
- command = Masamune::Commands::RetryWithBackoff.new(command, configuration.aws_emr.slice(:retries, :backoff).merge(opts))
31
+ command = Masamune::Commands::RetryWithBackoff.new(command, configuration.commands.aws_emr.slice(:retries, :backoff).merge(opts))
32
32
  command = Masamune::Commands::Shell.new(command, opts)
33
33
 
34
34
  command.interactive? ? command.replace : command.execute
35
35
  end
36
36
 
37
37
  def validate_cluster_id!
38
- cluster_id = configuration.aws_emr[:cluster_id]
38
+ cluster_id = configuration.commands.aws_emr[:cluster_id]
39
39
  raise ::Thor::RequiredArgumentMissingError, "No value provided for required options '--cluster-id'" unless cluster_id
40
40
  raise ::Thor::RequiredArgumentMissingError, %(AWS EMR cluster '#{cluster_id}' does not exist) unless aws_emr(action: 'describe-cluster', cluster_id: cluster_id, fail_fast: false).success?
41
41
  end
@@ -43,9 +43,9 @@ module Masamune::Actions
43
43
  included do |base|
44
44
  base.class_option :cluster_id, desc: 'AWS EMR cluster_id ID (Hint: `masamune-emr-aws list-clusters`)' if defined?(base.class_option)
45
45
  base.after_initialize(:early) do |thor, options|
46
- next unless thor.configuration.aws_emr.any?
47
- next unless thor.configuration.aws_emr.fetch(:enabled, true)
48
- thor.configuration.aws_emr[:cluster_id] = options[:cluster_id] if options[:cluster_id]
46
+ next unless thor.configuration.commands.aws_emr.any?
47
+ next unless thor.configuration.commands.aws_emr.fetch(:enabled, true)
48
+ thor.configuration.commands.aws_emr[:cluster_id] = options[:cluster_id] if options[:cluster_id]
49
49
  next unless options[:initialize]
50
50
  thor.validate_cluster_id!
51
51
  end if defined?(base.after_initialize)
@@ -30,7 +30,7 @@ module Masamune::Actions
30
30
  opts[:block] = block.to_proc if block_given?
31
31
 
32
32
  command = Masamune::Commands::HadoopFilesystem.new(environment, opts)
33
- command = Masamune::Commands::RetryWithBackoff.new(command, configuration.hadoop_filesystem.slice(:retries, :backoff).merge(opts))
33
+ command = Masamune::Commands::RetryWithBackoff.new(command, configuration.commands.hadoop_filesystem.slice(:retries, :backoff).merge(opts))
34
34
  command = Masamune::Commands::Shell.new(command, opts)
35
35
 
36
36
  command.execute
@@ -26,8 +26,8 @@ module Masamune::Actions
26
26
  opts = opts.to_hash.symbolize_keys
27
27
 
28
28
  command = Masamune::Commands::HadoopStreaming.new(environment, aws_emr_options(opts))
29
- command = Masamune::Commands::AwsEmr.new(command, opts.except(:extra)) if configuration.aws_emr[:cluster_id]
30
- command = Masamune::Commands::RetryWithBackoff.new(command, configuration.hadoop_streaming.slice(:retries, :backoff).merge(opts))
29
+ command = Masamune::Commands::AwsEmr.new(command, opts.except(:extra)) if configuration.commands.aws_emr[:cluster_id]
30
+ command = Masamune::Commands::RetryWithBackoff.new(command, configuration.commands.hadoop_streaming.slice(:retries, :backoff).merge(opts))
31
31
  command = Masamune::Commands::Shell.new(command, opts)
32
32
 
33
33
  command.execute
@@ -36,7 +36,7 @@ module Masamune::Actions
36
36
  private
37
37
 
38
38
  def aws_emr_options(opts = {})
39
- return opts unless configuration.aws_emr[:cluster_id]
39
+ return opts unless configuration.commands.aws_emr[:cluster_id]
40
40
  opts.merge(quote: true, upload: false)
41
41
  end
42
42
  end
@@ -33,8 +33,8 @@ module Masamune::Actions
33
33
  opts[:block] = block.to_proc if block_given?
34
34
 
35
35
  command = Masamune::Commands::Hive.new(environment, opts)
36
- command = Masamune::Commands::AwsEmr.new(command, opts.except(:extra)) if configuration.aws_emr[:cluster_id]
37
- command = Masamune::Commands::RetryWithBackoff.new(command, configuration.hive.slice(:retries, :backoff).merge(opts))
36
+ command = Masamune::Commands::AwsEmr.new(command, opts.except(:extra)) if configuration.commands.aws_emr[:cluster_id]
37
+ command = Masamune::Commands::RetryWithBackoff.new(command, configuration.commands.hive.slice(:retries, :backoff).merge(opts))
38
38
  command = Masamune::Commands::Shell.new(command, opts)
39
39
 
40
40
  command.interactive? ? command.replace : command.execute
@@ -42,10 +42,10 @@ module Masamune::Actions
42
42
 
43
43
  # TODO: warn or error if database is not defined
44
44
  def create_hive_database_if_not_exists
45
- return if configuration.hive[:database] == 'default'
45
+ return if configuration.commands.hive[:database] == 'default'
46
46
  sql = []
47
- sql << %(CREATE DATABASE IF NOT EXISTS #{configuration.hive[:database]})
48
- sql << %(LOCATION "#{configuration.hive[:location]}") if configuration.hive[:location]
47
+ sql << %(CREATE DATABASE IF NOT EXISTS #{configuration.commands.hive[:database]})
48
+ sql << %(LOCATION "#{configuration.commands.hive[:location]}") if configuration.commands.hive[:location]
49
49
  hive(exec: sql.join(' ') + ';', database: nil)
50
50
  end
51
51
 
@@ -35,24 +35,24 @@ module Masamune::Actions
35
35
  opts[:block] = block.to_proc if block_given?
36
36
 
37
37
  command = Masamune::Commands::Postgres.new(environment, opts)
38
- command = Masamune::Commands::RetryWithBackoff.new(command, configuration.postgres.slice(:retries, :backoff).merge(opts))
38
+ command = Masamune::Commands::RetryWithBackoff.new(command, configuration.commands.postgres.slice(:retries, :backoff).merge(opts))
39
39
  command = Masamune::Commands::Shell.new(command, opts)
40
40
 
41
41
  command.interactive? ? command.replace : command.execute
42
42
  end
43
43
 
44
44
  def create_postgres_database_if_not_exists
45
- if configuration.postgres.key?(:database)
46
- postgres_admin(action: :create, database: configuration.postgres[:database], safe: true) unless postgres_helper.database_exists?
45
+ if configuration.commands.postgres.key?(:database)
46
+ postgres_admin(action: :create, database: configuration.commands.postgres[:database], safe: true) unless postgres_helper.database_exists?
47
47
  end
48
48
  end
49
49
 
50
50
  def load_postgres_setup_files
51
- configuration.postgres[:setup_files].each do |file|
51
+ configuration.commands.postgres[:setup_files].each do |file|
52
52
  configuration.with_quiet do
53
53
  postgres(file: file, retries: 0)
54
54
  end
55
- end if configuration.postgres.key?(:setup_files)
55
+ end if configuration.commands.postgres.key?(:setup_files)
56
56
  end
57
57
 
58
58
  def load_postgres_schema
@@ -33,7 +33,7 @@ module Masamune::Actions
33
33
  opts[:block] = block.to_proc if block_given?
34
34
 
35
35
  command = Masamune::Commands::S3Cmd.new(environment, opts)
36
- command = Masamune::Commands::RetryWithBackoff.new(command, configuration.s3cmd.slice(:retries, :backoff).merge(opts))
36
+ command = Masamune::Commands::RetryWithBackoff.new(command, configuration.commands.s3cmd.slice(:retries, :backoff).merge(opts))
37
37
  command = Masamune::Commands::Shell.new(command, opts)
38
38
 
39
39
  command.execute
@@ -78,7 +78,7 @@ module Masamune
78
78
  next if entry.name == dirname
79
79
  next unless entry.name =~ file_regexp
80
80
  yield entry
81
- end if depth == 0
81
+ end if depth.zero?
82
82
  end
83
83
 
84
84
  # FIXME: cache eviction policy can be more precise
@@ -29,19 +29,19 @@ module Masamune::Commands
29
29
  include Masamune::Actions::Execute
30
30
 
31
31
  DEFAULT_ATTRIBUTES =
32
- {
33
- path: 'aws',
34
- extra: [],
35
- config_file: nil,
36
- action: nil,
37
- cluster_id: nil,
38
- interactive: false
39
- }.freeze
32
+ {
33
+ path: 'aws',
34
+ extra: [],
35
+ config_file: nil,
36
+ action: nil,
37
+ cluster_id: nil,
38
+ interactive: false
39
+ }.with_indifferent_access.freeze
40
40
 
41
41
  def initialize(delegate, attrs = {})
42
42
  super delegate
43
43
  @delegate = delegate
44
- DEFAULT_ATTRIBUTES.merge(configuration.aws_emr).merge(attrs).each do |name, value|
44
+ DEFAULT_ATTRIBUTES.merge(configuration.commands.aws_emr).merge(attrs).each do |name, value|
45
45
  instance_variable_set("@#{name}", value)
46
46
  end
47
47
  end
@@ -104,7 +104,7 @@ module Masamune::Commands
104
104
  end
105
105
 
106
106
  def handle_stdout(line, line_no)
107
- if line_no == 0 && line.start_with?('ssh') && @delegate.respond_to?(:handle_stderr)
107
+ if line_no.zero? && line.start_with?('ssh') && @delegate.respond_to?(:handle_stderr)
108
108
  @delegate.handle_stderr(line, line_no)
109
109
  elsif @delegate.respond_to?(:handle_stdout)
110
110
  @delegate.handle_stdout(line, line_no)
@@ -118,7 +118,7 @@ module Masamune::Commands
118
118
  end
119
119
 
120
120
  def action_options
121
- configuration.aws_emr.fetch(action.underscore.to_sym, {}).with_indifferent_access.fetch(:options, {}).reject { |key, _| @extra.include?(key.to_s) }
121
+ configuration.commands.aws_emr.fetch(action.underscore.to_sym, {}).with_indifferent_access.fetch(:options, {}).reject { |key, _| @extra.include?(key.to_s) }
122
122
  end
123
123
 
124
124
  def ssh_command?
@@ -25,17 +25,17 @@ require 'delegate'
25
25
  module Masamune::Commands
26
26
  class HadoopFilesystem < SimpleDelegator
27
27
  DEFAULT_ATTRIBUTES =
28
- {
29
- path: 'hadoop',
30
- options: [],
31
- extra: [],
32
- block: nil,
33
- print: false
34
- }.freeze
28
+ {
29
+ path: 'hadoop',
30
+ options: [],
31
+ extra: [],
32
+ block: nil,
33
+ print: false
34
+ }.with_indifferent_access.freeze
35
35
 
36
36
  def initialize(delegate, attrs = {})
37
37
  super delegate
38
- DEFAULT_ATTRIBUTES.merge(configuration.hadoop_filesystem).merge(attrs).each do |name, value|
38
+ DEFAULT_ATTRIBUTES.merge(configuration.commands.hadoop_filesystem).merge(attrs).each do |name, value|
39
39
  instance_variable_set("@#{name}", value)
40
40
  end
41
41
  end
@@ -49,13 +49,13 @@ module Masamune::Commands
49
49
  extra: [],
50
50
  upload: true,
51
51
  quote: false
52
- }.freeze
52
+ }.with_indifferent_access.freeze
53
53
 
54
54
  attr_reader :input
55
55
 
56
56
  def initialize(delegate, attrs = {})
57
57
  super delegate
58
- DEFAULT_ATTRIBUTES.merge(configuration.hadoop_streaming).merge(attrs).each do |name, value|
58
+ DEFAULT_ATTRIBUTES.merge(configuration.commands.hadoop_streaming).merge(attrs).each do |name, value|
59
59
  instance_variable_set("@#{name}", value)
60
60
  end
61
61
  @input = Array.wrap(@input)
@@ -33,28 +33,28 @@ module Masamune::Commands
33
33
  PROMPT = 'hive>'.freeze
34
34
 
35
35
  DEFAULT_ATTRIBUTES =
36
- {
37
- path: 'hive',
38
- options: [],
39
- database: 'default',
40
- setup_files: [],
41
- schema_files: [],
42
- file: nil,
43
- exec: nil,
44
- output: nil,
45
- print: false,
46
- block: nil,
47
- variables: {},
48
- buffer: nil,
49
- service: false,
50
- delimiter: "\001",
51
- csv: false,
52
- debug: false
53
- }.freeze
36
+ {
37
+ path: 'hive',
38
+ options: [],
39
+ database: 'default',
40
+ setup_files: [],
41
+ schema_files: [],
42
+ file: nil,
43
+ exec: nil,
44
+ output: nil,
45
+ print: false,
46
+ block: nil,
47
+ variables: {},
48
+ buffer: nil,
49
+ service: false,
50
+ delimiter: "\001",
51
+ csv: false,
52
+ debug: false
53
+ }.with_indifferent_access.freeze
54
54
 
55
55
  def initialize(delegate, attrs = {})
56
56
  super delegate
57
- DEFAULT_ATTRIBUTES.merge(configuration.hive).merge(attrs).each do |name, value|
57
+ DEFAULT_ATTRIBUTES.merge(configuration.commands.hive).merge(attrs).each do |name, value|
58
58
  instance_variable_set("@#{name}", value)
59
59
  end
60
60
  raise ArgumentError, 'Cannot specify both file and exec' if @file && @exec
@@ -31,28 +31,28 @@ module Masamune::Commands
31
31
  include Masamune::Commands::PostgresCommon
32
32
 
33
33
  DEFAULT_ATTRIBUTES =
34
- {
35
- path: 'psql',
36
- options: [],
37
- hostname: 'localhost',
38
- database: 'postgres',
39
- username: 'postgres',
40
- pgpass_file: nil,
41
- file: nil,
42
- exec: nil,
43
- input: nil,
44
- output: nil,
45
- print: false,
46
- block: nil,
47
- csv: false,
48
- variables: {},
49
- tuple_output: false,
50
- debug: false
51
- }.freeze
34
+ {
35
+ path: 'psql',
36
+ options: [],
37
+ hostname: 'localhost',
38
+ database: 'postgres',
39
+ username: 'postgres',
40
+ pgpass_file: nil,
41
+ file: nil,
42
+ exec: nil,
43
+ input: nil,
44
+ output: nil,
45
+ print: false,
46
+ block: nil,
47
+ csv: false,
48
+ variables: {},
49
+ tuple_output: false,
50
+ debug: false
51
+ }.with_indifferent_access.freeze
52
52
 
53
53
  def initialize(delegate, attrs = {})
54
54
  super delegate
55
- DEFAULT_ATTRIBUTES.merge(configuration.postgres).merge(attrs).each do |name, value|
55
+ DEFAULT_ATTRIBUTES.merge(configuration.commands.postgres).merge(attrs).each do |name, value|
56
56
  instance_variable_set("@#{name}", value)
57
57
  end
58
58
  raise ArgumentError, 'Cannot specify both file and exec' if @file && @exec
@@ -29,22 +29,22 @@ module Masamune::Commands
29
29
  include Masamune::Commands::PostgresCommon
30
30
 
31
31
  DEFAULT_ATTRIBUTES =
32
- {
33
- create_db_path: 'createdb',
34
- drop_db_path: 'dropdb',
35
- pg_dump_path: 'pg_dump',
36
- options: [],
37
- hostname: 'localhost',
38
- username: 'postgres',
39
- pgpass_file: nil,
40
- action: nil,
41
- database: nil,
42
- output: nil
43
- }.freeze
32
+ {
33
+ create_db_path: 'createdb',
34
+ drop_db_path: 'dropdb',
35
+ pg_dump_path: 'pg_dump',
36
+ options: [],
37
+ hostname: 'localhost',
38
+ username: 'postgres',
39
+ pgpass_file: nil,
40
+ action: nil,
41
+ database: nil,
42
+ output: nil
43
+ }.with_indifferent_access.freeze
44
44
 
45
45
  def initialize(delegate, attrs = {})
46
46
  super delegate
47
- DEFAULT_ATTRIBUTES.merge(configuration.postgres).merge(configuration.postgres_admin).merge(attrs).each do |name, value|
47
+ DEFAULT_ATTRIBUTES.merge(configuration.commands.postgres).merge(configuration.commands.postgres_admin).merge(attrs).each do |name, value|
48
48
  instance_variable_set("@#{name}", value)
49
49
  end
50
50
  end
@@ -25,16 +25,16 @@ require 'delegate'
25
25
  module Masamune::Commands
26
26
  class S3Cmd < SimpleDelegator
27
27
  DEFAULT_ATTRIBUTES =
28
- {
29
- path: 's3cmd',
30
- options: [],
31
- extra: [],
32
- block: nil
33
- }.freeze
28
+ {
29
+ path: 's3cmd',
30
+ options: [],
31
+ extra: [],
32
+ block: nil
33
+ }.with_indifferent_access.freeze
34
34
 
35
35
  def initialize(delegate, attrs = {})
36
36
  super delegate
37
- DEFAULT_ATTRIBUTES.merge(configuration.s3cmd).merge(attrs).each do |name, value|
37
+ DEFAULT_ATTRIBUTES.merge(configuration.commands.s3cmd).merge(attrs).each do |name, value|
38
38
  instance_variable_set("@#{name}", value)
39
39
  end
40
40
  end
@@ -26,43 +26,45 @@ require 'tilt/erb'
26
26
  require 'pp'
27
27
 
28
28
  require 'active_support/core_ext/hash'
29
+ require 'hashie'
29
30
 
30
31
  require 'masamune/has_environment'
31
32
 
32
- class Masamune::Configuration
33
+ class Masamune::Configuration < Hashie::Dash
33
34
  extend Forwardable
34
- include Masamune::HasEnvironment
35
35
 
36
- attr_accessor :quiet
37
- attr_accessor :verbose
38
- attr_accessor :debug
39
- attr_accessor :dry_run
40
- attr_accessor :lock
41
- attr_accessor :retries
42
- attr_accessor :backoff
43
- attr_accessor :params
44
-
45
- COMMANDS = %w(aws_emr hive hadoop_streaming hadoop_filesystem s3cmd postgres postgres_admin).freeze
46
- COMMANDS.each do |command|
47
- attr_accessor command
48
- define_method(command) do
49
- instance_variable_get("@#{command}").symbolize_keys!
36
+ include Hashie::Extensions::MergeInitializer
37
+ include Hashie::Extensions::IndifferentAccess
38
+
39
+ class << self
40
+ attr_writer :default_config_file
41
+
42
+ def default_config_file
43
+ @default_config_file ||= File.join(File.expand_path('../../../', __FILE__), 'config', 'masamune.yml.erb')
44
+ end
45
+
46
+ def default_commands
47
+ @default_commands ||= %i(aws_emr hive hadoop_streaming hadoop_filesystem s3cmd postgres postgres_admin)
50
48
  end
51
49
  end
52
50
 
53
- def initialize(environment)
54
- self.environment = environment
55
- self.quiet = false
56
- self.verbose = false
57
- self.debug = false
58
- self.dry_run = false
59
- self.lock = nil
60
- self.retries = 3
61
- self.backoff = 5
62
- self.params = HashWithIndifferentAccess.new
63
-
64
- COMMANDS.each do |command|
65
- instance_variable_set("@#{command}", {})
51
+ property :environment
52
+ include Masamune::HasEnvironment
53
+
54
+ property :quiet, default: false
55
+ property :verbose, default: false
56
+ property :debug, default: false
57
+ property :dry_run, default: false
58
+ property :lock
59
+ property :retries, default: 3
60
+ property :backoff, default: 5
61
+ property :params, default: Hashie::Mash.new
62
+ property :commands, default: Hashie::Mash.new { |h, k| h[k] = Hashie::Mash.new }
63
+
64
+ def initialize(*a)
65
+ super
66
+ self.class.default_commands.each do |command|
67
+ commands[command] = Hashie::Mash.new
66
68
  end
67
69
  end
68
70
 
@@ -70,8 +72,8 @@ class Masamune::Configuration
70
72
  @load_once ||= begin
71
73
  config_file = filesystem.eval_path(path)
72
74
  load_yaml_erb_file(config_file).each_pair do |command, value|
73
- if COMMANDS.include?(command)
74
- send("#{command}=", value)
75
+ if command == 'commands'
76
+ commands.merge!(value)
75
77
  elsif command == 'paths'
76
78
  load_paths(value)
77
79
  elsif command == 'params'
@@ -80,8 +82,8 @@ class Masamune::Configuration
80
82
  end
81
83
  end
82
84
  logger.debug("Loaded configuration #{config_file}")
83
- load_catalog(configuration.postgres.fetch(:schema_files, []) + configuration.hive.fetch(:schema_files, []))
84
- true
85
+ load_catalog(configuration.commands.postgres.fetch(:schema_files, []) + configuration.commands.hive.fetch(:schema_files, []))
86
+ self
85
87
  end
86
88
  end
87
89
 
@@ -95,18 +97,8 @@ class Masamune::Configuration
95
97
  end
96
98
  end
97
99
 
98
- def to_s
99
- io = StringIO.new
100
- rep = { 'path' => filesystem.paths }
101
- COMMANDS.each do |command|
102
- rep[command] = send(command)
103
- end
104
- PP.pp(rep, io)
105
- io.string
106
- end
107
-
108
100
  def debug=(debug)
109
- @debug = debug
101
+ self[:debug] = debug
110
102
  environment.reload_logger!
111
103
  end
112
104
 
@@ -135,14 +127,6 @@ class Masamune::Configuration
135
127
  YAML.load(t.result(binding))
136
128
  end
137
129
 
138
- class << self
139
- attr_writer :default_config_file
140
-
141
- def default_config_file
142
- @default_config_file ||= File.join(File.expand_path('../../../', __FILE__), 'config', 'masamune.yml.erb')
143
- end
144
- end
145
-
146
130
  def default_config_file
147
131
  self.class.default_config_file
148
132
  end