masamune 0.17.12 → 0.17.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -3
  3. data/bin/masamune-aws-emr +1 -1
  4. data/bin/masamune-dump +1 -1
  5. data/bin/masamune-hive +1 -1
  6. data/bin/masamune-psql +1 -1
  7. data/bin/masamune-shell +1 -1
  8. data/lib/masamune.rb +1 -1
  9. data/lib/masamune/actions/aws_emr.rb +2 -2
  10. data/lib/masamune/actions/data_flow.rb +10 -10
  11. data/lib/masamune/actions/date_parse.rb +4 -6
  12. data/lib/masamune/actions/execute.rb +3 -3
  13. data/lib/masamune/actions/filesystem.rb +1 -1
  14. data/lib/masamune/actions/hadoop_filesystem.rb +2 -2
  15. data/lib/masamune/actions/hive.rb +5 -5
  16. data/lib/masamune/actions/invoke_parallel.rb +5 -5
  17. data/lib/masamune/actions/postgres.rb +6 -6
  18. data/lib/masamune/actions/postgres_admin.rb +1 -1
  19. data/lib/masamune/actions/s3cmd.rb +3 -3
  20. data/lib/masamune/actions/transform.rb +4 -4
  21. data/lib/masamune/after_initialize_callbacks.rb +4 -4
  22. data/lib/masamune/cached_filesystem.rb +7 -11
  23. data/lib/masamune/commands/aws_emr.rb +12 -12
  24. data/lib/masamune/commands/hadoop_filesystem.rb +8 -8
  25. data/lib/masamune/commands/hadoop_streaming.rb +16 -16
  26. data/lib/masamune/commands/hive.rb +31 -35
  27. data/lib/masamune/commands/postgres.rb +30 -32
  28. data/lib/masamune/commands/postgres_admin.rb +17 -16
  29. data/lib/masamune/commands/postgres_common.rb +1 -1
  30. data/lib/masamune/commands/retry_with_backoff.rb +19 -19
  31. data/lib/masamune/commands/s3cmd.rb +7 -7
  32. data/lib/masamune/commands/shell.rb +25 -38
  33. data/lib/masamune/configuration.rb +8 -9
  34. data/lib/masamune/data_plan/builder.rb +5 -5
  35. data/lib/masamune/data_plan/elem.rb +7 -7
  36. data/lib/masamune/data_plan/engine.rb +12 -15
  37. data/lib/masamune/data_plan/rule.rb +14 -12
  38. data/lib/masamune/data_plan/set.rb +13 -13
  39. data/lib/masamune/environment.rb +3 -3
  40. data/lib/masamune/filesystem.rb +29 -28
  41. data/lib/masamune/helpers/postgres.rb +8 -5
  42. data/lib/masamune/io.rb +2 -2
  43. data/lib/masamune/last_element.rb +3 -3
  44. data/lib/masamune/method_logger.rb +1 -1
  45. data/lib/masamune/schema/catalog.rb +9 -12
  46. data/lib/masamune/schema/column.rb +12 -10
  47. data/lib/masamune/schema/dimension.rb +5 -4
  48. data/lib/masamune/schema/fact.rb +2 -2
  49. data/lib/masamune/schema/map.rb +9 -13
  50. data/lib/masamune/schema/row.rb +3 -2
  51. data/lib/masamune/schema/store.rb +13 -14
  52. data/lib/masamune/schema/table.rb +24 -28
  53. data/lib/masamune/schema/table_reference.rb +7 -7
  54. data/lib/masamune/spec_helper.rb +1 -1
  55. data/lib/masamune/string_format.rb +1 -1
  56. data/lib/masamune/tasks/aws_emr_thor.rb +9 -9
  57. data/lib/masamune/tasks/dump_thor.rb +5 -5
  58. data/lib/masamune/tasks/hive_thor.rb +13 -13
  59. data/lib/masamune/tasks/postgres_thor.rb +8 -8
  60. data/lib/masamune/tasks/shell_thor.rb +3 -3
  61. data/lib/masamune/template.rb +4 -4
  62. data/lib/masamune/thor.rb +26 -25
  63. data/lib/masamune/transform/common/denormalize_table.rb +6 -6
  64. data/lib/masamune/transform/define_table.rb +1 -1
  65. data/lib/masamune/transform/hive/define_table.rb +0 -2
  66. data/lib/masamune/transform/insert_reference_values.rb +1 -1
  67. data/lib/masamune/transform/operator.rb +3 -2
  68. data/lib/masamune/transform/postgres/bulk_upsert.rb +0 -3
  69. data/lib/masamune/transform/postgres/deduplicate_dimension.rb +4 -6
  70. data/lib/masamune/transform/postgres/define_table.rb +2 -2
  71. data/lib/masamune/transform/postgres/insert_reference_values.rb +1 -4
  72. data/lib/masamune/transform/postgres/relabel_dimension.rb +1 -3
  73. data/lib/masamune/transform/postgres/rollup_fact.rb +3 -5
  74. data/lib/masamune/transform/postgres/snapshot_dimension.rb +1 -4
  75. data/lib/masamune/transform/postgres/stage_dimension.rb +8 -10
  76. data/lib/masamune/transform/postgres/stage_fact.rb +15 -14
  77. data/lib/masamune/version.rb +1 -1
  78. data/spec/masamune/actions/aws_emr_spec.rb +8 -8
  79. data/spec/masamune/actions/execute_spec.rb +6 -6
  80. data/spec/masamune/actions/hive_spec.rb +20 -15
  81. data/spec/masamune/actions/postgres_spec.rb +17 -10
  82. data/spec/masamune/after_initialization_callbacks_spec.rb +13 -7
  83. data/spec/masamune/commands/aws_emr_spec.rb +10 -10
  84. data/spec/masamune/commands/hadoop_filesystem_spec.rb +3 -3
  85. data/spec/masamune/commands/hadoop_streaming_spec.rb +4 -4
  86. data/spec/masamune/commands/hive_spec.rb +11 -11
  87. data/spec/masamune/commands/postgres_admin_spec.rb +9 -9
  88. data/spec/masamune/commands/postgres_spec.rb +15 -15
  89. data/spec/masamune/commands/retry_with_backoff_spec.rb +10 -7
  90. data/spec/masamune/commands/s3cmd_spec.rb +3 -3
  91. data/spec/masamune/commands/shell_spec.rb +16 -16
  92. data/spec/masamune/data_plan/builder_spec.rb +22 -19
  93. data/spec/masamune/data_plan/elem_spec.rb +20 -20
  94. data/spec/masamune/data_plan/engine_spec.rb +41 -33
  95. data/spec/masamune/data_plan/rule_spec.rb +19 -19
  96. data/spec/masamune/data_plan/set_spec.rb +8 -6
  97. data/spec/masamune/environment_spec.rb +5 -5
  98. data/spec/masamune/filesystem_spec.rb +87 -87
  99. data/spec/masamune/helpers/postgres_spec.rb +1 -1
  100. data/spec/masamune/rspec/job_fixture_spec.rb +0 -1
  101. data/spec/masamune/schema/catalog_spec.rb +16 -16
  102. data/spec/masamune/schema/column_spec.rb +19 -19
  103. data/spec/masamune/schema/dimension_spec.rb +2 -2
  104. data/spec/masamune/schema/fact_spec.rb +3 -3
  105. data/spec/masamune/schema/map_spec.rb +41 -41
  106. data/spec/masamune/schema/table_spec.rb +16 -16
  107. data/spec/masamune/string_format_spec.rb +7 -7
  108. data/spec/masamune/tasks/dump_thor_spec.rb +6 -6
  109. data/spec/masamune/tasks/hive_thor_spec.rb +2 -2
  110. data/spec/masamune/template_spec.rb +3 -2
  111. data/spec/masamune/thor_spec.rb +8 -8
  112. data/spec/masamune/transform/bulk_upsert.dimension_spec.rb +3 -3
  113. data/spec/masamune/transform/define_table.dimension_spec.rb +3 -3
  114. data/spec/masamune/transform/define_table.fact_spec.rb +5 -5
  115. data/spec/masamune/transform/define_table.table_spec.rb +6 -6
  116. data/spec/masamune/transform/denormalize_table_spec.rb +15 -15
  117. data/spec/masamune/transform/insert_reference_values.dimension_spec.rb +1 -1
  118. data/spec/masamune/transform/load_dimension_spec.rb +1 -1
  119. data/spec/masamune/transform/load_fact_spec.rb +1 -1
  120. data/spec/masamune/transform/rollup_fact_spec.rb +4 -4
  121. data/spec/masamune/transform/stage_dimension_spec.rb +3 -3
  122. data/spec/masamune/transform/stage_fact_spec.rb +4 -4
  123. data/spec/spec_helper.rb +1 -1
  124. data/spec/support/masamune/example_group.rb +2 -2
  125. data/spec/support/masamune/job_example_group.rb +3 -3
  126. data/spec/support/masamune/job_fixture.rb +4 -4
  127. data/spec/support/masamune/mock_command.rb +10 -10
  128. data/spec/support/masamune/mock_delegate.rb +2 -2
  129. data/spec/support/masamune/mock_filesystem.rb +3 -3
  130. data/spec/support/masamune/shared_example_group.rb +14 -16
  131. data/spec/support/masamune/step_example_group.rb +4 -4
  132. data/spec/support/masamune/step_fixture.rb +1 -1
  133. data/spec/support/masamune/task_example_group.rb +1 -1
  134. data/spec/support/masamune/thor_mute.rb +3 -2
  135. data/spec/support/rspec/example/action_example_group.rb +1 -1
  136. data/spec/support/rspec/example/task_example_group.rb +7 -4
  137. data/spec/support/rspec/example/transform_example_group.rb +1 -1
  138. data/spec/support/shared_examples/postgres_common_examples.rb +2 -2
  139. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1eb266f52acc5ee8e0c52a49902c99818f6f12b5
