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
@@ -54,7 +54,7 @@ module Masamune
54
54
  end
55
55
 
56
56
  def with_exclusive_lock(name)
57
- raise 'filesystem path :run_dir not defined' unless filesystem.has_path?(:run_dir)
57
+ raise 'filesystem path :run_dir not defined' unless filesystem.path?(:run_dir)
58
58
  lock_name = [name, configuration.lock].compact.join(':')
59
59
  logger.debug("acquiring lock '#{lock_name}'")
60
60
  lock_file = lock_file(lock_name)
@@ -80,7 +80,7 @@ module Masamune
80
80
  end
81
81
 
82
82
  def log_file_template
83
- @log_file_template || "#{Time.now.to_i}-#{$$}.log"
83
+ @log_file_template || "#{Time.now.to_i}-#{$PROCESS_ID}.log"
84
84
  end
85
85
 
86
86
  def log_file_template=(log_file_template)
@@ -149,7 +149,7 @@ module Masamune
149
149
  end
150
150
 
151
151
  def log_file_io
152
- if filesystem.has_path?(:log_dir)
152
+ if filesystem.path?(:log_dir)
153
153
  log_file = File.open(log_file_name, 'a')
154
154
  log_file.sync = true
155
155
  configuration.debug ? Masamune::MultiIO.new($stderr, log_file) : log_file
@@ -54,7 +54,7 @@ module Masamune
54
54
  def get_path(symbol, *args)
55
55
  options = args.last.is_a?(Hash) ? args.pop : {}
56
56
  lazy_path = lambda do |fs|
57
- fs.has_path?(symbol) or raise "Path :#{symbol} not defined"
57
+ fs.path?(symbol) || raise("Path :#{symbol} not defined")
58
58
  path, options = fs.paths[symbol]
59
59
 
60
60
  mkdir!(path) if options[:mkdir]
@@ -67,15 +67,13 @@ module Masamune
67
67
  lazy_path
68
68
  end
69
69
  end
70
- alias :path :get_path
70
+ alias path get_path
71
71
 
72
- def has_path?(symbol)
73
- @paths.has_key?(symbol)
72
+ def path?(symbol)
73
+ @paths.key?(symbol)
74
74
  end
75
75
 
76
- def paths
77
- @paths
78
- end
76
+ attr_reader :paths
79
77
 
80
78
  def eval_path(path)
81
79
  path.respond_to?(:call) ? path.call(self) : path
@@ -84,7 +82,7 @@ module Masamune
84
82
  def expand_params(fs, path)
85
83
  new_path = path.dup
86
84
  fs.environment.configuration.params.each do |key, value|
87
- new_path.gsub!("%#{key.to_s}", value.to_s)
85
+ new_path.gsub!("%#{key}", value.to_s)
88
86
  end
89
87
  new_path
90
88
  end
@@ -95,7 +93,8 @@ module Masamune
95
93
  end
96
94
 
97
95
  def parent_paths(path)
98
- if prefix = remote_prefix(path)
96
+ prefix = remote_prefix(path)
97
+ if prefix
99
98
  node = path.split(prefix).last
100
99
  else
101
100
  prefix = ''
@@ -104,7 +103,7 @@ module Masamune
104
103
 
105
104
  return [] if prefix.blank? && node.blank?
106
105
  parent_paths = node ? File.expand_path(node, '/').split('/') : []
107
- parent_paths.reject! { |x| x.blank? }
106
+ parent_paths.reject!(&:blank?)
108
107
  parent_paths.prepend('/') if node =~ %r{\A/}
109
108
  tmp = []
110
109
  result = []
@@ -125,7 +124,7 @@ module Masamune
125
124
  end
126
125
 
127
126
  def resolve_file(paths = [])
128
- Array.wrap(paths).select { |path| File.exists?(path) && File.file?(path) }.first
127
+ Array.wrap(paths).select { |path| File.exist?(path) && File.file?(path) }.first
129
128
  end
130
129
 
131
130
  def dirname(path)
@@ -165,12 +164,12 @@ module Masamune
165
164
  when :s3
