Module: PGTrunk::Operation::RubyHelpers

Extended by:
ActiveSupport::Concern
Included in:
PGTrunk::Operation
Defined in:
lib/pg_trunk/core/operation/ruby_helpers.rb

Overview

Helpers to build ruby snippet from the operation definition

Instance Method Summary collapse

Instance Method Details

#dump(stream) ⇒ Object

Parameters:

  • stream (IO)


95
96
97
# File 'lib/pg_trunk/core/operation/ruby_helpers.rb', line 95

def dump(stream)
  to_ruby&.rstrip&.lines&.each { |line| stream.print(line.indent(2)) }
end

#to_aObject

List of attributes assigned that are assigned via Ruby method parameters.

We can use it to announce the operation to $stdout like create_foreign_key("users", "roles").



86
87
88
# File 'lib/pg_trunk/core/operation/ruby_helpers.rb', line 86

def to_a
  to_h.values_at(*self.class.ruby_params)
end

#to_optsObject



90
91
92
# File 'lib/pg_trunk/core/operation/ruby_helpers.rb', line 90

def to_opts
  to_h.except(*self.class.ruby_params)
end

#to_rubyString

Ruby snippet to dump the creator

Returns:

  • (String)


75
76
77
78
79
# File 'lib/pg_trunk/core/operation/ruby_helpers.rb', line 75

def to_ruby
  builder = RubyBuilder.new(self.class.ruby_name)
  instance_exec(builder, &self.class.ruby_snippet)
  builder.build.rstrip
end