4
- data.tar.gz: d508a06edbd0ee12026452da4d6dcb8bc4d67602
3
+ metadata.gz: 211a98d1efc9791eeceb07e89df0c2ad70c27a4a
4
+ data.tar.gz: 2a7240f993c7a1252f75f009be836b5b6b5bdd32
5
5
  SHA512:
6
- metadata.gz: 3e07e29a9d2ae2f8d30ca1e4955ff0a9be518f99ea6776aabc9ee5410dd79a3b4c99e28b2ce4cc0a772d4c0e7f693b18e6789567f5a8d7b201bf72b5ce9fe3dc
7
- data.tar.gz: ae3fddf024a995705f361a0b11de610d1efe7f75e4211dbadcb604cd0ef410f6f5beb7821fdcb6cb3ee0ec3147d243cd8dea6e10485ff9b034646cdd7ef0972f
6
+ metadata.gz: 91022241697047ed01744ef834602314e35b90144c50d84699d4c21ab3403f4333188c7a340fac00a90433f92fe382654a852d7817cc43fd0942f5e7ef24f1a7
7
+ data.tar.gz: 13b3a769d6edf9efa8b50e6a982b59c3d0241c9a38558700e6938a30748aea1953c8b83e6a1ea834141446b5557e8886bb2681b5ae7bfdfeb98d3d3c59465449
data/Rakefile CHANGED
@@ -37,16 +37,16 @@ RSpec::Core::RakeTask.new(:spec)
37
37
  namespace :spec do