166
165
  result = Set.new
167
166
  s3cmd('ls', s3b(file), safe: true) do |line|
168
- date, time, size, name = line.split(/\s+/)
167
+ _date, _time, _size, name = line.split(/\s+/)
169
168
  result << (name == file)
170
169
  end
171
170
  result.any?
172
171
  when :local
173
- File.exists?(file)
172
+ File.exist?(file)
174
173
  end
175
174
  end
176
175
 
@@ -218,9 +217,9 @@ module Masamune
218
217
  when :hdfs
219
218
  hadoop_fs('-mkdir', '-p', *dir_set)
220
219
  when :s3
221
- touch! *dir_set.map { |dir| File.join(dir, '.not_empty') }
220
+ touch!(*dir_set.map { |dir| File.join(dir, '.not_empty') })
222
221
  when :local
223
- missing_dir_set = dir_set.reject { |dir| File.exists?(dir) }
222
+ missing_dir_set = dir_set.reject { |dir| File.exist?(dir) }
224
223
  FileUtils.mkdir_p(missing_dir_set, file_util_args) if missing_dir_set.any?
225
224
  end
226
225
  end
@@ -230,7 +229,7 @@ module Masamune
230
229
  return Set.new(to_enum(:glob, pattern, options)) unless block_given?
231
230
  case type(pattern)
232
231
  when :hdfs
233
- file_glob, file_regexp = glob_split(pattern)
232
+ _file_glob, file_regexp = glob_split(pattern)
234
233
  hadoop_fs('-ls', pattern, safe: true) do |line|
235
234
  next if line =~ /\AFound \d+ items/
236
235
  name = line.split(/\s+/).last
@@ -258,7 +257,7 @@ module Masamune
258
257
  return to_enum(:glob_sort, pattern, options).to_a unless block_given?
259
258
  case options[:order]
260
259
  when :basename
261
- glob(pattern).sort { |x,y| File.basename(x) <=> File.basename(y) }.each do |result|
260
+ glob(pattern).sort { |x, y| File.basename(x) <=> File.basename(y) }.each do |result|
262
261
  yield result
263
262
  end
264
263
  else
@@ -381,7 +380,7 @@ module Masamune
381
380
  case type
382
381
  when :local
383
382
  file_set.map do |file|
384
- next unless File.exists?(file)
383
+ next unless File.exist?(file)
385
384
  next if File.directory?(file)
386
385
  buf << File.read(file)
387
386
  end
@@ -403,7 +402,8 @@ module Masamune
403
402
 
404
403
  def chown!(*files)
405
404
  opts = files.last.is_a?(Hash) ? files.pop : {}
406
- user, group = opts.fetch(:user, current_user), opts.fetch(:group, current_group)
405
+ user = opts.fetch(:user, current_user)
406
+ group = opts.fetch(:group, current_group)
407
407
 
408
408
  files.group_by { |path| type(path) }.each do |type, file_set|
409
409
  case type
@@ -430,12 +430,12 @@ module Masamune
430
430
  end
431
431
 
432
432
  def glob_split(input, options = {})
433
- [ input.include?('*') ? input.split('*').first + '*' : input, glob_to_regexp(input, options) ]
433
+ [input.include?('*') ? input.split('*').first + '*' : input, glob_to_regexp(input, options)]
434
434
  end
435
435
 
436
436
  def glob_to_regexp(input, options = {})
437
437
  if input.include?('*') || options.fetch(:recursive, false)
438
- %r|\A#{Regexp.escape(input).gsub('\\*', '.*?').gsub(%r{\/\.\*\?\z}, '/?.*?')}|
438
+ /\A#{Regexp.escape(input).gsub('\\*', '.*?').gsub(%r{\/\.\*\?\z}, '/?.*?')}/
439
439
  else
440
440
  /\A#{Regexp.escape(input)}\z/
441
441
  end
@@ -472,7 +472,7 @@ module Masamune
472
472
  end
473
473
 
474
474
  def eager_load_paths?
475
- @paths.reject { |key,_| key == :root_dir }.any?
475
+ @paths.reject { |key, _| key == :root_dir }.any?
476
476
  end