38
38
  desc 'Run Rspec unit code examples'
39
39
  RSpec::Core::RakeTask.new(:unit) do |spec|
40
- spec.pattern = "spec/**/*_spec.rb"
40
+ spec.pattern = 'spec/**/*_spec.rb'
41
41
  end
42
42
 
43
43
  desc 'Run Rspec acceptance code examples'
44
44
  RSpec::Core::RakeTask.new(:acceptance) do |spec|
45
- spec.pattern = "examples/**/*_spec.rb"
45
+ spec.pattern = 'examples/**/*_spec.rb'
46
46
  end
47
47
 
48
48
  desc 'Run All Rspec code examples'
49
49
  task all: [:unit, :acceptance]
50
50
  end
51
51
 
52
- task :default => :spec
52
+ task default: :spec
@@ -21,6 +21,6 @@
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
  # THE SOFTWARE.
23
23
 
24
- $: << File.expand_path('../../lib/', __FILE__)
24
+ $LOAD_PATH << File.expand_path('../../lib/', __FILE__)
25
25
  require 'masamune/tasks/aws_emr_thor'
26
26
  Masamune::Tasks::AwsEmrThor.start(ARGV)
@@ -21,6 +21,6 @@
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
  # THE SOFTWARE.
23
23
 
24
- $: << File.expand_path('../../lib/', __FILE__)
24
+ $LOAD_PATH << File.expand_path('../../lib/', __FILE__)
25
25
  require 'masamune/tasks/dump_thor'
26
26
  Masamune::Tasks::DumpThor.start(ARGV)
@@ -21,6 +21,6 @@
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
  # THE SOFTWARE.
23
23
 
24
- $: << File.expand_path('../../lib/', __FILE__)
24
+ $LOAD_PATH << File.expand_path('../../lib/', __FILE__)
25
25
  require 'masamune/tasks/hive_thor'
26
26
  Masamune::Tasks::HiveThor.start(ARGV)
@@ -21,6 +21,6 @@
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
  # THE SOFTWARE.
23
23
 
24
- $: << File.expand_path('../../lib/', __FILE__)
24
+ $LOAD_PATH << File.expand_path('../../lib/', __FILE__)
25
25
  require 'masamune/tasks/postgres_thor'
26
26
  Masamune::Tasks::PostgresThor.start(ARGV)
@@ -21,6 +21,6 @@
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
  # THE SOFTWARE.
23
23
 
24
- $: << File.expand_path('../../lib/', __FILE__)
24
+ $LOAD_PATH << File.expand_path('../../lib/', __FILE__)
25
25
  require 'masamune/tasks/shell_thor'
26
26
  Masamune::Tasks::ShellThor.start(ARGV)
@@ -43,6 +43,6 @@ module Masamune
43
43
  require 'masamune/schema'
44
44
  require 'masamune/transform'
45
45
 
46
- extend self
46
+ extend self # rubocop:disable Style/ModuleFunction
47
47
  extend Masamune::HasEnvironment
48
48
  end
@@ -37,11 +37,11 @@ module Masamune::Actions
37
37
  def validate_cluster_id!
38
38
  cluster_id = configuration.aws_emr[:cluster_id]
39
39
  raise ::Thor::RequiredArgumentMissingError, "No value provided for required options '--cluster-id'" unless cluster_id
40
- raise ::Thor::RequiredArgumentMissingError, %Q(AWS EMR cluster '#{cluster_id}' does not exist) unless aws_emr(action: 'describe-cluster', cluster_id: cluster_id, fail_fast: false).success?
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
42
42
 
43
43
  included do |base|
44
- base.class_option :cluster_id, :desc => "AWS EMR cluster_id ID (Hint: `masamune-emr-aws list-clusters`)" if defined?(base.class_option)
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
46
  next unless thor.configuration.aws_emr.any?
47
47
  next unless thor.configuration.aws_emr.fetch(:enabled, true)
@@ -50,11 +50,11 @@ module Masamune::Actions
50
50
  sources.first
51
51
  end
52
52
 
53
- # TODO sources from file or input array
53
+ # TODO: sources from file or input array
54
54
  def parse_file_type(key)
55
55
  return Set.new unless key
56
- value = options[key] or return Set.new
57
- File.exists?(value) or raise Thor::MalformattedArgumentError, "Expected file value for '--#{key}'; got #{value}"
56
+ (value = options[key]) || (return Set.new)
57
+ File.exist?(value) || raise(Thor::MalformattedArgumentError, "Expected file value for '--#{key}'; got #{value}")
58
58
  Set.new File.read(value).split(/\s+/)
59
59
  end
60
60
 
@@ -78,14 +78,12 @@ module Masamune::Actions
78
78
  end
79
79
  module_function :reset_module!
80
80
 
81
- private
82
-
83
81
  included do |base|
84
82
  base.extend ClassMethods
85
83
  base.class_eval do