477
477
 
478
478
  def type(path)
@@ -487,27 +487,27 @@ module Masamune
487
487
  end
488
488
 
489
489
  def file_util_args
490
- {noop: configuration.dry_run, verbose: configuration.verbose}
490
+ { noop: configuration.dry_run, verbose: configuration.verbose }
491
491
  end
492
492
 
493
493
  def qualify_file(dir, file)
494
- if prefix = remote_prefix(dir) and file !~ /\A#{Regexp.escape(prefix)}/
494
+ if (prefix = remote_prefix(dir)) && file !~ /\A#{Regexp.escape(prefix)}/
495
495
  "#{prefix}/#{file.sub(%r{\A/+}, '')}"
496
496
  else
497
497
  file
498
498
  end
499
499
  end
500
- alias :q :qualify_file
500
+ alias q qualify_file
501
501
 
502
502
  def ensure_dir(dir)
503
503
  File.join(dir, '/')
504
504
  end
505
- alias :d :ensure_dir
505
+ alias d ensure_dir
506
506
 
507
507
  def ensure_file(file)
508
508
  file.chomp('/')
509
509
  end
510
- alias :f :ensure_file
510
+ alias f ensure_file
511
511
 
512
512
  def add_immutable_path(path)
513
513
  @immutable_paths[path] = /\A#{Regexp.escape(path)}/
@@ -526,6 +526,7 @@ module Masamune
526
526
  def current_group
527
527
  Etc.getgrgid(Etc.getpwnam(current_user).gid).name
528
528
  rescue
529
+ nil
529
530
  end
530
531
 
531
532
  def copy_file_helper(src, dst, dir)
@@ -569,7 +570,7 @@ module Masamune
569
570
  s3cmd('del', src)
570
571
  when [:s3, :hdfs]
571
572
  hadoop_fs('-mv', s3n(src), dst)
572
- when [:local, :local]
573
+ when [:local, :local]
573
574
  FileUtils.mv(src, dst, file_util_args)
574
575
  FileUtils.chmod(FILE_MODE, dst, file_util_args)
575
576
  when [:local, :hdfs]
@@ -66,7 +66,7 @@ module Masamune::Helpers
66
66
  return unless @cache.empty?
67
67
  postgres(exec: 'SELECT table_name FROM information_schema.tables;', tuple_output: true, retries: 0) do |line|
68
68
  table = line.strip
69
- next if table =~ /\Apg_/
69
+ next if table.start_with?('pg_')
70
70
  @cache[table] ||= nil
71
71
  end
72
72
  end
@@ -74,11 +74,14 @@ module Masamune::Helpers
74
74
  def update_table_last_modified_at(table, column)
75
75
  return if @cache[table].present?
76
76
  postgres(exec: "SELECT MAX(#{column}) FROM #{table};", tuple_output: true, retries: 0) do |line|
77
- begin
78
- @cache[table] = Time.parse(line.strip).at_beginning_of_minute.utc
79
- rescue ArgumentError
80
- end
77
+ @cache[table] = parse_date_time(line.strip)
81
78
  end
82
79
  end
80
+
81
+ def parse_date_time(value)
82
+ Time.parse(value).at_beginning_of_minute.utc
83
+ rescue ArgumentError
84
+ nil
85
+ end
83
86
  end
84
87
  end
@@ -22,12 +22,12 @@
22
22
 
23
23
  class IO
24
24
  def wait_readable(timeout = 0)
25
- rs, ws = IO.select([self], [], [], timeout)
25
+ rs, _ws = IO.select([self], [], [], timeout)
26
26
  rs && rs[0]
27
27
  end unless IO.method_defined?(:wait_readable)
28
28
 
29
29
  def wait_writable(timeout = 0)
30
- rs, ws = IO.select([], [self], [], timeout)
30
+ _rs, ws = IO.select([], [self], [], timeout)
31
31
  ws && ws[0]
32
32
  end unless IO.method_defined?(:wait_writable)
33
33
  end
@@ -36,12 +36,12 @@ module Masamune
36
36
 