86
- class_option :sources, :desc => 'File of data sources to process'
87
- class_option :targets, :desc => 'File of data targets to process'
88
- class_option :resolve, :type => :boolean, :desc => 'Recursively resolve data dependencies', :default => true
84
+ class_option :sources, desc: 'File of data sources to process'
85
+ class_option :targets, desc: 'File of data targets to process'
86
+ class_option :resolve, type: :boolean, desc: 'Recursively resolve data dependencies', default: true
89
87
  end
90
88
 
91
89
  base.after_initialize(:final) do |thor, options|
@@ -98,12 +96,13 @@ module Masamune::Actions
98
96
  end if defined?(base.after_initialize)
99
97
  end
100
98
 
99
+ # rubocop:disable Style/ClassVars
101
100
  module ClassMethods
102
101
  def skip
103
102
  initialize_module!
104
103
  @@namespaces << namespace
105
- @@sources << {skip: true}
106
- @@targets << {skip: true}
104
+ @@sources << { skip: true }
105
+ @@targets << { skip: true }
107
106
  end
108
107
 
109
108
  def source(source_options = {})
@@ -151,5 +150,6 @@ module Masamune::Actions
151
150
  true
152
151
  end
153
152
  end
153
+ # rubocop:enable Style/ClassVars
154
154
  end
155
155
  end
@@ -30,20 +30,18 @@ module Masamune::Actions
30
30
  value = options[key]
31
31
  Chronic.parse(value).tap do |datetime_value|
32
32
  logger.debug("Using '#{datetime_value}' for --#{key}") if value != datetime_value
33
- end or raise Thor::MalformattedArgumentError, "Expected date time value for '--#{key}'; got #{value}"
33
+ end || raise(Thor::MalformattedArgumentError, "Expected date time value for '--#{key}'; got #{value}")
34
34
  end
35
35
 
36
- private
37
-
38
36
  included do |base|
39
37
  base.class_eval do
40
38
  attr_accessor :start_value
41
39
  attr_accessor :stop_value
42
40
  attr_accessor :exact_value
43
41
 
44
- class_option :start, :aliases => '-a', :desc => 'Start time'
45
- class_option :stop, :aliases => '-b', :desc => 'Stop time'
46
- class_option :at, :desc => 'Exact time'
42
+ class_option :start, aliases: '-a', desc: 'Start time'
43
+ class_option :stop, aliases: '-b', desc: 'Stop time'
44
+ class_option :at, desc: 'Exact time'
47
45
 
48
46
  no_tasks do
49
47
  def start_date
@@ -22,7 +22,7 @@
22
22
 
23
23
  module Masamune::Actions
24
24
  module Execute
25
- def execute(*args, &block)
25
+ def execute(*args)
26
26
  opts = args.last.is_a?(Hash) ? args.pop : {}
27
27
  opts = opts.to_hash.symbolize_keys
28
28
 
@@ -52,13 +52,13 @@ module Masamune::Actions
52
52
 
53
53
  klass.class_eval do
54
54
  define_method(:handle_stdout) do |line, line_no|
55
- block.call(line, line_no)
55
+ yield(line, line_no)
56
56
  end
57
57
  end if block_given?
58
58
 
59
59
  command = klass.new(self)
60
60
  command = Masamune::Commands::RetryWithBackoff.new(command, opts)
61
- command = Masamune::Commands::Shell.new(command, {fail_fast: false}.merge(opts))
61
+ command = Masamune::Commands::Shell.new(command, { fail_fast: false }.merge(opts))
62
62
  opts.fetch(:interactive, false) ? command.replace(opts) : command.execute
63
63
  end
64
64
  end
@@ -28,7 +28,7 @@ module Masamune::Actions
28
28
  def filesystem
29
29
  defined?(environment) ? environment.filesystem : Masamune.environment.filesystem
30
30
  end
31
- alias :fs :filesystem
31
+ alias fs filesystem
32
32
  end
33
33
  include ClassMethods
34
34
  end
@@ -26,8 +26,8 @@ module Masamune::Actions
26
26
  opts = args.last.is_a?(Hash) ? args.pop : {}