37
37
  module ClassMethods
38
38
  def method_with_last_element(method)
39
- self.class_eval do
39
+ class_eval do
40
40
  new_method = "#{method}_with_last_element"
41
41
  old_method = "#{method}_without_last_element"
42
42
  alias_method old_method, method
43
- define_method(new_method) do |*args, &block|
44
- last_element(old_method, *args)
43
+ define_method(new_method) do |*args|
44
+ last_element(old_method, *args)
45
45
  end
46
46
  alias_method method, new_method
47
47
  end
@@ -20,7 +20,7 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
- # FIXME refactor as Command
23
+ # FIXME: refactor as Command
24
24
  module Masamune
25
25
  class MethodLogger < SimpleDelegator
26
26
  def initialize(target, *methods)
@@ -37,7 +37,7 @@ module Masamune::Schema
37
37
  end
38
38
 
39
39
  def map(options = {})
40
- self.maps[options[:to]]
40
+ maps[options[:to]]
41
41
  end
42
42
  end
43
43
 
@@ -66,8 +66,8 @@ module Masamune::Schema
66
66
  def initialize(store, options = {})
67
67
  super store
68
68
  @store = store
69
- @options = Hash.new { |h,k| h[k] = [] }
70
- @options.merge!(store: @store)
69
+ @options = Hash.new { |h, k| h[k] = [] }
70
+ @options[:store] = @store
71
71
  @options.merge!(options)
72
72
  end
73
73
 
@@ -83,7 +83,7 @@ module Masamune::Schema
83
83
 
84
84
  def initialize(environment)
85
85
  self.environment = environment
86
- @stores = Hash.new { |h,k| h[k] = Masamune::Schema::Store.new(environment, type: k) }
86
+ @stores = Hash.new { |h, k| h[k] = Masamune::Schema::Store.new(environment, type: k) }
87
87
  @context = nil
88
88
  end
89
89
 
@@ -98,7 +98,7 @@ module Masamune::Schema
98
98
  stores.each do |id|
99
99
  begin
100
100
  @context = Context.new(@stores[id], options)
101
- instance_eval &block
101
+ instance_eval(&block)
102
102
  ensure
103
103
  @context = nil
104
104
  end
@@ -182,14 +182,11 @@ module Masamune::Schema
182
182
  @context.pop
183
183
  end
184
184
 
185
- def attribute(id, options = {})
186
- @context.options[:attributes] << Masamune::Schema::Event::Attribute.new(options.merge(id: id))
187
- end
188
-
189
185
  def map(options = {}, &block)
190
- raise ArgumentError, "invalid map, from: is missing" unless options.is_a?(Hash)
191
- from, to = options.delete(:from), options.delete(:to)
192
- raise ArgumentError, "invalid map, from: is missing" unless from && from.try(:id)
186
+ raise ArgumentError, 'invalid map, from: is missing' unless options.is_a?(Hash)
187
+ from = options.delete(:from)
188
+ to = options.delete(:to)
189
+ raise ArgumentError, 'invalid map, from: is missing' unless from && from.try(:id)
193
190
  raise ArgumentError, "invalid map from: '#{from.id}', to: is missing" unless to
194
191
  @context.push(options)
195
192
  @context.options[:function] = block.to_proc if block
@@ -47,7 +47,7 @@ module Masamune::Schema
47
47
  reference: nil,
48
48
  parent: nil,
49
49
  debug: false
50
- }
50
+ }.freeze
51
51
 
52
52
  DEFAULT_ATTRIBUTES.keys.each do |attr|
53
53
  attr_accessor attr
@@ -139,7 +139,7 @@ module Masamune::Schema
139
139
  end
140
140
 
141
141
  def reference_name(label = nil)
142
- qualified_name(label).to_s.gsub(/\./, '_').to_sym
142
+ qualified_name(label).to_s.tr('.', '_').to_sym
143
143
  end
144
144
 
145
145
  def sql_type(for_surrogate_key = false)
@@ -209,7 +209,11 @@ module Masamune::Schema
209
209
  return nil if value.nil?
210
210
  case type