27
27
  opts = opts.to_hash.symbolize_keys
28
28
  opts.reverse_merge!(fail_fast: false)
29
- opts.merge!(extra: Array.wrap(args))
30
- opts.merge!(block: block.to_proc) if block_given?
29
+ opts[:extra] = Array.wrap(args)
30
+ opts[:block] = block.to_proc if block_given?
31
31
 
32
32
  command = Masamune::Commands::HadoopFilesystem.new(environment, opts)
33
33
  command = Masamune::Commands::RetryWithBackoff.new(command, configuration.hadoop_filesystem.slice(:retries, :backoff).merge(opts))
@@ -30,7 +30,7 @@ module Masamune::Actions
30
30
 
31
31
  def hive(opts = {}, &block)
32
32
  opts = opts.to_hash.symbolize_keys
33
- opts.merge!(block: block.to_proc) if block_given?
33
+ opts[:block] = block.to_proc if block_given?
34
34
 
35
35
  command = Masamune::Commands::Hive.new(environment, opts)
36
36
  command = Masamune::Commands::AwsEmr.new(command, opts.except(:extra)) if configuration.aws_emr[:cluster_id]
@@ -40,12 +40,12 @@ module Masamune::Actions
40
40
  command.interactive? ? command.replace : command.execute
41
41
  end
42
42
 
43
- # TODO warn or error if database is not defined
43
+ # TODO: warn or error if database is not defined
44
44
  def create_hive_database_if_not_exists
45
45
  return if configuration.hive[:database] == 'default'
46
46
  sql = []
47
- sql << %Q(CREATE DATABASE IF NOT EXISTS #{configuration.hive[:database]})
48
- sql << %Q(LOCATION "#{configuration.hive[:location]}") if configuration.hive[:location]
47
+ sql << %(CREATE DATABASE IF NOT EXISTS #{configuration.hive[:database]})
48
+ sql << %(LOCATION "#{configuration.hive[:location]}") if configuration.hive[:location]
49
49
  hive(exec: sql.join(' ') + ';', database: nil)
50
50
  end
51
51
 
@@ -54,7 +54,7 @@ module Masamune::Actions
54
54
  hive(file: transform.to_file)
55
55
  rescue => e
56
56
  logger.error(e)
57
- logger.error("Could not load schema")
57
+ logger.error('Could not load schema')
58
58
  logger.error("\n" + transform.to_s)
59
59
  exit
60
60
  end
@@ -31,7 +31,7 @@ module Masamune::Actions
31
31
  include Masamune::Actions::Execute
32
32
 
33
33
  included do |base|
34
- base.class_option :max_tasks, aliases: '-p', :type => :numeric, :desc => 'Maximum number of tasks to execute in parallel', :default => 4
34
+ base.class_option :max_tasks, aliases: '-p', type: :numeric, desc: 'Maximum number of tasks to execute in parallel', default: 4
35
35
  end
36
36
 
37
37
  def invoke_parallel(*task_group)
@@ -42,7 +42,7 @@ module Masamune::Actions
42
42
  Parallel.each(task_group, in_processes: max_tasks) do |task_name|
43
43
  begin
44
44
  execute(thor_wrapper, task_name, *task_args(opts), interactive: true, detach: false)
45
- rescue SystemExit
45
+ rescue SystemExit # rubocop:disable Lint/HandleExceptions
46
46
  end
47
47
  end
48
48
  end
@@ -60,13 +60,13 @@ module Masamune::Actions
60
60
  end
61
61
 
62
62
  def task_args(opts = {})
63
- opts.map do |k,v|
63
+ opts.map do |k, v|
64
64
  case v
65
65
  when true
66
- "--#{k.to_s.gsub('_', '-')}"
66
+ "--#{k.to_s.tr('_', '-')}"
67
67
  when false
68
68
  else
69
- ["--#{k.to_s.gsub('_', '-')}", v]
69
+ ["--#{k.to_s.tr('_', '-')}", v]
70
70
  end
71
71
  end.flatten.compact
72
72
  end
@@ -32,7 +32,7 @@ module Masamune::Actions
32
32
 
33
33
  def postgres(opts = {}, &block)
34
34
  opts = opts.to_hash.symbolize_keys
35
- opts.merge!(block: block.to_proc) if block_given?
35
+ opts[:block] = block.to_proc if block_given?
36
36
 
37
37
  command = Masamune::Commands::Postgres.new(environment, opts)
38
38
  command = Masamune::Commands::RetryWithBackoff.new(command, configuration.postgres.slice(:retries, :backoff).merge(opts))
@@ -42,9 +42,9 @@ module Masamune::Actions
42
42
  end
43
43
 
44
44
  def create_postgres_database_if_not_exists
45
- unless postgres_helper.database_exists?
46
- postgres_admin(action: :create, database: configuration.postgres[:database], safe: true)
47
- end if configuration.postgres.has_key?(:database)
45
+ if configuration.postgres.key?(:database)
46
+ postgres_admin(action: :create, database: configuration.postgres[:database], safe: true) unless postgres_helper.database_exists?
47
+ end
48
48
  end
49
49
 
50
50
  def load_postgres_setup_files
@@ -52,7 +52,7 @@ module Masamune::Actions
52
52
  configuration.with_quiet do
53
53
  postgres(file: file, retries: 0)
54
54
  end
55
- end if configuration.postgres.has_key?(:setup_files)
55
+ end if configuration.postgres.key?(:setup_files)
56
56
  end
57
57
 
58
58
  def load_postgres_schema
@@ -60,7 +60,7 @@ module Masamune::Actions
60
60
  postgres(file: transform.to_file, retries: 0)
61
61
  rescue => e
62
62
  logger.error(e)
63
- logger.error("Could not load schema")
63
+ logger.error('Could not load schema')
64
64
  logger.error("\n" + transform.to_s)
65
65
  exit
66
66
  end
@@ -22,7 +22,7 @@
22
22
 
23
23
  module Masamune::Actions
24
24
  module PostgresAdmin
25
- def postgres_admin(opts = {}, &block)
25
+ def postgres_admin(opts = {})
26
26
  opts = opts.to_hash.symbolize_keys
27
27
 
28
28
  command = Masamune::Commands::PostgresAdmin.new(environment, opts)
@@ -29,8 +29,8 @@ module Masamune::Actions
29
29
  def s3cmd(*args, &block)
30
30
  opts = args.last.is_a?(Hash) ? args.pop : {}
31
31
  opts = opts.to_hash.symbolize_keys
32
- opts.merge!(extra: Array.wrap(args))
33
- opts.merge!(block: block.to_proc) if block_given?
32
+ opts[:extra] = Array.wrap(args)
33
+ opts[:block] = block.to_proc if block_given?
34
34
 
35
35
  command = Masamune::Commands::S3Cmd.new(environment, opts)
36
36
  command = Masamune::Commands::RetryWithBackoff.new(command, configuration.s3cmd.slice(:retries, :backoff).merge(opts))
@@ -40,7 +40,7 @@ module Masamune::Actions
40
40
  end
41
41
 
42
42
  def s3_sync(src, dst)
43
- s3cmd('sync', s3b(src), s3b(dst, :dir => true))
43
+ s3cmd('sync', s3b(src), s3b(dst, dir: true))
44
44
  end
45
45
  end
46
46
  end
@@ -35,7 +35,7 @@ module Masamune::Actions
35
35
 
36
36
  include Masamune::Actions::Postgres
37
37
 
38
- # FIXME should eventually be able to include Transform directly instead of through wrapper
38
+ # FIXME: should eventually be able to include Transform directly instead of through wrapper
39
39
  class Wrapper
40
40
  extend Masamune::Transform::LoadDimension
41
41
  extend Masamune::Transform::ConsolidateDimension
@@ -78,20 +78,20 @@ module Masamune::Actions
78
78
  private
79
79
 
80
80
  def optional_apply_map(source_files, source, target, &block)
81
- if source.respond_to?(:map) and map = source.map(to: target)
81
+ if source.respond_to?(:map) && (map = source.map(to: target))
82
82
  apply_map(map, source_files, source, target, &block)
83
83
  else
84
84
  yield source_files, source
85
85
  end
86
86
  end
87
87
 
88
- def apply_map(map, source_files, source, target)
88
+ def apply_map(map, source_files, source, _target)
89
89
  Tempfile.open('masamune_transform') do |output|
90
90
  begin
91
91
  FileUtils.chmod(FILE_MODE, output.path)
92
92
  result = map.apply(source_files, output)
93
93
  result.debug = map.debug
94
- logger.debug(File.read(output)) if (source.debug || result.debug)
94
+ logger.debug(File.read(output)) if source.debug || result.debug
95
95
  yield output, result
96
96
  ensure
97
97
  output.unlink
@@ -31,18 +31,18 @@ module Masamune
31
31
  default: 0,
32
32
  later: -10,
33
33
  final: -20
34
- }
34
+ }.freeze
35
35
 