211
211
  when :boolean
212
- value ? 'TRUE' : (hive_encoding? ? nil : 'FALSE')
212
+ if value
213
+ 'TRUE'
214
+ else
215
+ hive_encoding? ? nil : 'FALSE'
216
+ end
213
217
  when :yaml
214
218
  value.to_hash.to_yaml
215
219
  when :json, :key_value
@@ -298,14 +302,12 @@ module Masamune::Schema
298
302
 
299
303
  def default_ruby_value
300
304
  return [] if array_value?
301
- return HashWithIndifferentAccess.new { |h,k| h[k] = HashWithIndifferentAccess.new(&h.default_proc) } if hash_value?
305
+ return HashWithIndifferentAccess.new { |h, k| h[k] = HashWithIndifferentAccess.new(&h.default_proc) } if hash_value?
302
306
  case type
303
307
  when :date
304
308
  Date.new(0)
305
309
  when :timestamp
306
310
  Time.new(0)
307
- else
308
- nil
309
311
  end
310
312
  end
311
313
 
@@ -348,7 +350,7 @@ module Masamune::Schema
348
350
  end
349
351
 
350
352
  def array_value?
351
- !!(array || (reference && reference.respond_to?(:multiple) && reference.multiple))
353
+ (array || (reference && reference.respond_to?(:multiple) && reference.multiple)) == true
352
354
  end
353
355
 
354
356
  def hash_value?
@@ -364,7 +366,7 @@ module Masamune::Schema
364
366
  end
365
367
 
366
368
  def as_hash
367
- {id: id}.tap do |hash|
369
+ { id: id }.tap do |hash|
368
370
  DEFAULT_ATTRIBUTES.keys.each do |attr|
369
371
  hash[attr] = public_send(attr)
370
372
  end
@@ -451,7 +453,7 @@ module Masamune::Schema
451
453
  def required_value?
452
454
  return false if reference && (reference.null || !reference.default.nil?)
453
455
  return false if null || !default.nil?
454
- return false if !strict
456
+ return false unless strict
455
457
  true
456
458
  end
457
459
 
@@ -465,7 +467,7 @@ module Masamune::Schema
465
467
 
466
468
  def sql_default
467
469
  return if default.nil?
468
- return if !strict
470
+ return unless strict
469
471
  "DEFAULT #{sql_value(default)}"
470
472
  end
471
473
 
@@ -22,7 +22,7 @@
22
22
 
23
23
  module Masamune::Schema
24
24
  class Dimension < Table
25
- SUPPORTED_GRAINS = [:hourly, :daily, :monthly]
25
+ SUPPORTED_GRAINS = [:hourly, :daily, :monthly].freeze
26
26
 
27
27
  def initialize(opts = {})
28
28
  opts.symbolize_keys!
@@ -48,7 +48,8 @@ module Masamune::Schema
48
48
  end
49
49
 
50
50
  def suffix
51
- suffix = case type
51
+ suffix =
52
+ case type
52
53
  when :mini
53
54
  'type'
54
55
  when :one, :two, :four, :date
@@ -111,7 +112,7 @@ module Masamune::Schema
111
112
  end
112
113
 
113
114
  def initialize_dimension_columns!
114
- # TODO assign index for load_fact
115
+ # TODO: assign index for load_fact
115
116
  case type
116
117
  when :one, :date
117
118
  initialize_column! id: 'last_modified_at', type: :timestamp, default: 'NOW()'
@@ -122,7 +123,7 @@ module Masamune::Schema
122
123
  initialize_column! id: 'last_modified_at', type: :timestamp, default: 'NOW()'
123
124
  when :four
124
125
  children << ledger_table
125
- # FIXME derive type from from parent
126
+ # FIXME: derive type from from parent
126
127
  initialize_column! id: 'start_at', type: :timestamp, default: 'TO_TIMESTAMP(0)', index: [:start_at, :natural], unique: :natural
127
128
  initialize_column! id: 'end_at', type: :timestamp, null: true, index: :end_at
128
129
  initialize_column! id: 'version', type: :integer, default: 1, null: true