36
36
  module ClassMethods
37
37
  # Callbacks registered with the highest priority are executed first, ties are broken by callback registration order
38
38
  def after_initialize(priority = :default, &block)
39
- @after_initialize ||= Hash.new { |h,k| h[k] = [] }
39
+ @after_initialize ||= Hash.new { |h, k| h[k] = [] }
40
40
  @after_initialize[PRIORITY.fetch(priority, 0)] << block
41
41
  end
42
42
 
43
43
  def after_initialize_invoke(*a)
44
- @after_initialize ||= Hash.new { |h,k| h[k] = [] }
45
- @after_initialize.sort.reverse.each { |p, x| x.each { |y| y.call(*a) } }
44
+ @after_initialize ||= Hash.new { |h, k| h[k] = [] }
45
+ @after_initialize.sort.reverse.each { |_p, x| x.each { |y| y.call(*a) } }
46
46
  end
47
47
  end
48
48
 
@@ -81,7 +81,7 @@ module Masamune
81
81
  end if depth == 0
82
82
  end
83
83
 
84
- # FIXME cache eviction policy can be more precise
84
+ # FIXME: cache eviction policy can be more precise
85
85
  [:touch!, :mkdir!, :copy_file_to_file, :copy_file_to_dir, :copy_dir, :remove_file, :remove_dir, :move_file_to_file, :move_file_to_dir, :move_dir, :write].each do |method|
86
86
  define_method(method) do |*args|
87
87
  clear!
@@ -89,8 +89,6 @@ module Masamune
89
89
  end
90
90
  end
91
91
 
92
- private
93
-
94
92
  class PathCache
95
93
  def initialize(filesystem)
96
94
  @filesystem = filesystem
@@ -102,25 +100,23 @@ module Masamune
102
100
  return if @filesystem.root_path?(path)
103
101
  put(File.join(@filesystem.dirname(path), '.'), OpenStruct.new(name: @filesystem.dirname(path)))
104
102
  paths = path_split(path)
105
- elems = paths.reverse.inject(entry) { |a, n| { n => a } }
103
+ elems = paths.reverse.inject(entry) { |a, e| { e => a } }
106
104
  @cache.deep_merge!(elems)
107
105
  end
108
106
 
109
107
  def get(path)
110
108
  return unless path
111
109
  paths = path_split(path)
112
- elem = paths.inject(@cache) { |level, path| level.is_a?(Hash) ? level.fetch(path, {}) : level }
110
+ elem = paths.inject(@cache) { |a, e| a.is_a?(Hash) ? a.fetch(e, {}) : a }
113
111
  emit(elem)
114
112
  rescue KeyError
115
113
  EMPTY_SET
116
114
  end
117
115
 
118
116
  def any?(path)
119
- if elem = get(path)
120
- elem.any? { |entry| entry.name.start_with?(path) }
121
- else
122
- false
123
- end
117
+ elem = get(path)
118
+ return false unless elem
119
+ elem.any? { |entry| entry.name.start_with?(path) }
124
120
  end
125
121
 
126
122
  private
@@ -142,7 +138,7 @@ module Masamune
142
138
  end
143
139
 
144
140
  def path_split(path)
145
- path.split('/').reject { |x| x.blank? }
141
+ path.split('/').reject(&:blank?)
146
142
  end
147
143
  end
148
144
  end